Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed ClrVersion from RuntimeFramework #1179

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/NUnitEngine/nunit.engine.api/IRuntimeFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public interface IRuntimeFramework
/// </summary>
Version FrameworkVersion { get; }

/// <summary>
/// Gets the Version of the CLR for this framework
/// </summary>
Version ClrVersion { get; }

/// <summary>
/// Gets a string representing the particular profile installed,
/// or null if there is no profile. Currently. the only defined
Expand Down
57 changes: 28 additions & 29 deletions src/NUnitEngine/nunit.engine.tests/RuntimeFrameworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ public void CanCreateUsingFrameworkVersion(FrameworkData data)
RuntimeFramework framework = new RuntimeFramework(data.runtime, data.frameworkVersion);
Assert.That(framework.Runtime, Is.EqualTo(data.runtime));
Assert.That(framework.FrameworkVersion, Is.EqualTo(data.frameworkVersion));
Assert.That(framework.ClrVersion, Is.EqualTo(data.clrVersion));
}

[TestCaseSource(nameof(frameworkData))]
public void CanParseRuntimeFramework(FrameworkData data)
{
RuntimeFramework framework = RuntimeFramework.Parse(data.representation);
Assert.That(framework.Runtime, Is.EqualTo(data.runtime));
Assert.That(framework.ClrVersion, Is.EqualTo(data.clrVersion));
}

[TestCaseSource(nameof(frameworkData))]
Expand Down Expand Up @@ -111,16 +109,14 @@ public struct FrameworkData
{
public Runtime runtime;
public Version frameworkVersion;
public Version clrVersion;
public string representation;
public string displayName;

public FrameworkData(Runtime runtime, Version frameworkVersion, Version clrVersion,
string representation, string displayName)
public FrameworkData(Runtime runtime, Version frameworkVersion, string representation,
string displayName)
{
this.runtime = runtime;
this.frameworkVersion = frameworkVersion;
this.clrVersion = clrVersion;
this.representation = representation;
this.displayName = displayName;
}
Expand All @@ -131,30 +127,33 @@ public override string ToString()
}
}

