Browse Source

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

pull/1/head
mrward 15 years ago
parent
commit
fc508ad174
  1. 85
      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

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

@ -4,97 +4,28 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Text; using System.Text;
using ICSharpCode.Scripting;
namespace ICSharpCode.PythonBinding namespace ICSharpCode.PythonBinding
{ {
public class PythonConsoleApplication public class PythonConsoleApplication : ScriptingConsoleApplication
{ {
PythonAddInOptions options; PythonAddInOptions options;
StringBuilder arguments;
bool debug;
string pythonScriptFileName = String.Empty;
string pythonScriptCommandLineArguments = String.Empty;
string workingDirectory = String.Empty;
public PythonConsoleApplication(PythonAddInOptions options) public PythonConsoleApplication(PythonAddInOptions options)
{ {
this.options = options; this.options = options;
} }
public string FileName { public override string FileName {
get { return options.PythonFileName; } get { return options.PythonFileName; }
} }
public bool Debug { protected override void AddArguments(ScriptingCommandLineBuilder commandLine)
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)
{ {
if (!String.IsNullOrEmpty(option)) { commandLine.AppendBooleanOptionIfTrue("-X:Debug", Debug);
AppendOption(option); commandLine.AppendQuotedStringIfNotEmpty(ScriptFileName);
} commandLine.AppendStringIfNotEmpty(ScriptCommandLineArguments);
} }
} }
} }

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

@ -83,8 +83,8 @@ namespace ICSharpCode.PythonBinding
public ProcessStartInfo CreateProcessStartInfo(SelectedTests selectedTests) public ProcessStartInfo CreateProcessStartInfo(SelectedTests selectedTests)
{ {
consoleApplication.PythonScriptFileName = GetSharpDevelopTestPythonScriptFileName(); consoleApplication.ScriptFileName = GetSharpDevelopTestPythonScriptFileName();
consoleApplication.PythonScriptCommandLineArguments = GetResponseFileNameCommandLineArgument(); consoleApplication.ScriptCommandLineArguments = GetResponseFileNameCommandLineArgument();
consoleApplication.WorkingDirectory = selectedTests.Project.Directory; consoleApplication.WorkingDirectory = selectedTests.Project.Directory;
return consoleApplication.GetProcessStartInfo(); return consoleApplication.GetProcessStartInfo();
} }

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

@ -56,7 +56,7 @@ namespace ICSharpCode.PythonBinding
ProcessStartInfo GetProcessStartInfo() ProcessStartInfo GetProcessStartInfo()
{ {
string scriptFileName = workbench.ActiveViewContent.PrimaryFileName; string scriptFileName = workbench.ActiveViewContent.PrimaryFileName;
ipy.PythonScriptFileName = scriptFileName; ipy.ScriptFileName = scriptFileName;
ipy.WorkingDirectory = Path.GetDirectoryName(scriptFileName); ipy.WorkingDirectory = Path.GetDirectoryName(scriptFileName);
return ipy.GetProcessStartInfo(); return ipy.GetProcessStartInfo();
} }

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

