From 63d671bb7e3889985fa529e2f56fb69469f79780 Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Sun, 20 Oct 2024 11:31:38 -0700 Subject: [PATCH] Eliminate .NET Standard 2.0 build of nunit.engine --- NUnitConsole.sln | 8 +++ build.cake | 13 +++-- nuget/engine/nunit.engine.nuspec | 9 ---- package-tests.cake | 4 +- .../nunit3-console.tests.csproj | 2 +- .../Services/ExtensionManagerTests.cs | 52 ++++++++++++++++--- .../nunit.engine.tests.csproj | 14 +---- .../nunit.engine/nunit.engine.csproj | 2 +- .../FakeExtensions/FakeExtensions.cs} | 0 .../FakeExtensions/FakeExtensions.csproj | 15 ++++++ src/TestData/mock-assembly-v2/MockAssembly.cs | 2 +- zip/nunit.bundle.agent.addins | 5 ++ 12 files changed, 89 insertions(+), 37 deletions(-) rename src/{NUnitEngine/nunit.engine.core.tests/DummyExtensions.cs => TestData/FakeExtensions/FakeExtensions.cs} (100%) create mode 100644 src/TestData/FakeExtensions/FakeExtensions.csproj create mode 100644 zip/nunit.bundle.agent.addins diff --git a/NUnitConsole.sln b/NUnitConsole.sln index ca1fc006d..9b322fbb5 100644 --- a/NUnitConsole.sln +++ b/NUnitConsole.sln @@ -100,6 +100,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "zip", "zip", "{20005864-BE82-412D-99BF-288E2D8370E9}" ProjectSection(SolutionItems) = preProject zip\nunit.bundle.addins = zip\nunit.bundle.addins + zip\nunit.bundle.agent.addins = zip\nunit.bundle.agent.addins EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.engine.core.tests", "src\NUnitEngine\nunit.engine.core.tests\nunit.engine.core.tests.csproj", "{CACC0520-B452-4310-A33C-DC944129ACDD}" @@ -153,6 +154,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net8.0", "net8.0", "{303CF8 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mock-assembly-v2", "src\TestData\mock-assembly-v2\mock-assembly-v2.csproj", "{AD40CA55-35CC-41CA-85F5-8FDA4ECAFF78}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FakeExtensions", "src\TestData\FakeExtensions\FakeExtensions.csproj", "{D6C217E0-BFB7-4C80-8D50-C969F46EBC59}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -235,6 +238,10 @@ Global {AD40CA55-35CC-41CA-85F5-8FDA4ECAFF78}.Debug|Any CPU.Build.0 = Debug|Any CPU {AD40CA55-35CC-41CA-85F5-8FDA4ECAFF78}.Release|Any CPU.ActiveCfg = Release|Any CPU {AD40CA55-35CC-41CA-85F5-8FDA4ECAFF78}.Release|Any CPU.Build.0 = Release|Any CPU + {D6C217E0-BFB7-4C80-8D50-C969F46EBC59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D6C217E0-BFB7-4C80-8D50-C969F46EBC59}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D6C217E0-BFB7-4C80-8D50-C969F46EBC59}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D6C217E0-BFB7-4C80-8D50-C969F46EBC59}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -271,6 +278,7 @@ Global {E43A3E4B-B050-471B-B43C-0DF60FD44376} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} {303CF83E-2A87-4882-8CAC-3EB59AAD81FC} = {F3E87D0F-6F06-4C0B-AE06-42C0834C3C6E} {AD40CA55-35CC-41CA-85F5-8FDA4ECAFF78} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} + {D6C217E0-BFB7-4C80-8D50-C969F46EBC59} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D8E4FC26-5422-4C51-8BBC-D1AC0A578711} diff --git a/build.cake b/build.cake index 288c9877e..98f78f8e8 100644 --- a/build.cake +++ b/build.cake @@ -119,13 +119,18 @@ BuildSettings.Packages.AddRange(new PackageDefinition[] { source: BuildSettings.ZipImageDirectory, checks: new PackageCheck[] { HasFiles("LICENSE.txt", "NOTICES.txt", "CHANGES.txt"), - HasDirectory("bin/net462").WithFiles("nunit3-console.exe", "nunit3-console.exe.config", "nunit3-console.pdb").AndFiles(ENGINE_FILES).AndFiles(ENGINE_PDB_FILES), - HasDirectory("bin/netstandard2.0").WithFiles(ENGINE_FILES).AndFiles(ENGINE_PDB_FILES), + HasDirectory("bin/net462").WithFiles("nunit3-console.exe", "nunit3-console.exe.config", + "nunit3-console.pdb").AndFiles(ENGINE_FILES).AndFiles(ENGINE_PDB_FILES), + HasDirectory("bin/net462/addins").WithFiles( + "nunit.core.dll", "nunit.core.interfaces.dll", "nunit.engine.api.dll", + "nunit.v2.driver.dll", "nunit-project-loader.dll", "nunit-v2-result-writer.dll", + "teamcity-event-listener.dll", "vs-project-loader.dll"), + HasDirectory("bin/netstandard2.0").WithFiles(ENGINE_CORE_FILES).AndFiles(ENGINE_CORE_PDB_FILES), HasDirectory("bin/netcoreapp3.1").WithFiles(ENGINE_CORE_FILES).AndFiles(ENGINE_CORE_PDB_FILES), HasDirectory("bin/agents/net462").WithFiles(AGENT_FILES).AndFiles(AGENT_PDB_FILES), HasDirectory("bin/agents/net6.0").WithFiles(AGENT_FILES_NETCORE).AndFiles(AGENT_PDB_FILES_NETCORE), HasDirectory("bin/agents/net7.0").WithFiles(AGENT_FILES_NETCORE).AndFiles(AGENT_PDB_FILES_NETCORE), - HasDirectory("bin/agents/net8.0").WithFiles(AGENT_FILES_NETCORE).AndFiles(AGENT_PDB_FILES_NETCORE) + HasDirectory("bin/agents/net8.0").WithFiles(AGENT_FILES_NETCORE).AndFiles(AGENT_PDB_FILES_NETCORE), }, testRunner: new ConsoleRunnerSelfTester(BuildSettings.ZipTestDirectory + $"NUnit.Console.{BuildSettings.PackageVersion}/bin/net462/nunit3-console.exe"), @@ -146,10 +151,8 @@ BuildSettings.Packages.AddRange(new PackageDefinition[] { checks: new PackageCheck[] { HasFiles("LICENSE.txt", "NOTICES.txt"), HasDirectory("lib/net462").WithFiles(ENGINE_FILES), - HasDirectory("lib/netstandard2.0").WithFiles(ENGINE_FILES), HasDirectory("lib/net8.0").WithFiles(ENGINE_FILES).AndFile("Microsoft.Extensions.DependencyModel.dll"), HasDirectory("contentFiles/any/lib/net462").WithFile("nunit.engine.nuget.addins"), - HasDirectory("contentFiles/any/lib/netstandard2.0").WithFile("nunit.engine.nuget.addins"), HasDirectory("contentFiles/any/lib/net8.0").WithFile("nunit.engine.nuget.addins"), HasDirectory("contentFiles/any/agents/net462").WithFiles(AGENT_FILES).AndFile("nunit.agent.addins") }, diff --git a/nuget/engine/nunit.engine.nuspec b/nuget/engine/nunit.engine.nuspec index 743232e34..e3eed7538 100644 --- a/nuget/engine/nunit.engine.nuspec +++ b/nuget/engine/nunit.engine.nuspec @@ -71,15 +71,6 @@ - - - - - - - - - diff --git a/package-tests.cake b/package-tests.cake index 6f889e268..7c893672e 100644 --- a/package-tests.cake +++ b/package-tests.cake @@ -264,7 +264,7 @@ StandardRunnerTests.Add(new PackageTest( StandardRunnerTests.Add(new PackageTest( 1, "V2FrameworkDriverTest", "Run mock-assembly-v2 using the V2 Driver in process", - "v2-tests/net462/mock-assembly-v2.dll --inprocess", + "v2-tests/net462/mock-assembly-v2.dll", new ExpectedResult("Failed") { Total = 28, @@ -280,7 +280,7 @@ StandardRunnerTests.Add(new PackageTest( StandardRunnerTests.Add(new PackageTest( 1, "V2FrameworkDriverTest", "Run mock-assembly-v2 using the V2 Driver out of process", - "v2-tests/net462/mock-assembly-v2.dll --trace:Debug", + "v2-tests/net462/mock-assembly-v2.dll --list-extensions", new ExpectedResult("Failed") { Total = 28, diff --git a/src/NUnitConsole/nunit3-console.tests/nunit3-console.tests.csproj b/src/NUnitConsole/nunit3-console.tests/nunit3-console.tests.csproj index ec2a90e9e..2ad1519ba 100644 --- a/src/NUnitConsole/nunit3-console.tests/nunit3-console.tests.csproj +++ b/src/NUnitConsole/nunit3-console.tests/nunit3-console.tests.csproj @@ -2,7 +2,7 @@ NUnit.ConsoleRunner.Tests - net462;net6.0;net8.0 + net462;net8.0 Exe NUnit.Engine.Tests.Program 1685 diff --git a/src/NUnitEngine/nunit.engine.core.tests/Services/ExtensionManagerTests.cs b/src/NUnitEngine/nunit.engine.core.tests/Services/ExtensionManagerTests.cs index f1568f764..eca71b122 100644 --- a/src/NUnitEngine/nunit.engine.core.tests/Services/ExtensionManagerTests.cs +++ b/src/NUnitEngine/nunit.engine.core.tests/Services/ExtensionManagerTests.cs @@ -10,6 +10,7 @@ using NUnit.Engine.Internal; using NSubstitute; using NUnit.Engine.Internal.FileSystemAccess; +using System.Diagnostics; namespace NUnit.Engine.Services.Tests { @@ -57,9 +58,12 @@ public void CreateExtensionManager() // Find actual extension points. _extensionManager.FindExtensionPoints(typeof(CoreEngine).Assembly); _extensionManager.FindExtensionPoints(typeof(ITestEngine).Assembly); - - // Find dummy extensions in this test assembly. - _extensionManager.FindExtensionsInAssembly(new ExtensionAssembly(GetType().Assembly.Location, false)); + // Find extensions. +#if NETCOREAPP + _extensionManager.FindExtensionsInAssembly(FakeExtensions("netstandard2.0")); +#else + _extensionManager.FindExtensionsInAssembly(FakeExtensions("net462")); +#endif } [Test] @@ -161,21 +165,39 @@ public void SkipsGracefullyLoadingOtherFrameworkExtensionAssembly() Assert.That(() => service.FindExtensionsInAssembly(extensionAssembly), Throws.Nothing); } - [TestCaseSource(nameof(ValidCombos))] +#if NETCOREAPP + [TestCase("netstandard2.0", ExpectedResult = true)] + [TestCase("net462", ExpectedResult = false)] + //[TestCase("net20", ExpectedResult = false)] +#elif NET40_OR_GREATER + [TestCase("netstandard2.0", ExpectedResult = false)] + [TestCase("net462", ExpectedResult = true)] + //[TestCase("net20", ExpectedResult = true)] +#else + [TestCase("netstandard2.0", ExpectedResult = false)] + [TestCase("net462", ExpectedResult = false)] + //[TestCase("net20", ExpectedResult = true)] +#endif + public bool LoadTargetFramework(string tfm) + { + return _extensionManager.CanLoadTargetFramework(THIS_ASSEMBLY, FakeExtensions(tfm)); + } + + //[TestCaseSource(nameof(ValidCombos))] public void ValidTargetFrameworkCombinations(FrameworkCombo combo) { Assert.That(() => _extensionManager.CanLoadTargetFramework(combo.RunnerAssembly, combo.ExtensionAssembly), Is.True); } - [TestCaseSource(nameof(InvalidTargetFrameworkCombos))] + //[TestCaseSource(nameof(InvalidTargetFrameworkCombos))] public void InvalidTargetFrameworkCombinations(FrameworkCombo combo) { Assert.That(() => _extensionManager.CanLoadTargetFramework(combo.RunnerAssembly, combo.ExtensionAssembly), Is.False); } - [TestCaseSource(nameof(InvalidRunnerCombos))] + //[TestCaseSource(nameof(InvalidRunnerCombos))] public void InvalidRunnerTargetFrameworkCombinations(FrameworkCombo combo) { var ex = Assert.Catch(() => _extensionManager.CanLoadTargetFramework(combo.RunnerAssembly, combo.ExtensionAssembly)); @@ -275,5 +297,23 @@ private static string GetSiblingDirectory(string dir) var file = new FileInfo(typeof(ExtensionManagerTests).Assembly.Location); return Path.Combine(file.Directory.Parent.FullName, dir); } + + private static readonly Assembly THIS_ASSEMBLY = typeof(ExtensionManagerTests).Assembly; + private static readonly string THIS_ASSEMBLY_DIRECTORY = Path.GetDirectoryName(THIS_ASSEMBLY.Location); + private const string FAKE_EXTENSIONS_FILENAME = "FakeExtensions.dll"; + private static readonly string FAKE_EXTENSIONS_PARENT_DIRECTORY = + Path.Combine(new DirectoryInfo(THIS_ASSEMBLY_DIRECTORY).Parent.FullName, "fakes"); + + /// + /// Returns an ExtensionAssembly referring to a particular build of the fake test extensions + /// assembly based on the argument provided. + /// + /// A test framework moniker. Must be one for which the fake extensions are built. + /// + private static ExtensionAssembly FakeExtensions(string tfm) + { + return new ExtensionAssembly( + Path.Combine(FAKE_EXTENSIONS_PARENT_DIRECTORY, Path.Combine(tfm, FAKE_EXTENSIONS_FILENAME)), false); + } } } diff --git a/src/NUnitEngine/nunit.engine.tests/nunit.engine.tests.csproj b/src/NUnitEngine/nunit.engine.tests/nunit.engine.tests.csproj index 35822ea83..08b96fc58 100644 --- a/src/NUnitEngine/nunit.engine.tests/nunit.engine.tests.csproj +++ b/src/NUnitEngine/nunit.engine.tests/nunit.engine.tests.csproj @@ -2,7 +2,7 @@ NUnit.Engine.Tests - net462;netcoreapp3.1;net8.0 + net462;net8.0 Exe true ..\..\nunit.snk @@ -17,13 +17,7 @@ Tests of nunit.engine assembly - - - - - - - + @@ -35,10 +29,6 @@ - - - - diff --git a/src/NUnitEngine/nunit.engine/nunit.engine.csproj b/src/NUnitEngine/nunit.engine/nunit.engine.csproj index 1db72dfa5..c8a16bcdf 100644 --- a/src/NUnitEngine/nunit.engine/nunit.engine.csproj +++ b/src/NUnitEngine/nunit.engine/nunit.engine.csproj @@ -2,7 +2,7 @@ NUnit.Engine - net462;netstandard2.0;net8.0 + net462;net8.0 true ..\..\nunit.snk portable diff --git a/src/NUnitEngine/nunit.engine.core.tests/DummyExtensions.cs b/src/TestData/FakeExtensions/FakeExtensions.cs similarity index 100% rename from src/NUnitEngine/nunit.engine.core.tests/DummyExtensions.cs rename to src/TestData/FakeExtensions/FakeExtensions.cs diff --git a/src/TestData/FakeExtensions/FakeExtensions.csproj b/src/TestData/FakeExtensions/FakeExtensions.csproj new file mode 100644 index 000000000..066d31608 --- /dev/null +++ b/src/TestData/FakeExtensions/FakeExtensions.csproj @@ -0,0 +1,15 @@ + + + + net462;netstandard2.0 + TestCentric.Extensibility + true + ..\..\nunit.snk + ..\..\..\bin\$(Configuration)\fakes + + + + + + + diff --git a/src/TestData/mock-assembly-v2/MockAssembly.cs b/src/TestData/mock-assembly-v2/MockAssembly.cs index b9439abce..bf764e8d3 100644 --- a/src/TestData/mock-assembly-v2/MockAssembly.cs +++ b/src/TestData/mock-assembly-v2/MockAssembly.cs @@ -3,7 +3,7 @@ using System; using NUnit.Framework; -namespace TestCentric.Tests +namespace NUnit.Tests { namespace Assemblies { diff --git a/zip/nunit.bundle.agent.addins b/zip/nunit.bundle.agent.addins new file mode 100644 index 000000000..9977bd6e9 --- /dev/null +++ b/zip/nunit.bundle.agent.addins @@ -0,0 +1,5 @@ +../../addins/nunit.v2.driver.dll +../../addins/nunit-v2-result-writer.dll +../../addins/nunit-project-loader.dll +../../addins/vs-project-loader.dll +../../addins/teamcity-event-listener.dll