#pragma warning disable 414
static FrameworkData[] frameworkData = new FrameworkData[] {
new FrameworkData(Runtime.Net, new Version(1,0), new Version(1,0,3705), "net-1.0", ".NET 1.0"),
new FrameworkData(Runtime.Net, new Version(1,1), new Version(1,1,4322), "net-1.1", ".NET 1.1"),
new FrameworkData(Runtime.Net, new Version(2,0), new Version(2,0,50727), "net-2.0", ".NET 2.0"),
new FrameworkData(Runtime.Net, new Version(3,0), new Version(2,0,50727), "net-3.0", ".NET 3.0"),
new FrameworkData(Runtime.Net, new Version(3,5), new Version(2,0,50727), "net-3.5", ".NET 3.5"),
new FrameworkData(Runtime.Net, new Version(4,0), new Version(4,0,30319), "net-4.0", ".NET 4.0"),
new FrameworkData(Runtime.Net, new Version(4,5), new Version(4,0,30319), "net-4.5", ".NET 4.5"),
new FrameworkData(Runtime.Net, new Version(4,5,1), new Version(4,0,30319), "net-4.5.1", ".NET 4.5.1"),
new FrameworkData(Runtime.Net, new Version(4,5,2), new Version(4,0,30319), "net-4.5.2", ".NET 4.5.2"),
new FrameworkData(Runtime.Net, new Version(4,6), new Version(4,0,30319), "net-4.6", ".NET 4.6"),
new FrameworkData(Runtime.Net, new Version(4,6,1), new Version(4,0,30319), "net-4.6.1", ".NET 4.6.1"),
new FrameworkData(Runtime.Net, new Version(4,6,2), new Version(4,0,30319), "net-4.6.2", ".NET 4.6.2"),
new FrameworkData(Runtime.Net, new Version(4,7), new Version(4,0,30319), "net-4.7", ".NET 4.7"),
new FrameworkData(Runtime.Net, new Version(4,7,1), new Version(4,0,30319), "net-4.7.1", ".NET 4.7.1"),
new FrameworkData(Runtime.Net, new Version(4,7,2), new Version(4,0,30319), "net-4.7.2", ".NET 4.7.2"),
new FrameworkData(Runtime.Net, new Version(4,8), new Version(4,0,30319), "net-4.8", ".NET 4.8"),
new FrameworkData(Runtime.Mono, new Version(1,0), new Version(1,1,4322), "mono-1.0", "Mono 1.0"),
new FrameworkData(Runtime.Mono, new Version(2,0), new Version(2,0,50727), "mono-2.0", "Mono 2.0"),
new FrameworkData(Runtime.Mono, new Version(3,5), new Version(2,0,50727), "mono-3.5", "Mono 3.5"),
new FrameworkData(Runtime.Mono, new Version(4,0), new Version(4,0,30319), "mono-4.0", "Mono 4.0"),
static readonly FrameworkData[] frameworkData = new FrameworkData[] {
new FrameworkData(Runtime.Net, new Version(1,0), "net-1.0", ".NET 1.0"),
new FrameworkData(Runtime.Net, new Version(1,1), "net-1.1", ".NET 1.1"),
new FrameworkData(Runtime.Net, new Version(2,0), "net-2.0", ".NET 2.0"),
new FrameworkData(Runtime.Net, new Version(3,0), "net-3.0", ".NET 3.0"),
new FrameworkData(Runtime.Net, new Version(3,5), "net-3.5", ".NET 3.5"),
new FrameworkData(Runtime.Net, new Version(4,0), "net-4.0", ".NET 4.0"),
new FrameworkData(Runtime.Net, new Version(4,5), "net-4.5", ".NET 4.5"),
new FrameworkData(Runtime.Net, new Version(4,5,1), "net-4.5.1", ".NET 4.5.1"),
new FrameworkData(Runtime.Net, new Version(4,5,2), "net-4.5.2", ".NET 4.5.2"),
new FrameworkData(Runtime.Net, new Version(4,6), "net-4.6", ".NET 4.6"),
new FrameworkData(Runtime.Net, new Version(4,6,1), "net-4.6.1", ".NET 4.6.1"),
new FrameworkData(Runtime.Net, new Version(4,6,2), "net-4.6.2", ".NET 4.6.2"),
new FrameworkData(Runtime.Net, new Version(4,7), "net-4.7", ".NET 4.7"),
new FrameworkData(Runtime.Net, new Version(4,7,1), "net-4.7.1", ".NET 4.7.1"),
new FrameworkData(Runtime.Net, new Version(4,7,2), "net-4.7.2", ".NET 4.7.2"),
new FrameworkData(Runtime.Net, new Version(4,8), "net-4.8", ".NET 4.8"),
new FrameworkData(Runtime.Mono, new Version(1,0), "mono-1.0", "Mono 1.0"),
new FrameworkData(Runtime.Mono, new Version(2,0), "mono-2.0", "Mono 2.0"),
new FrameworkData(Runtime.Mono, new Version(3,5), "mono-3.5", "Mono 3.5"),
new FrameworkData(Runtime.Mono, new Version(4,0), "mono-4.0", "Mono 4.0"),
new FrameworkData(Runtime.NetCore, new Version(2,1), "netcore-2.1", ".NETCore 2.1"),
new FrameworkData(Runtime.NetCore, new Version(3,1), "netcore-3.1", ".NETCore 3.1"),
new FrameworkData(Runtime.NetCore, new Version(5,0), "netcore-5.0", ".NETCore 5.0"),
new FrameworkData(Runtime.NetCore, new Version(6,0), "netcore-6.0", ".NETCore 6.0"),
new FrameworkData(Runtime.NetCore, new Version(7,0), "netcore-7.0", ".NETCore 7.0"),
};
#pragma warning restore 414
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void DefaultValues(string framework)
var targetRuntime = RuntimeFramework.Parse(framework);
if (targetRuntime.Runtime == Runtime.Mono)
{
string monoOptions = "--runtime=v" + targetRuntime.ClrVersion.ToString(3);
string monoOptions = "--runtime=v" + targetRuntime.FrameworkVersion.ToString(2);
monoOptions += " --debug";
Assert.That(startInfo.FileName, Is.EqualTo(RuntimeFrameworkService.MonoExePath));
Assert.That(startInfo.Arguments, Is.EqualTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ public void CanGetCurrentFramework()
var framework = _runtimeService.CurrentFramework as RuntimeFramework;

Assert.That(framework.Runtime, Is.EqualTo(_currentRuntime));
Assert.That(framework.ClrVersion, Is.EqualTo(Environment.Version));
}

[Test]
public void CurrentFrameworkHasBuildSpecified()
{
Assert.That(_runtimeService.CurrentFramework.ClrVersion.Build, Is.GreaterThan(0));
}

[Test]
Expand Down
71 changes: 16 additions & 55 deletions src/NUnitEngine/nunit.engine/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public static Runtime FromFrameworkIdentifier(string s)

public abstract bool Matches(Runtime targetRuntime);

public abstract Version GetClrVersionForFramework(Version frameworkVersion);
public virtual bool Supports(Version runtime, Version target)
{
// We assume that Major versions must match.
return runtime.Major == target.Major && runtime.Minor >= target.Minor;
}

#endregion

Expand All @@ -81,27 +85,12 @@ private class NetFrameworkRuntime : Runtime
public override string ToString() => "Net";
public override bool Matches(Runtime targetRuntime) => targetRuntime is NetFrameworkRuntime;

public override Version GetClrVersionForFramework(Version frameworkVersion)
public override bool Supports(Version runtime, Version target)
{
switch (frameworkVersion.Major)
{
case 1:
switch (frameworkVersion.Minor)
{
case 0:
return new Version(1, 0, 3705);
case 1:
return new Version(1, 1, 4322);
}
break;
case 2:
case 3:
return new Version(2, 0, 50727);
case 4:
return new Version(4, 0, 30319);
}

throw new ArgumentException($"Unknown version for .NET Framework: {frameworkVersion}", "version");
// Runtime 3 supports runtime 2.
return base.Supports(runtime, target) ||
(runtime.Major == 3 && (target.Major == 2 || target.Major == 3) &&
runtime.Minor >= target.Minor);
}
}

Expand All @@ -110,22 +99,6 @@ private class MonoRuntime : NetFrameworkRuntime
public override string DisplayName => "Mono";

public override string ToString() => "Mono";

public override Version GetClrVersionForFramework(Version frameworkVersion)
{
switch (frameworkVersion.Major)
{
case 1:
return new Version(1, 1, 4322);
case 2:
case 3:
return new Version(2, 0, 50727);
case 4:
return new Version(4, 0, 30319);
}

throw new ArgumentException($"Unknown version for Mono runtime: {frameworkVersion}", "version");
}
}