@ -397,7 +397,7 @@
<Compile Include="Resolver\ResolveTextBoxFromSystemWindowsFormsImportTextBoxTests.cs" /> <Compile Include="Resolver\ResolveTextBoxFromSystemWindowsFormsImportTextBoxTests.cs" />
<Compile Include="Resolver\ResolveUnknownNamespaceTests.cs" /> <Compile Include="Resolver\ResolveUnknownNamespaceTests.cs" />
<Compile Include="Testing\CreatePythonTestRunnerTestFixture.cs" /> <Compile Include="Testing\CreatePythonTestRunnerTestFixture.cs" />
<Compile Include="Testing\PythonConsoleApplicationTestFixture.cs" /> <Compile Include="Testing\PythonConsoleApplicationTests.cs" />
<Compile Include="Testing\PythonStandardLibraryPathTests.cs" /> <Compile Include="Testing\PythonStandardLibraryPathTests.cs" />
<Compile Include="Testing\PythonTestDebuggerRunsSelectedTestMethodTestFixture.cs" /> <Compile Include="Testing\PythonTestDebuggerRunsSelectedTestMethodTestFixture.cs" />
<Compile Include="Testing\PythonTestFrameworkIsTestClassTests.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;
namespace PythonBinding.Tests.Testing namespace PythonBinding.Tests.Testing
{ {
[TestFixture] [TestFixture]
public class PythonConsoleApplicationTestFixture public class PythonConsoleApplicationTests
{ {
PythonConsoleApplication app; PythonConsoleApplication app;
PythonAddInOptions options; PythonAddInOptions options;
@ -25,44 +25,48 @@ namespace PythonBinding.Tests.Testing
} }
[Test] [Test]
public void FileNameIsPythonFileNameFromAddInOptions() public void FileName_NewInstance_FileNameIsPythonFileNameFromAddInOptions()
{ {
string fileName = app.FileName;
string expectedFileName = @"C:\IronPython\ipy.exe"; string expectedFileName = @"C:\IronPython\ipy.exe";
Assert.AreEqual(expectedFileName, app.FileName); Assert.AreEqual(expectedFileName, fileName);
} }
[Test] [Test]
public void GetArgumentsReturnsDebugOptionWhenDebugIsTrue() public void GetArguments_DebugIsTrue_ReturnsDebugOption()
{ {
app.Debug = true; app.Debug = true;
string args = app.GetArguments();
string expectedCommandLine = "-X:Debug"; string expectedCommandLine = "-X:Debug";
Assert.AreEqual(expectedCommandLine, app.GetArguments()); Assert.AreEqual(expectedCommandLine, args);
} }
[Test] [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\""; string expectedCommandLine = "\"d:\\projects\\my ipy\\test.py\"";
Assert.AreEqual(expectedCommandLine, app.GetArguments()); Assert.AreEqual(expectedCommandLine, args);
} }
[Test] [Test]
public void GetArgumentsReturnsQuotedPythonScriptFileNameAndItsCommandLineArguments() public void GetArguments_ScriptFileNameAndScriptCommandLineArgsSet_ReturnsQuotedPythonScriptFileNameAndItsCommandLineArguments()
{ {
app.Debug = true; app.Debug = true;
app.PythonScriptFileName = @"d:\projects\my ipy\test.py"; app.ScriptFileName = @"d:\projects\my ipy\test.py";
app.PythonScriptCommandLineArguments = "@responseFile.txt -def"; app.ScriptCommandLineArguments = "@responseFile.txt -def";
string args = app.GetArguments();
string expectedCommandLine = string expectedCommandLine =
"-X:Debug \"d:\\projects\\my ipy\\test.py\" @responseFile.txt -def"; "-X:Debug \"d:\\projects\\my ipy\\test.py\" @responseFile.txt -def";
Assert.AreEqual(expectedCommandLine, app.GetArguments()); Assert.AreEqual(expectedCommandLine, args);
} }
[Test] [Test]
public void GetProcessStartInfoHasFileNameThatEqualsIronPythonConsoleApplicationExeFileName() public void GetProcessStartInfo_NewInstance_ReturnsProcessStartInfoWithFileNameThatEqualsIronPythonConsoleApplicationExeFileName()
{ {
ProcessStartInfo startInfo = app.GetProcessStartInfo(); ProcessStartInfo startInfo = app.GetProcessStartInfo();
string expectedFileName = @"C:\IronPython\ipy.exe"; string expectedFileName = @"C:\IronPython\ipy.exe";
@ -71,7 +75,7 @@ namespace PythonBinding.Tests.Testing
} }
[Test] [Test]
public void GetProcessStartInfoHasDebugFlagSetInArguments() public void GetProcessStartInfo_DebugIsTrue_ReturnsProcessStartInfoWithDebugFlagSetInArguments()
{ {
app.Debug = true; app.Debug = true;
ProcessStartInfo startInfo = app.GetProcessStartInfo(); ProcessStartInfo startInfo = app.GetProcessStartInfo();
@ -81,20 +85,21 @@ namespace PythonBinding.Tests.Testing
} }
[Test] [Test]
public void GetProcessStartInfoHasWorkingDirectoryIfSet() public void GetProcessStartInfo_WorkingDirectorySet_ReturnsProcessStartInfoWithMatchingWorkingDirectory()
{ {
app.WorkingDirectory = @"d:\temp"; app.WorkingDirectory = @"d:\temp";
ProcessStartInfo startInfo = app.GetProcessStartInfo(); ProcessStartInfo startInfo = app.GetProcessStartInfo();
Assert.AreEqual(@"d:\temp", startInfo.WorkingDirectory); string expectedDirectory = @"d:\temp";
Assert.AreEqual(expectedDirectory, startInfo.WorkingDirectory);
} }
[Test] [Test]
public void ChangingOptionsPythonFileNameChangesProcessStartInfoFileName() public void GetProcessStartInfo_ChangingPythonOptionsFileName_ProcessStartInfoFileNameMatchesChange()
{ {
options.PythonFileName = @"d:\temp\test\ipy.exe"; options.PythonFileName = @"d:\temp\test\ipy.exe";
ProcessStartInfo startInfo = app.GetProcessStartInfo(); ProcessStartInfo startInfo = app.GetProcessStartInfo();
string expectedFileName = @"d:\temp\test\ipy.exe";
Assert.AreEqual(@"d:\temp\test\ipy.exe", startInfo.FileName); Assert.AreEqual(expectedFileName, startInfo.FileName);
} }
} }
} }

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

