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

Refactoring and moving RuntimeFramework class #1170

Merged
merged 12 commits into from
Mar 7, 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
8 changes: 4 additions & 4 deletions cake/constants.cake
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ var ENGINE_TESTS_PROJECT = SOURCE_DIR + "NUnitEngine/nunit.engine.tests/nunit.en
var ENGINE_CORE_TESTS_PROJECT = SOURCE_DIR + "NUnitEngine/nunit.engine.core.tests/nunit.engine.core.tests.csproj";
var CONSOLE_PROJECT = SOURCE_DIR + "NUnitConsole/nunit-console/nunit-console.csproj";
var CONSOLE_TESTS_PROJECT = SOURCE_DIR + "NUnitConsole/nunit-console.tests/nunit-console.tests.csproj";
var MOCK_ASSEMBLY_PROJECT = SOURCE_DIR + "NUnitEngine/mock-assembly/mock-assembly.csproj";
var MOCK_ASSEMBLY_X86_PROJECT = SOURCE_DIR + "NUnitEngine/mock-assembly-x86/mock-assembly-x86.csproj";
var MOCK_ASSEMBLY_NUNIT4_PROJECT = SOURCE_DIR + "NUnitEngine/mock-assembly-nunit4/mock-assembly-nunit4.csproj";
var NOTEST_PROJECT = SOURCE_DIR + "NUnitEngine/notest-assembly/notest-assembly.csproj";
var MOCK_ASSEMBLY_PROJECT = SOURCE_DIR + "TestData/mock-assembly/mock-assembly.csproj";
var MOCK_ASSEMBLY_X86_PROJECT = SOURCE_DIR + "TestData/mock-assembly-x86/mock-assembly-x86.csproj";
var MOCK_ASSEMBLY_NUNIT4_PROJECT = SOURCE_DIR + "TestData/mock-assembly-nunit4/mock-assembly-nunit4.csproj";
var NOTEST_PROJECT = SOURCE_DIR + "TestData/notest-assembly/notest-assembly.csproj";
// Console Runner
var NET20_CONSOLE = BIN_DIR + "net20/nunit-console.exe";
var NET60_CONSOLE = BIN_DIR + "net6.0/nunit-console.dll";
Expand Down
30 changes: 21 additions & 9 deletions src/NUnitEngine/nunit-agent/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,34 @@
using System.IO;
using System.Runtime.InteropServices;
using System.Security;
using Microsoft.Win32;
using NUnit.Common;
using NUnit.Engine;
using NUnit.Engine.Agents;
using NUnit.Engine.Internal;

#if NETFRAMEWORK
using RuntimeInformation = NUnit.Engine.Internal.Backports.RuntimeInformation;
#endif

