diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleApplication.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleApplication.cs index 937556d01d..01797852f4 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleApplication.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleApplication.cs @@ -4,97 +4,28 @@ using System; using System.Diagnostics; using System.Text; +using ICSharpCode.Scripting; namespace ICSharpCode.PythonBinding { - public class PythonConsoleApplication + public class PythonConsoleApplication : ScriptingConsoleApplication { PythonAddInOptions options; - StringBuilder arguments; - bool debug; - string pythonScriptFileName = String.Empty; - string pythonScriptCommandLineArguments = String.Empty; - string workingDirectory = String.Empty; public PythonConsoleApplication(PythonAddInOptions options) { this.options = options; } - public string FileName { + public override string FileName { get { return options.PythonFileName; } } - - public bool Debug { - get { return debug; } - set { debug = value; } - } - - public string PythonScriptFileName { - get { return pythonScriptFileName; } - set { pythonScriptFileName = value; } - } - - public string PythonScriptCommandLineArguments { - get { return pythonScriptCommandLineArguments; } - set { pythonScriptCommandLineArguments = value; } - } - - public string WorkingDirectory { - get { return workingDirectory; } - set { workingDirectory = value; } - } - - public ProcessStartInfo GetProcessStartInfo() - { - ProcessStartInfo processStartInfo = new ProcessStartInfo(); - processStartInfo.FileName = FileName; - processStartInfo.Arguments = GetArguments(); - processStartInfo.WorkingDirectory = workingDirectory; - return processStartInfo; - } - - public string GetArguments() - { - arguments = new StringBuilder(); - - AppendBooleanOptionIfTrue("-X:Debug", debug); - AppendQuotedStringIfNotEmpty(pythonScriptFileName); - AppendStringIfNotEmpty(pythonScriptCommandLineArguments); - - return arguments.ToString().TrimEnd(); - } - - void AppendBooleanOptionIfTrue(string option, bool flag) - { - if (flag) { - AppendOption(option); - } - } - - void AppendOption(string option) - { - arguments.Append(option + " "); - } - - void AppendQuotedStringIfNotEmpty(string option) - { - if (!String.IsNullOrEmpty(option)) { - AppendQuotedString(option); - } - } - - void AppendQuotedString(string option) - { - string quotedOption = String.Format("\"{0}\"", option); - AppendOption(quotedOption); - } - - void AppendStringIfNotEmpty(string option) + + protected override void AddArguments(ScriptingCommandLineBuilder commandLine) { - if (!String.IsNullOrEmpty(option)) { - AppendOption(option); - } + commandLine.AppendBooleanOptionIfTrue("-X:Debug", Debug); + commandLine.AppendQuotedStringIfNotEmpty(ScriptFileName); + commandLine.AppendStringIfNotEmpty(ScriptCommandLineArguments); } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunnerApplication.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunnerApplication.cs index 2641dded3e..8b2b80ea61 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunnerApplication.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunnerApplication.cs @@ -83,8 +83,8 @@ namespace ICSharpCode.PythonBinding public ProcessStartInfo CreateProcessStartInfo(SelectedTests selectedTests) { - consoleApplication.PythonScriptFileName = GetSharpDevelopTestPythonScriptFileName(); - consoleApplication.PythonScriptCommandLineArguments = GetResponseFileNameCommandLineArgument(); + consoleApplication.ScriptFileName = GetSharpDevelopTestPythonScriptFileName(); + consoleApplication.ScriptCommandLineArguments = GetResponseFileNameCommandLineArgument(); consoleApplication.WorkingDirectory = selectedTests.Project.Directory; return consoleApplication.GetProcessStartInfo(); } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs index 21efb99590..7f8d1e75a3 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs @@ -56,7 +56,7 @@ namespace ICSharpCode.PythonBinding ProcessStartInfo GetProcessStartInfo() { string scriptFileName = workbench.ActiveViewContent.PrimaryFileName; - ipy.PythonScriptFileName = scriptFileName; + ipy.ScriptFileName = scriptFileName; ipy.WorkingDirectory = Path.GetDirectoryName(scriptFileName); return ipy.GetProcessStartInfo(); } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj index 07640e3197..f028a53657 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj @@ -397,7 +397,7 @@ - + diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonConsoleApplicationTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonConsoleApplicationTests.cs similarity index 52% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonConsoleApplicationTestFixture.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonConsoleApplicationTests.cs index fe6b44fda4..c9c4efe1cc 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonConsoleApplicationTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonConsoleApplicationTests.cs @@ -11,7 +11,7 @@ using PythonBinding.Tests.Utils; namespace PythonBinding.Tests.Testing { [TestFixture] - public class PythonConsoleApplicationTestFixture + public class PythonConsoleApplicationTests { PythonConsoleApplication app; PythonAddInOptions options; @@ -25,44 +25,48 @@ namespace PythonBinding.Tests.Testing } [Test] - public void FileNameIsPythonFileNameFromAddInOptions() + public void FileName_NewInstance_FileNameIsPythonFileNameFromAddInOptions() { + string fileName = app.FileName; string expectedFileName = @"C:\IronPython\ipy.exe"; - Assert.AreEqual(expectedFileName, app.FileName); + Assert.AreEqual(expectedFileName, fileName); } [Test] - public void GetArgumentsReturnsDebugOptionWhenDebugIsTrue() + public void GetArguments_DebugIsTrue_ReturnsDebugOption() { app.Debug = true; + string args = app.GetArguments(); string expectedCommandLine = "-X:Debug"; - Assert.AreEqual(expectedCommandLine, app.GetArguments()); + Assert.AreEqual(expectedCommandLine, args); } [Test] - public void GetArgumentsReturnsQuotedPythonScriptFileName() + public void GetArguments_ScriptFileNameSet_ReturnsQuotedPythonScriptFileName() { - app.PythonScriptFileName = @"d:\projects\my ipy\test.py"; + app.ScriptFileName = @"d:\projects\my ipy\test.py"; + string args = app.GetArguments(); string expectedCommandLine = "\"d:\\projects\\my ipy\\test.py\""; - Assert.AreEqual(expectedCommandLine, app.GetArguments()); + Assert.AreEqual(expectedCommandLine, args); } [Test] - public void GetArgumentsReturnsQuotedPythonScriptFileNameAndItsCommandLineArguments() + public void GetArguments_ScriptFileNameAndScriptCommandLineArgsSet_ReturnsQuotedPythonScriptFileNameAndItsCommandLineArguments() { app.Debug = true; - app.PythonScriptFileName = @"d:\projects\my ipy\test.py"; - app.PythonScriptCommandLineArguments = "@responseFile.txt -def"; + app.ScriptFileName = @"d:\projects\my ipy\test.py"; + app.ScriptCommandLineArguments = "@responseFile.txt -def"; + string args = app.GetArguments(); string expectedCommandLine = "-X:Debug \"d:\\projects\\my ipy\\test.py\" @responseFile.txt -def"; - Assert.AreEqual(expectedCommandLine, app.GetArguments()); + Assert.AreEqual(expectedCommandLine, args); } [Test] - public void GetProcessStartInfoHasFileNameThatEqualsIronPythonConsoleApplicationExeFileName() + public void GetProcessStartInfo_NewInstance_ReturnsProcessStartInfoWithFileNameThatEqualsIronPythonConsoleApplicationExeFileName() { ProcessStartInfo startInfo = app.GetProcessStartInfo(); string expectedFileName = @"C:\IronPython\ipy.exe"; @@ -71,7 +75,7 @@ namespace PythonBinding.Tests.Testing } [Test] - public void GetProcessStartInfoHasDebugFlagSetInArguments() + public void GetProcessStartInfo_DebugIsTrue_ReturnsProcessStartInfoWithDebugFlagSetInArguments() { app.Debug = true; ProcessStartInfo startInfo = app.GetProcessStartInfo(); @@ -81,20 +85,21 @@ namespace PythonBinding.Tests.Testing } [Test] - public void GetProcessStartInfoHasWorkingDirectoryIfSet() + public void GetProcessStartInfo_WorkingDirectorySet_ReturnsProcessStartInfoWithMatchingWorkingDirectory() { app.WorkingDirectory = @"d:\temp"; ProcessStartInfo startInfo = app.GetProcessStartInfo(); - Assert.AreEqual(@"d:\temp", startInfo.WorkingDirectory); + string expectedDirectory = @"d:\temp"; + Assert.AreEqual(expectedDirectory, startInfo.WorkingDirectory); } [Test] - public void ChangingOptionsPythonFileNameChangesProcessStartInfoFileName() + public void GetProcessStartInfo_ChangingPythonOptionsFileName_ProcessStartInfoFileNameMatchesChange() { options.PythonFileName = @"d:\temp\test\ipy.exe"; ProcessStartInfo startInfo = app.GetProcessStartInfo(); - - Assert.AreEqual(@"d:\temp\test\ipy.exe", startInfo.FileName); + string expectedFileName = @"d:\temp\test\ipy.exe"; + Assert.AreEqual(expectedFileName, startInfo.FileName); } } } diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsoleApplication.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsoleApplication.cs index d32bcbc60f..84603d0867 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsoleApplication.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsoleApplication.cs @@ -6,110 +6,41 @@ using System.Collections.Generic; using System.Diagnostics; using System.Text; +using ICSharpCode.Scripting; + namespace ICSharpCode.RubyBinding { - public class RubyConsoleApplication + public class RubyConsoleApplication : ScriptingConsoleApplication { RubyAddInOptions options; - bool debug; List loadPaths = new List(); - string rubyScriptFileName = String.Empty; - string rubyScriptCommandLineArguments = String.Empty; - string workingDirectory = String.Empty; - string loadPath = String.Empty; - StringBuilder arguments; public RubyConsoleApplication(RubyAddInOptions options) { this.options = options; } - public string FileName { + public override string FileName { get { return options.RubyFileName; } } - public bool Debug { - get { return debug; } - set { debug = value; } - } - public void AddLoadPath(string path) { loadPaths.Add(path); } - public string RubyScriptFileName { - get { return rubyScriptFileName; } - set { rubyScriptFileName = value; } - } - - public string RubyScriptCommandLineArguments { - get { return rubyScriptCommandLineArguments; } - set { rubyScriptCommandLineArguments = value; } - } - - public string WorkingDirectory { - get { return workingDirectory; } - set { workingDirectory = value; } - } - - public ProcessStartInfo GetProcessStartInfo() - { - ProcessStartInfo processStartInfo = new ProcessStartInfo(); - processStartInfo.FileName = FileName; - processStartInfo.Arguments = GetArguments(); - processStartInfo.WorkingDirectory = workingDirectory; - return processStartInfo; - } - - public string GetArguments() - { - arguments = new StringBuilder(); - - AppendBooleanOptionIfTrue("-D", debug); - AppendLoadPaths(); - AppendQuotedStringIfNotEmpty(rubyScriptFileName); - AppendStringIfNotEmpty(rubyScriptCommandLineArguments); - - return arguments.ToString().TrimEnd(); - } - - void AppendBooleanOptionIfTrue(string option, bool flag) + protected override void AddArguments(ScriptingCommandLineBuilder commandLine) { - if (flag) { - AppendOption(option); - } - } - - void AppendOption(string option) - { - arguments.Append(option + " "); + commandLine.AppendBooleanOptionIfTrue("-D", Debug); + AppendLoadPaths(commandLine); + commandLine.AppendQuotedStringIfNotEmpty(ScriptFileName); + commandLine.AppendStringIfNotEmpty(ScriptCommandLineArguments); } - void AppendLoadPaths() + void AppendLoadPaths(ScriptingCommandLineBuilder commandLine) { foreach (string path in loadPaths) { - AppendQuotedString("-I" + path); - } - } - - void AppendQuotedStringIfNotEmpty(string option) - { - if (!String.IsNullOrEmpty(option)) { - AppendQuotedString(option); - } - } - - void AppendQuotedString(string option) - { - string quotedOption = String.Format("\"{0}\"", option); - AppendOption(quotedOption); - } - - void AppendStringIfNotEmpty(string option) - { - if (!String.IsNullOrEmpty(option)) { - AppendOption(option); + commandLine.AppendQuotedString("-I" + path); } } } diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestRunnerApplication.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestRunnerApplication.cs index 54fe17b63d..b77123dc38 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestRunnerApplication.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestRunnerApplication.cs @@ -66,9 +66,9 @@ namespace ICSharpCode.RubyBinding public ProcessStartInfo CreateProcessStartInfo(SelectedTests selectedTests) { - consoleApplication.RubyScriptFileName = GetSharpDevelopTestRubyScriptFileName(); + consoleApplication.ScriptFileName = GetSharpDevelopTestRubyScriptFileName(); AddLoadPaths(selectedTests.Project); - consoleApplication.RubyScriptCommandLineArguments = GetCommandLineArguments(selectedTests); + consoleApplication.ScriptCommandLineArguments = GetCommandLineArguments(selectedTests); consoleApplication.WorkingDirectory = selectedTests.Project.Directory; return consoleApplication.GetProcessStartInfo(); } @@ -84,7 +84,7 @@ namespace ICSharpCode.RubyBinding if (options.HasRubyLibraryPath) { consoleApplication.AddLoadPath(options.RubyLibraryPath); } - string testRunnerLoadPath = Path.GetDirectoryName(consoleApplication.RubyScriptFileName); + string testRunnerLoadPath = Path.GetDirectoryName(consoleApplication.ScriptFileName); consoleApplication.AddLoadPath(testRunnerLoadPath); } diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RunRubyCommand.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RunRubyCommand.cs index 2026888771..e744fc2853 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RunRubyCommand.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RunRubyCommand.cs @@ -22,7 +22,7 @@ namespace ICSharpCode.RubyBinding IDebugger debugger; RubyAddInOptions options; IScriptingWorkbench workbench; - bool debug; + RubyConsoleApplication rubyConsoleApplication; public RunRubyCommand() : this(new RubyWorkbench(), new RubyAddInOptions(), DebuggerService.CurrentDebugger) @@ -34,17 +34,18 @@ namespace ICSharpCode.RubyBinding this.workbench = workbench; this.debugger = debugger; this.options = options; + rubyConsoleApplication = new RubyConsoleApplication(options); } public bool Debug { - get { return debug; } - set { debug = value; } + get { return rubyConsoleApplication.Debug; } + set { rubyConsoleApplication.Debug = value; } } public override void Run() { ProcessStartInfo processStartInfo = CreateProcessStartInfo(); - if (debug) { + if (Debug) { debugger.Start(processStartInfo); } else { PauseCommandPromptProcessStartInfo commandPrompt = new PauseCommandPromptProcessStartInfo(processStartInfo); @@ -54,12 +55,9 @@ namespace ICSharpCode.RubyBinding ProcessStartInfo CreateProcessStartInfo() { - ProcessStartInfo info = new ProcessStartInfo(); - info.FileName = options.RubyFileName; - info.Arguments = GetArguments(); - info.WorkingDirectory = GetWorkingDirectory(); - - return info; + rubyConsoleApplication.ScriptFileName = GetRubyScriptFileName(); + rubyConsoleApplication.WorkingDirectory = GetWorkingDirectory(); + return rubyConsoleApplication.GetProcessStartInfo(); } string GetWorkingDirectory() @@ -71,15 +69,6 @@ namespace ICSharpCode.RubyBinding get { return workbench.ActiveViewContent.PrimaryFileName; } } - string GetArguments() - { - string args = GetRubyScriptFileName(); - if (Debug) { - return "-D " + args; - } - return args; - } - string GetRubyScriptFileName() { return Path.GetFileName(WorkbenchPrimaryFileName); diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/DebugRunRubyCommandTests.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/DebugRunRubyCommandTests.cs index ecbbddc4ab..1f8fd8ccac 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/DebugRunRubyCommandTests.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/DebugRunRubyCommandTests.cs @@ -52,7 +52,7 @@ namespace RubyBinding.Tests.Gui public void Run_RubyFileOpen_ProcessInfoArgsHasDebugArgument() { string arguments = debugger.ProcessStartInfo.Arguments; - string expectedArguments = "-D test.rb"; + string expectedArguments = "-D \"test.rb\""; Assert.AreEqual(expectedArguments, arguments); } diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/RunRubyCommandTests.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/RunRubyCommandTests.cs index bafa270e62..1ba2d2d20e 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/RunRubyCommandTests.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/RunRubyCommandTests.cs @@ -62,7 +62,7 @@ namespace RubyBinding.Tests.Gui public void Run_RubyFileOpen_ProcessInfoArgsContainsFileNameActiveInTextEditor() { string arguments = debugger.ProcessStartInfo.Arguments; - string expectedArguments = "/c \"C:\\IronRuby\\ir.exe test.rb\" & pause"; + string expectedArguments = "/c \"C:\\IronRuby\\ir.exe \"test.rb\"\" & pause"; Assert.AreEqual(expectedArguments, arguments); } diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj index 67796542f2..1d31f9d487 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj @@ -289,7 +289,7 @@ - + diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Testing/RubyConsoleApplicationTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Testing/RubyConsoleApplicationTests.cs similarity index 58% rename from src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Testing/RubyConsoleApplicationTestFixture.cs rename to src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Testing/RubyConsoleApplicationTests.cs index 21ed0b8c09..02e43e0ff0 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Testing/RubyConsoleApplicationTestFixture.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Testing/RubyConsoleApplicationTests.cs @@ -11,7 +11,7 @@ using RubyBinding.Tests.Utils; namespace RubyBinding.Tests.Testing { [TestFixture] - public class RubyConsoleApplicationTestFixture + public class RubyConsoleApplicationTests { RubyConsoleApplication app; RubyAddInOptions options; @@ -25,44 +25,49 @@ namespace RubyBinding.Tests.Testing } [Test] - public void FileNameIsRubyFileNameFromAddInOptions() + public void FileName_NewInstance_FileNameIsRubyFileNameFromAddInOptions() { + string fileName = app.FileName; string expectedFileName = @"C:\IronRuby\ir.exe"; - Assert.AreEqual(expectedFileName, app.FileName); + Assert.AreEqual(expectedFileName, fileName); } [Test] - public void GetArgumentsReturnsDebugOptionWhenDebugIsTrue() + public void GetArguments_DebugIsTrue_ReturnsDebugOption() { app.Debug = true; + string args = app.GetArguments(); string expectedCommandLine = "-D"; - Assert.AreEqual(expectedCommandLine, app.GetArguments()); + Assert.AreEqual(expectedCommandLine, args); } [Test] - public void GetArgumentsReturnsQuotedRubyScriptFileName() + public void GetArguments_ScriptFileNameIsSet_ReturnsQuotedRubyScriptFileName() { - app.RubyScriptFileName = @"d:\projects\my ruby\test.rb"; + app.ScriptFileName = @"d:\projects\my ruby\test.rb"; + string args = app.GetArguments(); string expectedCommandLine = "\"d:\\projects\\my ruby\\test.rb\""; - Assert.AreEqual(expectedCommandLine, app.GetArguments()); + Assert.AreEqual(expectedCommandLine, args); } [Test] - public void GetArgumentsReturnsQuotedRubyScriptFileNameAndItsCommandLineArguments() + public void GetArguments_ScriptFileNameAndScriptCommandLineArgumentsSet_ReturnsQuotedRubyScriptFileNameAndItsCommandLineArguments() { app.Debug = true; - app.RubyScriptFileName = @"d:\projects\my ruby\test.rb"; - app.RubyScriptCommandLineArguments = "-- responseFile.txt"; + app.ScriptFileName = @"d:\projects\my ruby\test.rb"; + app.ScriptCommandLineArguments = "-- responseFile.txt"; + string args = app.GetArguments(); + string expectedCommandLine = "-D \"d:\\projects\\my ruby\\test.rb\" -- responseFile.txt"; - Assert.AreEqual(expectedCommandLine, app.GetArguments()); + Assert.AreEqual(expectedCommandLine, args); } [Test] - public void GetProcessStartInfoHasFileNameThatEqualsIronRubyConsoleApplicationExeFileName() + public void GetProcessStartInfo_NewInstance_HasFileNameThatEqualsIronRubyConsoleApplicationExeFileName() { ProcessStartInfo startInfo = app.GetProcessStartInfo(); string expectedFileName = @"C:\IronRuby\ir.exe"; @@ -71,7 +76,7 @@ namespace RubyBinding.Tests.Testing } [Test] - public void GetProcessStartInfoHasDebugFlagSetInArguments() + public void GetProcessStartInfo_DebugIsTrue_HasDebugFlagSetInArguments() { app.Debug = true; ProcessStartInfo startInfo = app.GetProcessStartInfo(); @@ -81,7 +86,7 @@ namespace RubyBinding.Tests.Testing } [Test] - public void GetProcessStartInfoHasWorkingDirectoryIfSet() + public void GetProcessStartInfo_WorkingDirectorySet_ProcessStartInfoHasMatchingWorkingDirectory() { app.WorkingDirectory = @"d:\temp"; ProcessStartInfo startInfo = app.GetProcessStartInfo(); @@ -89,7 +94,7 @@ namespace RubyBinding.Tests.Testing } [Test] - public void ChangingOptionsRubyFileNameChangesProcessStartInfoFileName() + public void GetProcessStartInfo_ChangingOptionsRubyFileName_ChangesProcessStartInfoFileName() { options.RubyFileName = @"d:\temp\test\ir.exe"; ProcessStartInfo startInfo = app.GetProcessStartInfo(); diff --git a/src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj b/src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj index 3d692cc779..58282e9272 100644 --- a/src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj +++ b/src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj @@ -82,7 +82,9 @@ + + diff --git a/src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingCommandLineBuilder.cs b/src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingCommandLineBuilder.cs new file mode 100644 index 0000000000..4ade27ea23 --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingCommandLineBuilder.cs @@ -0,0 +1,54 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Text; + +namespace ICSharpCode.Scripting +{ + public class ScriptingCommandLineBuilder + { + StringBuilder commandLine = new StringBuilder(); + + public ScriptingCommandLineBuilder() + { + } + + public override string ToString() + { + return commandLine.ToString().TrimEnd(); + } + + public void AppendBooleanOptionIfTrue(string option, bool flag) + { + if (flag) { + AppendOption(option); + } + } + + public void AppendOption(string option) + { + commandLine.Append(option + " "); + } + + public void AppendQuotedStringIfNotEmpty(string option) + { + if (!String.IsNullOrEmpty(option)) { + AppendQuotedString(option); + } + } + + public void AppendQuotedString(string option) + { + string quotedOption = String.Format("\"{0}\"", option); + AppendOption(quotedOption); + } + + public void AppendStringIfNotEmpty(string option) + { + if (!String.IsNullOrEmpty(option)) { + AppendOption(option); + } + } + } +} diff --git a/src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleApplication.cs b/src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleApplication.cs new file mode 100644 index 0000000000..8d126b87b9 --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleApplication.cs @@ -0,0 +1,52 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Diagnostics; +using System.Text; + +namespace ICSharpCode.Scripting +{ + public abstract class ScriptingConsoleApplication + { + public ScriptingConsoleApplication() + { + WorkingDirectory = String.Empty; + ScriptFileName = String.Empty; + ScriptCommandLineArguments = String.Empty; + } + + public bool Debug { get; set; } + + /// + /// Console application filename. + /// + public virtual string FileName { get; set; } + + public string WorkingDirectory { get; set; } + + public string ScriptFileName { get; set; } + + public string ScriptCommandLineArguments { get; set; } + + public ProcessStartInfo GetProcessStartInfo() + { + ProcessStartInfo processStartInfo = new ProcessStartInfo(); + processStartInfo.FileName = FileName; + processStartInfo.Arguments = GetArguments(); + processStartInfo.WorkingDirectory = WorkingDirectory; + return processStartInfo; + } + + public string GetArguments() + { + ScriptingCommandLineBuilder commandLine = new ScriptingCommandLineBuilder(); + AddArguments(commandLine); + return commandLine.ToString(); + } + + protected virtual void AddArguments(ScriptingCommandLineBuilder commandLine) + { + } + } +}