@ -6,110 +6,41 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Text; using System.Text;
using ICSharpCode.Scripting;
namespace ICSharpCode.RubyBinding namespace ICSharpCode.RubyBinding
{ {
public class RubyConsoleApplication public class RubyConsoleApplication : ScriptingConsoleApplication
{ {
RubyAddInOptions options; RubyAddInOptions options;
bool debug;
List<string> loadPaths = new List<string>(); 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) public RubyConsoleApplication(RubyAddInOptions options)
{ {
this.options = options; this.options = options;
} }
public string FileName { public override string FileName {
get { return options.RubyFileName; } get { return options.RubyFileName; }
} }
public bool Debug {
get { return debug; }
set { debug = value; }
}
public void AddLoadPath(string path) public void AddLoadPath(string path)
{ {
loadPaths.Add(path); loadPaths.Add(path);
} }
public string RubyScriptFileName { protected override void AddArguments(ScriptingCommandLineBuilder commandLine)
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) { commandLine.AppendBooleanOptionIfTrue("-D", Debug);
AppendOption(option); AppendLoadPaths(commandLine);
} commandLine.AppendQuotedStringIfNotEmpty(ScriptFileName);
} commandLine.AppendStringIfNotEmpty(ScriptCommandLineArguments);
void AppendOption(string option)
{
arguments.Append(option + " ");
} }
void AppendLoadPaths() void AppendLoadPaths(ScriptingCommandLineBuilder commandLine)
{ {
foreach (string path in loadPaths) { foreach (string path in loadPaths) {
AppendQuotedString("-I" + path); commandLine.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);
} }
} }
} }

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

@ -66,9 +66,9 @@ namespace ICSharpCode.RubyBinding
public ProcessStartInfo CreateProcessStartInfo(SelectedTests selectedTests) public ProcessStartInfo CreateProcessStartInfo(SelectedTests selectedTests)
{ {
consoleApplication.RubyScriptFileName = GetSharpDevelopTestRubyScriptFileName(); consoleApplication.ScriptFileName = GetSharpDevelopTestRubyScriptFileName();
AddLoadPaths(selectedTests.Project); AddLoadPaths(selectedTests.Project);
consoleApplication.RubyScriptCommandLineArguments = GetCommandLineArguments(selectedTests); consoleApplication.ScriptCommandLineArguments = GetCommandLineArguments(selectedTests);
consoleApplication.WorkingDirectory = selectedTests.Project.Directory; consoleApplication.WorkingDirectory = selectedTests.Project.Directory;
return consoleApplication.GetProcessStartInfo(); return consoleApplication.GetProcessStartInfo();
} }
@ -84,7 +84,7 @@ namespace ICSharpCode.RubyBinding
if (options.HasRubyLibraryPath) { if (options.HasRubyLibraryPath) {
consoleApplication.AddLoadPath(options.RubyLibraryPath); consoleApplication.AddLoadPath(options.RubyLibraryPath);
} }
string testRunnerLoadPath = Path.GetDirectoryName(consoleApplication.RubyScriptFileName); string testRunnerLoadPath = Path.GetDirectoryName(consoleApplication.ScriptFileName);
consoleApplication.AddLoadPath(testRunnerLoadPath); consoleApplication.AddLoadPath(testRunnerLoadPath);
} }

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

