Browse Source

IronRuby addin now adds the directories of referenced projects to the load path when running unit tests. This allows unit tests to be put in a separate project to the code under test.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6108 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Matt Ward 16 years ago
parent
commit
bb9007ce6d
  1. 22
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestRunnerApplication.cs
  2. 32
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Testing/RubyTestRunnerApplicationTests.cs

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

@ -11,6 +11,7 @@ using System.IO;
using System.Text; using System.Text;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting; using ICSharpCode.UnitTesting;
namespace ICSharpCode.RubyBinding namespace ICSharpCode.RubyBinding
@ -69,13 +70,19 @@ namespace ICSharpCode.RubyBinding
public ProcessStartInfo CreateProcessStartInfo(SelectedTests selectedTests) public ProcessStartInfo CreateProcessStartInfo(SelectedTests selectedTests)
{ {
consoleApplication.RubyScriptFileName = GetSharpDevelopTestRubyScriptFileName(); consoleApplication.RubyScriptFileName = GetSharpDevelopTestRubyScriptFileName();
AddLoadPaths(); AddLoadPaths(selectedTests.Project);
consoleApplication.RubyScriptCommandLineArguments = GetCommandLineArguments(selectedTests); consoleApplication.RubyScriptCommandLineArguments = GetCommandLineArguments(selectedTests);
consoleApplication.WorkingDirectory = selectedTests.Project.Directory; consoleApplication.WorkingDirectory = selectedTests.Project.Directory;
return consoleApplication.GetProcessStartInfo(); return consoleApplication.GetProcessStartInfo();
} }
void AddLoadPaths() void AddLoadPaths(IProject project)
{
AddLoadPathForRubyStandardLibrary();
AddLoadPathForReferencedProjects(project);
}
void AddLoadPathForRubyStandardLibrary()
{ {
if (options.HasRubyLibraryPath) { if (options.HasRubyLibraryPath) {
consoleApplication.AddLoadPath(options.RubyLibraryPath); consoleApplication.AddLoadPath(options.RubyLibraryPath);
@ -84,6 +91,17 @@ namespace ICSharpCode.RubyBinding
consoleApplication.AddLoadPath(testRunnerLoadPath); consoleApplication.AddLoadPath(testRunnerLoadPath);
} }
void AddLoadPathForReferencedProjects(IProject project)
{
foreach (ProjectItem item in project.Items) {
ProjectReferenceProjectItem projectRef = item as ProjectReferenceProjectItem;
if (projectRef != null) {
string directory = Path.GetDirectoryName(projectRef.FileName);
consoleApplication.AddLoadPath(directory);
}
}
}
string GetSharpDevelopTestRubyScriptFileName() string GetSharpDevelopTestRubyScriptFileName()
{ {
string fileName = StringParser.Parse(@"${addinpath:ICSharpCode.RubyBinding}\TestRunner\sdtest.rb"); string fileName = StringParser.Parse(@"${addinpath:ICSharpCode.RubyBinding}\TestRunner\sdtest.rb");

32
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Testing/RubyTestRunnerApplicationTests.cs

@ -11,6 +11,7 @@ using System.Diagnostics;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.RubyBinding; using ICSharpCode.RubyBinding;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting; using ICSharpCode.UnitTesting;
using NUnit.Framework; using NUnit.Framework;
using RubyBinding.Tests.Testing; using RubyBinding.Tests.Testing;
@ -125,5 +126,36 @@ namespace RubyBinding.Tests.Testing
Assert.AreEqual(expectedCommandLine, processStartInfo.Arguments); Assert.AreEqual(expectedCommandLine, processStartInfo.Arguments);
} }
[Test]
public void CreateProcessInfoReturnsCommandLineWithDirectoriesForReferencedProjects()
{
MockCSharpProject referencedProject = new MockCSharpProject();
referencedProject.FileName = @"c:\projects\rbproject\rbproject.rbproj";
MockCSharpProject unitTestProject = new MockCSharpProject();
ProjectReferenceProjectItem projectRef = new ProjectReferenceProjectItem(unitTestProject, referencedProject);
projectRef.FileName = @"c:\projects\rbproject\pyproject.rbproj";
ProjectService.AddProjectItem(unitTestProject, projectRef);
MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes();
method.CompilationUnit.FileName = @"d:\mytest.rb";
FileProjectItem fileItem = new FileProjectItem(unitTestProject, ItemType.Compile);
fileItem.FileName = @"d:\mytest.rb";
ProjectService.AddProjectItem(unitTestProject, fileItem);
SelectedTests tests = RubySelectedTestsHelper.CreateSelectedTests(unitTestProject);
ProcessStartInfo processStartInfo = GetProcessStartInfoFromTestRunnerApp(tests);
string expectedCommandLine =
"\"-Ic:\\rubybinding\\TestRunner\" " +
"\"-Ic:\\projects\\rbproject\" " +
"\"c:\\rubybinding\\TestRunner\\sdtest.rb\" " +
"-- " +
"\"results.txt\" " +
"\"temp.tmp\"";
Assert.AreEqual(expectedCommandLine, processStartInfo.Arguments);
}
} }
} }

Loading…
Cancel
Save