Browse Source

Use 32-bit NUnit to run AnyCPU tests.

This allows debugging unit tests without having to set the target framework to x86.
pull/28/head
Daniel Grunwald 13 years ago
parent
commit
85cb6c3a9f
  1. 11
      src/AddIns/Analysis/UnitTesting/Src/NUnitConsoleApplication.cs
  2. 40
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitConsoleExeSelectedTestFixture.cs

11
src/AddIns/Analysis/UnitTesting/Src/NUnitConsoleApplication.cs

@ -82,7 +82,9 @@ namespace ICSharpCode.UnitTesting @@ -82,7 +82,9 @@ namespace ICSharpCode.UnitTesting
if (ProjectUsesDotnet20Runtime(project)) {
exe += "-dotnet2";
}
if (IsPlatformTarget32Bit(project)) {
// As SharpDevelop can't debug 64-bit applications yet, use
// 32-bit NUnit even for AnyCPU test projects.
if (IsPlatformTarget32BitOrAnyCPU(project)) {
exe += "-x86";
}
exe += ".exe";
@ -234,14 +236,15 @@ namespace ICSharpCode.UnitTesting @@ -234,14 +236,15 @@ namespace ICSharpCode.UnitTesting
}
/// <summary>
/// Checks that the project's PlatformTarget is x86 for the active configuration.
/// Checks that the project's PlatformTarget is x32 for the active configuration.
/// </summary>
bool IsPlatformTarget32Bit(IProject project)
bool IsPlatformTarget32BitOrAnyCPU(IProject project)
{
MSBuildBasedProject msbuildProject = project as MSBuildBasedProject;
if (msbuildProject != null) {
string platformTarget = msbuildProject.GetEvaluatedProperty("PlatformTarget");
return String.Compare(platformTarget, "x86", true) == 0;
return String.Equals(platformTarget, "x86", StringComparison.OrdinalIgnoreCase)
|| String.Equals(platformTarget, "AnyCPU", StringComparison.OrdinalIgnoreCase);
}
return false;
}

40
src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitConsoleExeSelectedTestFixture.cs

@ -11,7 +11,7 @@ using UnitTesting.Tests.Utils; @@ -11,7 +11,7 @@ using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
/// <summary>
/// If the project explicitly targets 32 bit (x86) architecture then nunit-console-x86.exe should be
/// If the project explicitly targets 32 bit (x86) architecture then nunit-console-x86.exe should be
/// used. Otherwise the normal nunit-console.exe is used.
/// </summary>
[TestFixture]
@ -52,7 +52,8 @@ namespace UnitTesting.Tests.Frameworks @@ -52,7 +52,8 @@ namespace UnitTesting.Tests.Frameworks
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-dotnet2.exe", app.FileName);
// We use 32-bit NUnit to test AnyCPU projects because the debugger doesn't support 64-bit
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-dotnet2-x86.exe", app.FileName);
}
[Test]
@ -64,6 +65,35 @@ namespace UnitTesting.Tests.Frameworks @@ -64,6 +65,35 @@ namespace UnitTesting.Tests.Frameworks
project.SetProperty("PlatformTarget", "AnyCPU");
project.SetProperty("TargetFrameworkVersion", "v4.5");
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
// We use 32-bit NUnit to test AnyCPU projects because the debugger doesn't support 64-bit
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-x86.exe", app.FileName);
}
[Test]
public void TargetCpuX64Dotnet2()
{
MockCSharpProject project = new MockCSharpProject();
project.ActiveConfiguration = "Debug";
project.ActivePlatform = "AnyCPU";
project.SetProperty("PlatformTarget", "x64");
project.SetProperty("TargetFrameworkVersion", "v3.5");
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-dotnet2.exe", app.FileName);
}
[Test]
public void TargetCpuX64Dotnet45()
{
MockCSharpProject project = new MockCSharpProject();
project.ActiveConfiguration = "Debug";
project.ActivePlatform = "AnyCPU";
project.SetProperty("PlatformTarget", "x64");
project.SetProperty("TargetFrameworkVersion", "v4.5");
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console.exe", app.FileName);
@ -90,10 +120,10 @@ namespace UnitTesting.Tests.Frameworks @@ -90,10 +120,10 @@ namespace UnitTesting.Tests.Frameworks
project.ActiveConfiguration = "Debug";
project.ActivePlatform = "AnyCPU";
project.SetProperty("PlatformTarget", "x86");
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-x86.exe", app.FileName);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-x86.exe", app.FileName);
}
[Test]
@ -104,7 +134,7 @@ namespace UnitTesting.Tests.Frameworks @@ -104,7 +134,7 @@ namespace UnitTesting.Tests.Frameworks
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
Assert.AreEqual(project.GetType().BaseType, typeof(AbstractProject), "MissingProject should be derived from AbstractProject.");
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console.exe", app.FileName);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console.exe", app.FileName);
}
}
}

Loading…
Cancel
Save