namespace NUnit.Agent
{
public class NUnitTestAgent
{
static readonly string CURRENT_RUNTIME = RuntimeInformation.FrameworkDescription;
const string AGENT_RUNTIME =
#if NET6_0
".NET 6.0";
#elif NET5_0
".NET 5.0";
#elif NETCOREAPP3_1
".NET Core 3.1";
#elif NET40
".NET 4.0";
#elif NET20
".NET 2.0";
#endif

static Guid AgentId;
static string AgencyUrl;
static Process AgencyProcess;
Expand Down Expand Up @@ -63,21 +82,14 @@ public static void Main(string[] args)
InternalTrace.Initialize(Path.Combine(workDirectory, logName), traceLevel);
log = InternalTrace.GetLogger(typeof(NUnitTestAgent));

log.Info("Agent process {0} starting", pid);
log.Info($"Agent process {pid} starting");
log.Info($"Running {AGENT_RUNTIME} agent under {CURRENT_RUNTIME}");

if (debugArgPassed)
TryLaunchDebugger();

LocateAgencyProcess(agencyPid);

#if NETCOREAPP3_1
log.Info($"Running .NET Core 3.1 agent under {RuntimeInformation.FrameworkDescription}");
#elif NET40
log.Info($"Running .NET 4.0 agent under {RuntimeFramework.CurrentFramework.DisplayName}");
#elif NET20
log.Info($"Running .NET 2.0 agent under {RuntimeFramework.CurrentFramework.DisplayName}");
#endif

log.Info("Starting RemoteTestAgent");
Agent = new RemoteTestAgent(AgentId);
Agent.Transport =
Expand Down
6 changes: 6 additions & 0 deletions src/NUnitEngine/nunit.engine.api/IRuntimeFrameworkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ namespace NUnit.Engine
/// </summary>
public interface IRuntimeFrameworkService
{
/// <summary>
/// Gets a RuntimeFramework instance representing the runtime under
/// which the code is currently running.
/// </summary>
IRuntimeFramework CurrentFramework { get; }

/// <summary>
/// Returns true if the runtime framework represented by
/// the string passed as an argument is available.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,54 @@
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt

using System;
using System.Reflection;
using System.IO;
using NUnit.Engine.Extensibility;
using NUnit.Framework;

namespace NUnit.Engine.Tests.Extensibility
#if NETFRAMEWORK
using FrameworkName = NUnit.Engine.Compatibility.FrameworkName;
#else
using FrameworkName = System.Runtime.Versioning.FrameworkName;
#endif

namespace NUnit.Engine.Extensibility
{
// TODO: This should actually give us 3.5
[TestFixture("../net35/mock-assembly.dll", FrameworkIdentifiers.NetFramework, "2.0")]
[TestFixture("../netcoreapp2.1/mock-assembly.dll", FrameworkIdentifiers.NetCoreApp, "2.1")]
[TestFixture("../netcoreapp3.1/mock-assembly.dll", FrameworkIdentifiers.NetCoreApp, "3.1")]
[TestFixture("../net5.0/mock-assembly.dll", FrameworkIdentifiers.NetCoreApp, "5.0")]
[TestFixture("../net6.0/mock-assembly.dll", FrameworkIdentifiers.NetCoreApp, "6.0")]
public class ExtensionAssemblyTests
{
private static readonly Assembly THIS_ASSEMBLY = Assembly.GetExecutingAssembly();
private static readonly string THIS_ASSEMBLY_PATH = THIS_ASSEMBLY.Location;
private static readonly string THIS_ASSEMBLY_FULL_NAME = THIS_ASSEMBLY.GetName().FullName;
private static readonly string THIS_ASSEMBLY_NAME = THIS_ASSEMBLY.GetName().Name;
private static readonly Version THIS_ASSEMBLY_VERSION = THIS_ASSEMBLY.GetName().Version;

private string _assemblyPath;
private string _assemblyFileName;
private FrameworkName _expectedTargetRuntime;
private ExtensionAssembly _ea;

[OneTimeSetUp]
public void CreateExtensionAssemblies()
{
_ea = new ExtensionAssembly(THIS_ASSEMBLY_PATH, false);
}

[Test]
public void AssemblyDefinition()
public ExtensionAssemblyTests(string assemblyPath, string expectedRuntime, string expectedVersion)
{
Assert.That(_ea.Assembly.FullName, Is.EqualTo(THIS_ASSEMBLY_FULL_NAME));
_assemblyPath = assemblyPath;
_assemblyFileName = Path.GetFileNameWithoutExtension(assemblyPath);
_expectedTargetRuntime = new FrameworkName(expectedRuntime, new Version(expectedVersion));
}

[Test]
public void MainModule()
[OneTimeSetUp]
public void CreateExtensionAssemblies()
{
Assert.That(_ea.MainModule.Assembly.FullName, Is.EqualTo(THIS_ASSEMBLY_FULL_NAME));
_ea = new ExtensionAssembly(_assemblyPath, false);
}

[Test]
public void AssemblyName()
{
Assert.That(_ea.AssemblyName, Is.EqualTo(THIS_ASSEMBLY_NAME));
Assert.That(_ea.AssemblyName, Is.EqualTo(_assemblyFileName));
}

[Test]
public void AssemblyVersion()
{
Assert.That(_ea.AssemblyVersion, Is.EqualTo(THIS_ASSEMBLY_VERSION));
}

#if NETFRAMEWORK
[Test]
public void TargetFramework()
{
Assert.Multiple(() =>
{
Assert.That(_ea.TargetFramework, Has.Property(nameof(RuntimeFramework.Runtime)).EqualTo(RuntimeType.Any));
Assert.That(_ea.TargetFramework, Has.Property(nameof(RuntimeFramework.FrameworkVersion)).EqualTo(new Version(2, 0)));
});
Assert.That(_ea.TargetRuntime, Is.EqualTo(_expectedTargetRuntime));
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#if NETFRAMEWORK
using System;
using NSubstitute;
using NUnit.Engine.Compatibility;
using NUnit.Engine.Extensibility;
using NUnit.Framework;

Expand Down Expand Up @@ -112,7 +113,7 @@ private static IExtensionAssembly MockExtension(string assemblyName = "Extension
sub.AssemblyName.Returns(assemblyName);
sub.AssemblyVersion.Returns(assemblyVersion ?? new Version(1, 0));
targetFramework = targetFramework ?? new Version(2, 0);
sub.TargetFramework.Returns(new RuntimeFramework(RuntimeType.Any, targetFramework));
sub.TargetRuntime.Returns(new FrameworkName(FrameworkIdentifiers.NetFramework, targetFramework));
sub.FromWildCard.Returns(fromWildcard);
return sub;
}
Expand Down
Loading