private class NetCoreRuntime : Runtime
Expand All @@ -134,29 +107,17 @@ private class NetCoreRuntime : Runtime
public override string FrameworkIdentifier => FrameworkIdentifiers.NetCoreApp;

public override string ToString() => "NetCore";

public override bool Matches(Runtime targetRuntime) => targetRuntime is NetCoreRuntime;

public override Version GetClrVersionForFramework(Version frameworkVersion)
public override bool Supports(Version runtime, Version target)
{
switch(frameworkVersion.Major)
{
case 1:
case 2:
return new Version(4, 0, 30319);
case 3:
return new Version(3, 1, 10);
case 5:
return new Version(5, 0, 1);
case 6:
return new Version(6, 0, 0);
case 7:
return new Version(7, 0, 0);
}

throw new ArgumentException($"Unknown .NET Core version: {frameworkVersion}", "version");
// We assume that all later versions support all previous version.
return runtime.Major > target.Major ||
(runtime.Major == target.Major && runtime.Minor >= target.Minor);
}
}

#endregion
#endregion
}
}
24 changes: 2 additions & 22 deletions src/NUnitEngine/nunit.engine/RuntimeFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public RuntimeFramework(Runtime runtime, Version version, string profile)
Guard.ArgumentValid(IsValidFrameworkVersion(version), $"{version} is not a valid framework version", nameof(version));

Runtime = runtime;
FrameworkVersion = ClrVersion = version;
ClrVersion = runtime.GetClrVersionForFramework(version);
FrameworkVersion = version;

Profile = profile;

Expand Down Expand Up @@ -81,11 +80,6 @@ private bool IsValidFrameworkVersion(Version v)
/// </summary>
public Version FrameworkVersion { get; private set; }

/// <summary>
/// The CLR version for this runtime framework
/// </summary>
public Version ClrVersion { get; set; }