@ -22,7 +22,7 @@ namespace ICSharpCode.RubyBinding
IDebugger debugger; IDebugger debugger;
RubyAddInOptions options; RubyAddInOptions options;
IScriptingWorkbench workbench; IScriptingWorkbench workbench;
bool debug; RubyConsoleApplication rubyConsoleApplication;
public RunRubyCommand() public RunRubyCommand()
: this(new RubyWorkbench(), new RubyAddInOptions(), DebuggerService.CurrentDebugger) : this(new RubyWorkbench(), new RubyAddInOptions(), DebuggerService.CurrentDebugger)
@ -34,17 +34,18 @@ namespace ICSharpCode.RubyBinding
this.workbench = workbench; this.workbench = workbench;
this.debugger = debugger; this.debugger = debugger;
this.options = options; this.options = options;
rubyConsoleApplication = new RubyConsoleApplication(options);
} }
public bool Debug { public bool Debug {
get { return debug; } get { return rubyConsoleApplication.Debug; }
set { debug = value; } set { rubyConsoleApplication.Debug = value; }
} }
public override void Run() public override void Run()
{ {
ProcessStartInfo processStartInfo = CreateProcessStartInfo(); ProcessStartInfo processStartInfo = CreateProcessStartInfo();
if (debug) { if (Debug) {
debugger.Start(processStartInfo); debugger.Start(processStartInfo);
} else { } else {
PauseCommandPromptProcessStartInfo commandPrompt = new PauseCommandPromptProcessStartInfo(processStartInfo); PauseCommandPromptProcessStartInfo commandPrompt = new PauseCommandPromptProcessStartInfo(processStartInfo);
@ -54,12 +55,9 @@ namespace ICSharpCode.RubyBinding
ProcessStartInfo CreateProcessStartInfo() ProcessStartInfo CreateProcessStartInfo()
{ {
ProcessStartInfo info = new ProcessStartInfo(); rubyConsoleApplication.ScriptFileName = GetRubyScriptFileName();
info.FileName = options.RubyFileName; rubyConsoleApplication.WorkingDirectory = GetWorkingDirectory();
info.Arguments = GetArguments(); return rubyConsoleApplication.GetProcessStartInfo();
info.WorkingDirectory = GetWorkingDirectory();
return info;
} }
string GetWorkingDirectory() string GetWorkingDirectory()
@ -71,15 +69,6 @@ namespace ICSharpCode.RubyBinding
get { return workbench.ActiveViewContent.PrimaryFileName; } get { return workbench.ActiveViewContent.PrimaryFileName; }
} }
string GetArguments()
{
string args = GetRubyScriptFileName();
if (Debug) {
return "-D " + args;
}
return args;
}
string GetRubyScriptFileName() string GetRubyScriptFileName()
{ {
return Path.GetFileName(WorkbenchPrimaryFileName); return Path.GetFileName(WorkbenchPrimaryFileName);

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

@ -52,7 +52,7 @@ namespace RubyBinding.Tests.Gui
public void Run_RubyFileOpen_ProcessInfoArgsHasDebugArgument() public void Run_RubyFileOpen_ProcessInfoArgsHasDebugArgument()
{ {
string arguments = debugger.ProcessStartInfo.Arguments; string arguments = debugger.ProcessStartInfo.Arguments;
string expectedArguments = "-D test.rb"; string expectedArguments = "-D \"test.rb\"";
Assert.AreEqual(expectedArguments, arguments); Assert.AreEqual(expectedArguments, arguments);
} }

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

@ -62,7 +62,7 @@ namespace RubyBinding.Tests.Gui
public void Run_RubyFileOpen_ProcessInfoArgsContainsFileNameActiveInTextEditor() public void Run_RubyFileOpen_ProcessInfoArgsContainsFileNameActiveInTextEditor()
{ {
string arguments = debugger.ProcessStartInfo.Arguments; 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); Assert.AreEqual(expectedArguments, arguments);
} }

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

@ -289,7 +289,7 @@
<Compile Include="RubyLanguage\RubyLanguageBindingTestFixture.cs" /> <Compile Include="RubyLanguage\RubyLanguageBindingTestFixture.cs" />
<Compile Include="RubyLanguage\RubyLanguagePropertiesTests.cs" /> <Compile Include="RubyLanguage\RubyLanguagePropertiesTests.cs" />
<Compile Include="Testing\CreateRubyTestRunnerTestFixture.cs" /> <Compile Include="Testing\CreateRubyTestRunnerTestFixture.cs" />
<Compile Include="Testing\RubyConsoleApplicationTestFixture.cs" /> <Compile Include="Testing\RubyConsoleApplicationTests.cs" />
<Compile Include="Testing\RubyTestDebuggerRunsSelectedTestMethodTestFixture.cs" /> <Compile Include="Testing\RubyTestDebuggerRunsSelectedTestMethodTestFixture.cs" />
<Compile Include="Testing\RubyTestFrameworkIsTestClassTests.cs" /> <Compile Include="Testing\RubyTestFrameworkIsTestClassTests.cs" />
<Compile Include="Testing\RubyTestFrameworkIsTestMethodTests.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;
namespace RubyBinding.Tests.Testing namespace RubyBinding.Tests.Testing
{ {
[TestFixture] [TestFixture]
public class RubyConsoleApplicationTestFixture public class RubyConsoleApplicationTests
{ {
RubyConsoleApplication app; RubyConsoleApplication app;
RubyAddInOptions options; RubyAddInOptions options;
@ -25,44 +25,49 @@ namespace RubyBinding.Tests.Testing
} }
[Test] [Test]
public void FileNameIsRubyFileNameFromAddInOptions() public void FileName_NewInstance_FileNameIsRubyFileNameFromAddInOptions()
{ {
string fileName = app.FileName;
string expectedFileName = @"C:\IronRuby\ir.exe"; string expectedFileName = @"C:\IronRuby\ir.exe";
Assert.AreEqual(expectedFileName, app.FileName); Assert.AreEqual(expectedFileName, fileName);
} }
[Test] [Test]
public void GetArgumentsReturnsDebugOptionWhenDebugIsTrue() public void GetArguments_DebugIsTrue_ReturnsDebugOption()
{ {
app.Debug = true; app.Debug = true;
string args = app.GetArguments();
string expectedCommandLine = "-D"; string expectedCommandLine = "-D";
Assert.AreEqual(expectedCommandLine, app.GetArguments()); Assert.AreEqual(expectedCommandLine, args);
} }
[Test] [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\""; string expectedCommandLine = "\"d:\\projects\\my ruby\\test.rb\"";
Assert.AreEqual(expectedCommandLine, app.GetArguments()); Assert.AreEqual(expectedCommandLine, args);
} }
[Test] [Test]
public void GetArgumentsReturnsQuotedRubyScriptFileNameAndItsCommandLineArguments() public void GetArguments_ScriptFileNameAndScriptCommandLineArgumentsSet_ReturnsQuotedRubyScriptFileNameAndItsCommandLineArguments()
{ {
app.Debug = true; app.Debug = true;
app.RubyScriptFileName = @"d:\projects\my ruby\test.rb"; app.ScriptFileName = @"d:\projects\my ruby\test.rb";
app.RubyScriptCommandLineArguments = "-- responseFile.txt"; app.ScriptCommandLineArguments = "-- responseFile.txt";
string args = app.GetArguments();
string expectedCommandLine = string expectedCommandLine =
"-D \"d:\\projects\\my ruby\\test.rb\" -- responseFile.txt"; "-D \"d:\\projects\\my ruby\\test.rb\" -- responseFile.txt";
Assert.AreEqual(expectedCommandLine, app.GetArguments()); Assert.AreEqual(expectedCommandLine, args);
} }
[Test] [Test]
public void GetProcessStartInfoHasFileNameThatEqualsIronRubyConsoleApplicationExeFileName() public void GetProcessStartInfo_NewInstance_HasFileNameThatEqualsIronRubyConsoleApplicationExeFileName()
{ {
ProcessStartInfo startInfo = app.GetProcessStartInfo(); ProcessStartInfo startInfo = app.GetProcessStartInfo();
string expectedFileName = @"C:\IronRuby\ir.exe"; string expectedFileName = @"C:\IronRuby\ir.exe";
@ -71,7 +76,7 @@ namespace RubyBinding.Tests.Testing
} }
[Test] [Test]
public void GetProcessStartInfoHasDebugFlagSetInArguments() public void GetProcessStartInfo_DebugIsTrue_HasDebugFlagSetInArguments()
{ {
app.Debug = true; app.Debug = true;
ProcessStartInfo startInfo = app.GetProcessStartInfo(); ProcessStartInfo startInfo = app.GetProcessStartInfo();
@ -81,7 +86,7 @@ namespace RubyBinding.Tests.Testing
} }
[Test] [Test]
public void GetProcessStartInfoHasWorkingDirectoryIfSet() public void GetProcessStartInfo_WorkingDirectorySet_ProcessStartInfoHasMatchingWorkingDirectory()
{ {
app.WorkingDirectory = @"d:\temp"; app.WorkingDirectory = @"d:\temp";
ProcessStartInfo startInfo = app.GetProcessStartInfo(); ProcessStartInfo startInfo = app.GetProcessStartInfo();
@ -89,7 +94,7 @@ namespace RubyBinding.Tests.Testing
} }
[Test] [Test]
public void ChangingOptionsRubyFileNameChangesProcessStartInfoFileName() public void GetProcessStartInfo_ChangingOptionsRubyFileName_ChangesProcessStartInfoFileName()
{ {
options.RubyFileName = @"d:\temp\test\ir.exe"; options.RubyFileName = @"d:\temp\test\ir.exe";
ProcessStartInfo startInfo = app.GetProcessStartInfo(); ProcessStartInfo startInfo = app.GetProcessStartInfo();

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

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

54
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);
}
}
}
}

52
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; }
/// <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