Browse Source

Move common IronRuby and IronPython console application code to Scripting project.

pull/1/head
mrward 15 years ago
parent
commit
fc508ad174
  1. 83
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleApplication.cs
  2. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunnerApplication.cs
  3. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs
  4. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  5. 43
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonConsoleApplicationTests.cs
  6. 91
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsoleApplication.cs
  7. 6
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestRunnerApplication.cs
  8. 27
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RunRubyCommand.cs
  9. 2
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/DebugRunRubyCommandTests.cs
  10. 2
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/RunRubyCommandTests.cs
  11. 2
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj
  12. 37
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Testing/RubyConsoleApplicationTests.cs
  13. 2
      src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj
  14. 54
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingCommandLineBuilder.cs
  15. 52
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleApplication.cs

83
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleApplication.cs

@ -4,97 +4,28 @@ @@ -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);
}
}
}

4
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunnerApplication.cs

@ -83,8 +83,8 @@ namespace ICSharpCode.PythonBinding @@ -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();
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.PythonBinding @@ -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();
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -397,7 +397,7 @@ @@ -397,7 +397,7 @@
<Compile Include="Resolver\ResolveTextBoxFromSystemWindowsFormsImportTextBoxTests.cs" />
<Compile Include="Resolver\ResolveUnknownNamespaceTests.cs" />
<Compile Include="Testing\CreatePythonTestRunnerTestFixture.cs" />
<Compile Include="Testing\PythonConsoleApplicationTestFixture.cs" />
<Compile Include="Testing\PythonConsoleApplicationTests.cs" />
<Compile Include="Testing\PythonStandardLibraryPathTests.cs" />
<Compile Include="Testing\PythonTestDebuggerRunsSelectedTestMethodTestFixture.cs" />
<Compile Include="Testing\PythonTestFrameworkIsTestClassTests.cs" />

43
src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonConsoleApplicationTestFixture.cs → src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonConsoleApplicationTests.cs

@ -11,7 +11,7 @@ using PythonBinding.Tests.Utils; @@ -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 @@ -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 @@ -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 @@ -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);
}
}
}

91
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyConsoleApplication.cs

@ -6,110 +6,41 @@ using System.Collections.Generic; @@ -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<string> loadPaths = new List<string>();
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)
{
if (flag) {
AppendOption(option);
}
}
void AppendOption(string option)
protected override void AddArguments(ScriptingCommandLineBuilder commandLine)
{
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);
}
}
}

6
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestRunnerApplication.cs

@ -66,9 +66,9 @@ namespace ICSharpCode.RubyBinding @@ -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 @@ -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);
}

27
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RunRubyCommand.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.RubyBinding @@ -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 @@ -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 @@ -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 @@ -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);

2
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/DebugRunRubyCommandTests.cs

@ -52,7 +52,7 @@ namespace RubyBinding.Tests.Gui @@ -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);
}

2
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Gui/RunRubyCommandTests.cs

@ -62,7 +62,7 @@ namespace RubyBinding.Tests.Gui @@ -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);
}

2
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj

@ -289,7 +289,7 @@ @@ -289,7 +289,7 @@
<Compile Include="RubyLanguage\RubyLanguageBindingTestFixture.cs" />
<Compile Include="RubyLanguage\RubyLanguagePropertiesTests.cs" />
<Compile Include="Testing\CreateRubyTestRunnerTestFixture.cs" />
<Compile Include="Testing\RubyConsoleApplicationTestFixture.cs" />
<Compile Include="Testing\RubyConsoleApplicationTests.cs" />
<Compile Include="Testing\RubyTestDebuggerRunsSelectedTestMethodTestFixture.cs" />
<Compile Include="Testing\RubyTestFrameworkIsTestClassTests.cs" />
<Compile Include="Testing\RubyTestFrameworkIsTestMethodTests.cs" />

37
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Testing/RubyConsoleApplicationTestFixture.cs → src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Testing/RubyConsoleApplicationTests.cs

@ -11,7 +11,7 @@ using RubyBinding.Tests.Utils; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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();

2
src/AddIns/BackendBindings/Scripting/Project/ICSharpCode.Scripting.csproj

@ -82,7 +82,9 @@ @@ -82,7 +82,9 @@
<Compile Include="Src\IScriptingWorkbench.cs" />
<Compile Include="Src\PauseCommandPromptProcessStartInfo.cs" />
<Compile Include="Src\ScriptingCodeBuilder.cs" />
<Compile Include="Src\ScriptingCommandLineBuilder.cs" />
<Compile Include="Src\ScriptingConsole.cs" />
<Compile Include="Src\ScriptingConsoleApplication.cs" />
<Compile Include="Src\ScriptingConsoleCompletionData.cs" />
<Compile Include="Src\ScriptingConsoleCompletionDataProvider.cs" />
<Compile Include="Src\ScriptingConsoleOutputStream.cs" />

54
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingCommandLineBuilder.cs

@ -0,0 +1,54 @@ @@ -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);
}
}
}
}

52
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingConsoleApplication.cs

@ -0,0 +1,52 @@ @@ -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; }
/// <summary>
/// Console application filename.
/// </summary>
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)
{
}
}
}
Loading…
Cancel
Save