Skip to content

Commit

Permalink
Merge pull request #1256 from nunit/issue-1130
Browse files Browse the repository at this point in the history
Run .NET 4.6.1 and higher tests using Mono on Linux
  • Loading branch information
CharliePoole committed Oct 31, 2022
2 parents 28f41ff + a53848a commit fbb5e67
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ jobs:
version: 2.1.x

- bash: |
./build.sh --target=Build --configuration=Release
displayName: Build
./build.sh --target=Test --configuration=Release
displayName: Build and Test
# Workaround for https://github.com/nunit/nunit/issues/3012#issuecomment-441517922
- task: PublishTestResults@2
Expand Down
4 changes: 2 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Task("TestNetStandard20Engine")
.OnError(exception => { UnreportedErrors.Add(exception.Message); })
.Does(() =>
{
RunDotnetNUnitLiteTests(ENGINE_TESTS_PROJECT, "netcoreapp2.1", "--labels:Before");
RunDotnetNUnitLiteTests(ENGINE_TESTS_PROJECT, "netcoreapp2.1");
});

//////////////////////////////////////////////////////////////////////
Expand All @@ -207,7 +207,7 @@ Task("TestNetCore31Engine")
.OnError(exception => { UnreportedErrors.Add(exception.Message); })
.Does(() =>
{
RunDotnetNUnitLiteTests(ENGINE_TESTS_PROJECT, "netcoreapp3.1", "--labels:Before");
RunDotnetNUnitLiteTests(ENGINE_TESTS_PROJECT, "netcoreapp3.1");
});

//////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions cake/utilities.cake
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void RunDotnetNUnitLiteTests(string projectPath, string targetRuntime, string ad
UnreportedErrors.Add($"{testAssembly}({targetRuntime}) returned rc = {rc}");
}

void RunNetFxConsole(string projectPath, string targetRuntime)
void RunNetFxConsole(string projectPath, string targetRuntime, string additionalArgs="")
{
var testAssembly = System.IO.Path.GetFileNameWithoutExtension(projectPath) + ".dll";
var workingDir = GetProjectBinDir(projectPath, targetRuntime);
Expand All @@ -257,7 +257,7 @@ void RunNetFxConsole(string projectPath, string targetRuntime)
NETFX_CONSOLE,
new ProcessSettings()
{
Arguments = $"\"{assemblyPath}\" --result:{resultPath}",
Arguments = $"\"{assemblyPath}\" --result:{resultPath} {additionalArgs}",
WorkingDirectory = workingDir
});

Expand Down
6 changes: 4 additions & 2 deletions src/NUnitConsole/nunit3-console.tests/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ public void CanRecognizeBooleanOptions(string propertyName, string pattern)
#if NETFRAMEWORK
[TestCase("ProcessModel", "process", new string[] { "InProcess", "Separate", "Multiple" }, new string[] { "JUNK" })]
[TestCase("DomainUsage", "domain", new string[] { "None", "Single", "Multiple" }, new string[] { "JUNK" })]
[TestCase("Framework", "framework", new string[] { "net-4.0" }, new string[0])]
// We can't predict which runtimes are available on the test machine, so we don't
// test for any good or bad values. TODO: Create a fake list of availble runtimes.
[TestCase("Framework", "framework", new string[0], new string[0])]
[TestCase("ConfigurationFile", "configfile", new string[] { "mytest.config" }, new string[0] )]
[TestCase("PrincipalPolicy", "set-principal-policy", new string[] { "UnauthenticatedPrincipal", "NoPrincipal", "WindowsPrincipal" }, new string[] { "JUNK" })]
#endif
Expand All @@ -215,7 +217,7 @@ public void CanRecognizeStringOptions(string propertyName, string pattern, strin
{
string optionPlusValue = string.Format("--{0}:{1}", option, value);
ConsoleOptions options = ConsoleMocks.Options(optionPlusValue);
Assert.That(options.Validate(), Is.True, "Should be valid: " + optionPlusValue);
Assert.That(options.Validate(), Is.True, $"The option {optionPlusValue} should be valid.");
Assert.That((string)property.GetValue(options, null), Is.EqualTo(value), "Didn't recognize " + optionPlusValue);
}

Expand Down
2 changes: 1 addition & 1 deletion src/NUnitConsole/nunit3-console/ConsoleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ private void ValidateFrameworkOption()
ErrorMessages.Add("Invalid or unknown framework requested: " + Framework);

foreach (var framework in RuntimeFramework.AvailableFrameworks)
if (framework.ToString() == Framework)
if (framework.Id == Framework)
return;

ErrorMessages.Add("Unavailable framework requested: " + Framework);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#if NETFRAMEWORK
using System;
using System.Collections.Generic;
using NSubstitute;
using NUnit.Framework;

namespace NUnit.Engine.Tests
Expand Down Expand Up @@ -163,6 +164,10 @@ public bool CanLoad(RuntimeFramework f1, RuntimeFramework f2)
new RuntimeFramework(RuntimeType.Mono, new Version(4,0)),
new RuntimeFramework(RuntimeType.Net, new Version(4,0)))
.Returns(true),
new TestCaseData(
new RuntimeFramework(RuntimeType.Mono, new Version(4,0)),
new RuntimeFramework(RuntimeType.Net, new Version(4,6,2)))
.Returns(true),
new TestCaseData(
new RuntimeFramework(RuntimeType.Net, new Version(2,0)),
new RuntimeFramework(RuntimeType.Net, new Version(1,1)))
Expand Down
10 changes: 7 additions & 3 deletions src/NUnitEngine/nunit.engine.core/RuntimeFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,13 @@ public bool Supports(RuntimeFramework target)
if (FrameworkVersion == DefaultVersion || target.FrameworkVersion == DefaultVersion)
return true;

return VersionsMatch(this.ClrVersion, target.ClrVersion)
&& this.FrameworkVersion.Major >= target.FrameworkVersion.Major
&& this.FrameworkVersion.Minor >= target.FrameworkVersion.Minor;
if (!VersionsMatch(this.ClrVersion, target.ClrVersion))
return false;

return this.Runtime == RuntimeType.Mono
? this.FrameworkVersion.Major >= target.FrameworkVersion.Major
: this.FrameworkVersion.Major >= target.FrameworkVersion.Major &&
this.FrameworkVersion.Minor >= target.FrameworkVersion.Minor;
}

private bool Supports(RuntimeType targetRuntime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ public bool IsAvailable(string name)
if (!RuntimeFramework.TryParse(name, out RuntimeFramework requestedFramework))
throw new NUnitEngineException("Invalid or unknown framework requested: " + name);

foreach (var framework in RuntimeFramework.AvailableFrameworks)
if (FrameworksMatch(requestedFramework, framework))
return true;

return false;
return requestedFramework.IsAvailable;
}

private static readonly Version AnyVersion = new Version(0, 0);
Expand Down

0 comments on commit fbb5e67

Please sign in to comment.