/// <summary>
/// The Profile for this framework, where relevant.
/// May be null and will have different sets of
Expand Down Expand Up @@ -158,10 +152,6 @@ public static RuntimeFramework FromFrameworkName(FrameworkName frameworkName)
/// Two RuntimeTypes match if they are equal, if either one
/// is RuntimeType.Any or if one is RuntimeType.Net and
/// the other is RuntimeType.Mono.
///
/// Two versions match if all specified version components
/// are equal. Negative (i.e. unspecified) version
/// components are ignored.
/// </summary>
/// <param name="target">The RuntimeFramework to be matched.</param>
/// <returns><c>true</c> on match, otherwise <c>false</c></returns>
Expand All @@ -170,9 +160,7 @@ public bool Supports(RuntimeFramework target)
if (!Runtime.Matches(target.Runtime))
return false;

return VersionsMatch(this.ClrVersion, target.ClrVersion)
&& this.FrameworkVersion.Major >= target.FrameworkVersion.Major
&& this.FrameworkVersion.Minor >= target.FrameworkVersion.Minor;
return Runtime.Supports(this.FrameworkVersion, target.FrameworkVersion);
}

public bool CanLoad(IRuntimeFramework requested)
Expand All @@ -190,14 +178,6 @@ private static string GetDefaultDisplayName(Runtime runtime, Version version, st
return displayName;
}

private static bool VersionsMatch(Version v1, Version v2)
{
return v1.Major == v2.Major &&
v1.Minor == v2.Minor &&
(v1.Build < 0 || v2.Build < 0 || v1.Build == v2.Build) &&
(v1.Revision < 0 || v2.Revision < 0 || v1.Revision == v2.Revision);
}

private static string GetMonoPrefixFromAssembly(Assembly assembly)
{
string prefix = assembly.Location;
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitEngine/nunit.engine/Services/AgentProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public AgentProcess(TestAgency agency, TestPackage package, Guid agentId)
if (TargetRuntime.Runtime == Runtime.Mono)
{
StartInfo.FileName = RuntimeFrameworkService.MonoExePath;
string monoOptions = "--runtime=v" + TargetRuntime.ClrVersion.ToString(3);
string monoOptions = "--runtime=v" + TargetRuntime.FrameworkVersion.ToString(2);
monoOptions += " --debug";
StartInfo.Arguments = string.Format("{0} \"{1}\" {2}", monoOptions, AgentExePath, AgentArgs);
}
Expand Down
30 changes: 3 additions & 27 deletions src/NUnitEngine/nunit.engine/Services/RuntimeFrameworkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Microsoft.Win32;
using Mono.Cecil;
using NUnit.Common;
using NUnit.Engine.Internal;
using NUnit.Engine.Services.RuntimeLocators;
#if NET20
using FrameworkName = NUnit.Engine.Compatibility.FrameworkName;
#endif

namespace NUnit.Engine.Services
{
using Microsoft.Win32;
using RuntimeLocators;

public class RuntimeFrameworkService : Service, IRuntimeFrameworkService, IAvailableRuntimes
{
static readonly Logger log = InternalTrace.GetLogger(typeof(RuntimeFrameworkService));
Expand Down Expand Up @@ -203,26 +202,6 @@ public override void StartService()
Status = ServiceStatus.Started;
}

/// <summary>
/// Returns the best available framework that matches a target framework.
/// If the target framework has a build number specified, then an exact
/// match is needed. Otherwise, the matching framework with the highest
/// build number is used.
/// </summary>
public RuntimeFramework GetBestAvailableFramework(RuntimeFramework target)
{
RuntimeFramework result = target;

foreach (RuntimeFramework framework in _availableRuntimes)
if (framework.Supports(target))
{
if (framework.ClrVersion.Build > result.ClrVersion.Build)
result = framework;
}

return result;
}

private void SetCurrentFramework()
{
Type monoRuntimeType = Type.GetType("Mono.Runtime", false);
Expand Down Expand Up @@ -275,10 +254,7 @@ private void SetCurrentFramework()
minor = 5;
}

var currentFramework = new RuntimeFramework(runtime, new Version(major, minor))
{
ClrVersion = Environment.Version
};
var currentFramework = new RuntimeFramework(runtime, new Version(major, minor));

if (isMono)
{
Expand Down