From e3d96c142df51fcb0d29d2c416f391b8dd93a28c Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Sun, 8 Sep 2024 17:02:02 -0700 Subject: [PATCH 1/2] Add more package tests and refactor --- NUnitConsole.sln | 71 +++-- build.cake | 229 +--------------- package-tests.cake | 250 ++++++++++++++++++ .../nunit3-console.tests.csproj | 2 +- .../nunit.engine.core.tests.csproj | 2 +- .../Internal/TestAssemblyResolver.cs | 2 +- .../nunit.engine.tests.csproj | 2 +- .../TestData.sln} | 4 +- .../aspnetcore-test/AspNetCoreTest.cs | 25 ++ .../aspnetcore-test/aspnetcore-test.csproj | 13 + .../mock-assembly-x86.csproj | 0 ...cessesCurrentTestContextDuringDiscovery.cs | 0 .../mock-assembly/MockAssembly.cs | 0 .../mock-assembly/mock-assembly.csproj | 0 .../mock-cpp-clr/AssemblyInfo.cpp | 0 .../mock-cpp-clr/TestClass.cpp | 0 .../mock-cpp-clr/TestClass.h | 0 .../mock-cpp-clr/mock-cpp-clr-x64.vcxproj | 0 .../mock-cpp-clr/mock-cpp-clr-x86.vcxproj | 0 .../Properties/AssemblyInfo.cs | 0 .../notest-assembly/notest-assembly.csproj | 0 .../windows-forms-test/WindowsFormsTest.cs | 25 ++ .../windows-forms-test.csproj | 13 + src/TestData/wpf-test/WpfTest.cs | 26 ++ src/TestData/wpf-test/WpfTest.csproj | 12 + 25 files changed, 416 insertions(+), 260 deletions(-) create mode 100644 package-tests.cake rename src/{NUnitEngine/mock-assembly/mock-assembly.sln => TestData/TestData.sln} (89%) create mode 100644 src/TestData/aspnetcore-test/AspNetCoreTest.cs create mode 100644 src/TestData/aspnetcore-test/aspnetcore-test.csproj rename src/{NUnitEngine => TestData}/mock-assembly-x86/mock-assembly-x86.csproj (100%) rename src/{NUnitEngine => TestData}/mock-assembly/AccessesCurrentTestContextDuringDiscovery.cs (100%) rename src/{NUnitEngine => TestData}/mock-assembly/MockAssembly.cs (100%) rename src/{NUnitEngine => TestData}/mock-assembly/mock-assembly.csproj (100%) rename src/{NUnitEngine => TestData}/mock-cpp-clr/AssemblyInfo.cpp (100%) rename src/{NUnitEngine => TestData}/mock-cpp-clr/TestClass.cpp (100%) rename src/{NUnitEngine => TestData}/mock-cpp-clr/TestClass.h (100%) rename src/{NUnitEngine => TestData}/mock-cpp-clr/mock-cpp-clr-x64.vcxproj (100%) rename src/{NUnitEngine => TestData}/mock-cpp-clr/mock-cpp-clr-x86.vcxproj (100%) rename src/{NUnitEngine => TestData}/notest-assembly/Properties/AssemblyInfo.cs (100%) rename src/{NUnitEngine => TestData}/notest-assembly/notest-assembly.csproj (100%) create mode 100644 src/TestData/windows-forms-test/WindowsFormsTest.cs create mode 100644 src/TestData/windows-forms-test/windows-forms-test.csproj create mode 100644 src/TestData/wpf-test/WpfTest.cs create mode 100644 src/TestData/wpf-test/WpfTest.csproj diff --git a/NUnitConsole.sln b/NUnitConsole.sln index fb214606c..6726812b1 100644 --- a/NUnitConsole.sln +++ b/NUnitConsole.sln @@ -21,20 +21,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution GitReleaseManager.yaml = GitReleaseManager.yaml GitVersion.yml = GitVersion.yml global.json = global.json - header-check.cake = header-check.cake LICENSE.txt = LICENSE.txt NetFXTests.nunit = NetFXTests.nunit NOTICES.txt = NOTICES.txt NuGet.config = NuGet.config nunit.ico = nunit.ico - package-checks.cake = package-checks.cake package-tests.cake = package-tests.cake - packages.cake = packages.cake PLATFORM_SUPPORT.md = PLATFORM_SUPPORT.md README.md = README.md - test-results.cake = test-results.cake VERSIONING.md = VERSIONING.md - cake\zip-package.cake = cake\zip-package.cake EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{A972031D-2F61-4183-AF75-99EE1A9F6B32}" @@ -47,7 +42,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.engine", "src\NUnitEn EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.engine.tests", "src\NUnitEngine\nunit.engine.tests\nunit.engine.tests.csproj", "{D694CB69-6CFB-4762-86C2-EB27B808B282}" ProjectSection(ProjectDependencies) = postProject - {B1D90742-39BD-429C-8E87-C5CD2991DF27} = {B1D90742-39BD-429C-8E87-C5CD2991DF27} {C2A8FC7A-FA64-46EA-AF6D-73D6B371DBF8} = {C2A8FC7A-FA64-46EA-AF6D-73D6B371DBF8} {0DE218CA-AFB8-423A-9CD2-E22DEAC55C46} = {0DE218CA-AFB8-423A-9CD2-E22DEAC55C46} EndProjectSection @@ -78,10 +72,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "runners", "runners", "{F3E8 nuget\runners\nunit.console.nuget.agent.addins = nuget\runners\nunit.console.nuget.agent.addins EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mock-assembly", "src\NUnitEngine\mock-assembly\mock-assembly.csproj", "{D2C80E4B-1117-4F02-AB02-E453BDA0C58E}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "notest-assembly", "src\NUnitEngine\notest-assembly\notest-assembly.csproj", "{B1D90742-39BD-429C-8E87-C5CD2991DF27}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "choco", "choco", "{4FDF7BFA-A337-41D3-898D-C6A98278E6AD}" ProjectSection(SolutionItems) = preProject choco\nunit-agent-x86.exe.ignore = choco\nunit-agent-x86.exe.ignore @@ -102,8 +92,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.engine.core", "src\NU EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit-agent-x86", "src\NUnitEngine\nunit-agent-x86\nunit-agent-x86.csproj", "{333D2FBC-CCA7-46AF-9453-C310671A67B0}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mock-assembly-x86", "src\NUnitEngine\mock-assembly-x86\mock-assembly-x86.csproj", "{9D3015EE-5B84-41B3-A1D3-1A439370C392}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "deprecated", "deprecated", "{068F6CA9-6108-4F45-8540-351AA5227259}" ProjectSection(SolutionItems) = preProject choco\deprecated\nunit-console-with-extensions.nuspec = choco\deprecated\nunit-console-with-extensions.nuspec @@ -135,6 +123,20 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config", "config", "{C5B712 .config\dotnet-tools.json = .config\dotnet-tools.json EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "aspnetcore-test", "src\TestData\aspnetcore-test\aspnetcore-test.csproj", "{DB42594C-9A68-488A-A289-47C0F9E29808}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "windows-forms-test", "src\TestData\windows-forms-test\windows-forms-test.csproj", "{0DF71C73-52A4-4423-8CEC-8A24D4F83FF3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfTest", "src\TestData\wpf-test\WpfTest.csproj", "{A96876EE-1A1F-4096-9B6A-5739E66B3364}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestData", "TestData", "{2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mock-assembly", "src\TestData\mock-assembly\mock-assembly.csproj", "{C3FF8716-052B-4D6C-81FF-E80F89AF9A80}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mock-assembly-x86", "src\TestData\mock-assembly-x86\mock-assembly-x86.csproj", "{8FE8378E-5A8B-4708-8F86-35BE0DE121F7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "notest-assembly", "src\TestData\notest-assembly\notest-assembly.csproj", "{81E63A90-3191-4E99-92FF-01F9B1D3E3C5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -165,14 +167,6 @@ Global {B310A760-8AE1-41CA-81F8-03B12E2FCE30}.Debug|Any CPU.Build.0 = Debug|Any CPU {B310A760-8AE1-41CA-81F8-03B12E2FCE30}.Release|Any CPU.ActiveCfg = Release|Any CPU {B310A760-8AE1-41CA-81F8-03B12E2FCE30}.Release|Any CPU.Build.0 = Release|Any CPU - {D2C80E4B-1117-4F02-AB02-E453BDA0C58E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D2C80E4B-1117-4F02-AB02-E453BDA0C58E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D2C80E4B-1117-4F02-AB02-E453BDA0C58E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D2C80E4B-1117-4F02-AB02-E453BDA0C58E}.Release|Any CPU.Build.0 = Release|Any CPU - {B1D90742-39BD-429C-8E87-C5CD2991DF27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B1D90742-39BD-429C-8E87-C5CD2991DF27}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B1D90742-39BD-429C-8E87-C5CD2991DF27}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B1D90742-39BD-429C-8E87-C5CD2991DF27}.Release|Any CPU.Build.0 = Release|Any CPU {A19C026B-1C0F-4AA3-AC49-7D8B4C7231CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A19C026B-1C0F-4AA3-AC49-7D8B4C7231CF}.Debug|Any CPU.Build.0 = Debug|Any CPU {A19C026B-1C0F-4AA3-AC49-7D8B4C7231CF}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -181,14 +175,34 @@ Global {333D2FBC-CCA7-46AF-9453-C310671A67B0}.Debug|Any CPU.Build.0 = Debug|Any CPU {333D2FBC-CCA7-46AF-9453-C310671A67B0}.Release|Any CPU.ActiveCfg = Release|Any CPU {333D2FBC-CCA7-46AF-9453-C310671A67B0}.Release|Any CPU.Build.0 = Release|Any CPU - {9D3015EE-5B84-41B3-A1D3-1A439370C392}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9D3015EE-5B84-41B3-A1D3-1A439370C392}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9D3015EE-5B84-41B3-A1D3-1A439370C392}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9D3015EE-5B84-41B3-A1D3-1A439370C392}.Release|Any CPU.Build.0 = Release|Any CPU {CACC0520-B452-4310-A33C-DC944129ACDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CACC0520-B452-4310-A33C-DC944129ACDD}.Debug|Any CPU.Build.0 = Debug|Any CPU {CACC0520-B452-4310-A33C-DC944129ACDD}.Release|Any CPU.ActiveCfg = Release|Any CPU {CACC0520-B452-4310-A33C-DC944129ACDD}.Release|Any CPU.Build.0 = Release|Any CPU + {DB42594C-9A68-488A-A289-47C0F9E29808}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DB42594C-9A68-488A-A289-47C0F9E29808}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DB42594C-9A68-488A-A289-47C0F9E29808}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DB42594C-9A68-488A-A289-47C0F9E29808}.Release|Any CPU.Build.0 = Release|Any CPU + {0DF71C73-52A4-4423-8CEC-8A24D4F83FF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0DF71C73-52A4-4423-8CEC-8A24D4F83FF3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0DF71C73-52A4-4423-8CEC-8A24D4F83FF3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0DF71C73-52A4-4423-8CEC-8A24D4F83FF3}.Release|Any CPU.Build.0 = Release|Any CPU + {A96876EE-1A1F-4096-9B6A-5739E66B3364}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A96876EE-1A1F-4096-9B6A-5739E66B3364}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A96876EE-1A1F-4096-9B6A-5739E66B3364}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A96876EE-1A1F-4096-9B6A-5739E66B3364}.Release|Any CPU.Build.0 = Release|Any CPU + {C3FF8716-052B-4D6C-81FF-E80F89AF9A80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C3FF8716-052B-4D6C-81FF-E80F89AF9A80}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C3FF8716-052B-4D6C-81FF-E80F89AF9A80}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C3FF8716-052B-4D6C-81FF-E80F89AF9A80}.Release|Any CPU.Build.0 = Release|Any CPU + {8FE8378E-5A8B-4708-8F86-35BE0DE121F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8FE8378E-5A8B-4708-8F86-35BE0DE121F7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8FE8378E-5A8B-4708-8F86-35BE0DE121F7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8FE8378E-5A8B-4708-8F86-35BE0DE121F7}.Release|Any CPU.Build.0 = Release|Any CPU + {81E63A90-3191-4E99-92FF-01F9B1D3E3C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {81E63A90-3191-4E99-92FF-01F9B1D3E3C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {81E63A90-3191-4E99-92FF-01F9B1D3E3C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {81E63A90-3191-4E99-92FF-01F9B1D3E3C5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -203,13 +217,10 @@ Global {B310A760-8AE1-41CA-81F8-03B12E2FCE30} = {576DB1E6-C5EC-4FEF-A826-EC19D8BEE572} {43A219A8-2995-4884-806F-FDB9CD25D403} = {A972031D-2F61-4183-AF75-99EE1A9F6B32} {F3E87D0F-6F06-4C0B-AE06-42C0834C3C6E} = {A972031D-2F61-4183-AF75-99EE1A9F6B32} - {D2C80E4B-1117-4F02-AB02-E453BDA0C58E} = {31B45C4C-206F-4F31-9CC6-33BF11DFEE39} - {B1D90742-39BD-429C-8E87-C5CD2991DF27} = {31B45C4C-206F-4F31-9CC6-33BF11DFEE39} {4FDF7BFA-A337-41D3-898D-C6A98278E6AD} = {49D441DF-39FD-4F4D-AECA-86CF8EFE23AF} {9A7C8370-ED1F-486F-A8F5-C5BF4221464E} = {A972031D-2F61-4183-AF75-99EE1A9F6B32} {A19C026B-1C0F-4AA3-AC49-7D8B4C7231CF} = {31B45C4C-206F-4F31-9CC6-33BF11DFEE39} {333D2FBC-CCA7-46AF-9453-C310671A67B0} = {31B45C4C-206F-4F31-9CC6-33BF11DFEE39} - {9D3015EE-5B84-41B3-A1D3-1A439370C392} = {31B45C4C-206F-4F31-9CC6-33BF11DFEE39} {068F6CA9-6108-4F45-8540-351AA5227259} = {4FDF7BFA-A337-41D3-898D-C6A98278E6AD} {20005864-BE82-412D-99BF-288E2D8370E9} = {49D441DF-39FD-4F4D-AECA-86CF8EFE23AF} {CACC0520-B452-4310-A33C-DC944129ACDD} = {31B45C4C-206F-4F31-9CC6-33BF11DFEE39} @@ -217,6 +228,12 @@ Global {08F8160E-E691-4F07-9F57-EA31B9736429} = {25DA12FE-6209-4524-9A37-8E51F815E198} {50371E48-BEC3-4D53-BD37-F3A6149CFD0D} = {25DA12FE-6209-4524-9A37-8E51F815E198} {C5B7120C-190B-4C38-95CB-83F12799598D} = {49D441DF-39FD-4F4D-AECA-86CF8EFE23AF} + {DB42594C-9A68-488A-A289-47C0F9E29808} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} + {0DF71C73-52A4-4423-8CEC-8A24D4F83FF3} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} + {A96876EE-1A1F-4096-9B6A-5739E66B3364} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} + {C3FF8716-052B-4D6C-81FF-E80F89AF9A80} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} + {8FE8378E-5A8B-4708-8F86-35BE0DE121F7} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} + {81E63A90-3191-4E99-92FF-01F9B1D3E3C5} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D8E4FC26-5422-4C51-8BBC-D1AC0A578711} diff --git a/build.cake b/build.cake index 10ba91ed8..87e9437fe 100644 --- a/build.cake +++ b/build.cake @@ -3,6 +3,8 @@ // Comment out above line and uncomment below for local tests of recipe changes //#load ../NUnit.Cake.Recipe/recipe/*.cake +#load package-tests.cake + // Initialize BuildSettings BuildSettings.Initialize( Context, @@ -12,233 +14,6 @@ BuildSettings.Initialize( exemptFiles: new[] { "Options.cs", "ProcessUtils.cs", "ProcessUtilsTests.cs" }, unitTests: "**/*.tests.exe"); -////////////////////////////////////////////////////////////////////// -// PACKAGE TEST LISTS -////////////////////////////////////////////////////////////////////// - -// Tests run for all runner packages except NETCORE runner -var StandardRunnerTests = new List - { - Net462Test, - Net462X86Test, - Net462PlusNet462Test, - Net462ExeTest, - NetCore31Test, - Net60Test, - Net70Test, - Net80Test, - Net60PlusNet80Test, - Net462PlusNet60Test, - NUnitProjectTest, - V2ResultWriterTest, - VSProjectLoaderTest_Project, - VSProjectLoaderTest_Solution - }; - -// Tests run for the NETCORE runner package -var NetCoreRunnerTests = new List - { - NetCore31Test, - Net60Test, - Net70Test, - Net80Test, - }; - -const string DOTNET_EXE_X86 = @"C:\Program Files (x86)\dotnet\dotnet.exe"; -// TODO: Remove the limitation to Windows -bool dotnetX86Available = IsRunningOnWindows() && System.IO.File.Exists(DOTNET_EXE_X86); - -if (dotnetX86Available) -{ - bool onAppVeyor = BuildSystem.IsRunningOnAppVeyor; - bool onGitHubActions = BuildSystem.IsRunningOnGitHubActions; - - StandardRunnerTests.Add(Net60X86Test); - // TODO: Make these tests run on AppVeyor and GitHub Actions - if (!onAppVeyor && !onGitHubActions) - StandardRunnerTests.Add(NetCore31X86Test); - if (!onAppVeyor && !onGitHubActions) - StandardRunnerTests.Add(Net70X86Test); - if (!onAppVeyor) - StandardRunnerTests.Add(Net80X86Test); - // Currently, NetCoreRunner runs tests in process. As a result, - // X86 tests will not work in our environment, although uses may run - // it as a tool using the X86 architecture. -} - -////////////////////////////////////////////////////////////////////// -// INDIVIDUAL PACKAGE TEST DEFINITIONS -////////////////////////////////////////////////////////////////////// - -static ExpectedResult MockAssemblyExpectedResult(int nCopies = 1) => new ExpectedResult("Failed") -{ - Total = 37 * nCopies, - Passed = 23 * nCopies, - Failed = 5 * nCopies, - Warnings = 1 * nCopies, - Inconclusive = 1 * nCopies, - Skipped = 7 * nCopies -}; - -static ExpectedResult MockAssemblyExpectedResult(params string[] runtimes) -{ - int nCopies = runtimes.Length; - var result = MockAssemblyExpectedResult(nCopies); - result.Assemblies = new ExpectedAssemblyResult[nCopies]; - for (int i = 0; i < nCopies; i++) - result.Assemblies[i] = new ExpectedAssemblyResult("mock-assembly.dll", runtimes[i]); - return result; -} - -static ExpectedResult MockAssemblyX86ExpectedResult(params string[] runtimes) -{ - int nCopies = runtimes.Length; - var result = MockAssemblyExpectedResult(nCopies); - result.Assemblies = new ExpectedAssemblyResult[nCopies]; - for (int i = 0; i < nCopies; i++) - result.Assemblies[i] = new ExpectedAssemblyResult("mock-assembly-x86.dll", runtimes[i]); - return result; -} - -static ExpectedResult MockAssemblySolutionResult = new ExpectedResult("Failed") -{ - Total = 37 * 5, - Passed = 23 * 5, - Failed = 5 * 5, - Warnings = 1 * 5, - Inconclusive = 1 * 5, - Skipped = 7 * 5, - Assemblies = new ExpectedAssemblyResult[] - { - new ExpectedAssemblyResult("mock-assembly.dll", "net-4.6.2"), - new ExpectedAssemblyResult("mock-assembly.dll", "netcore-3.1"), - new ExpectedAssemblyResult("mock-assembly.dll", "netcore-6.0"), - new ExpectedAssemblyResult("mock-assembly.dll", "netcore-7.0"), - new ExpectedAssemblyResult("mock-assembly.dll", "netcore-8.0"), - new ExpectedAssemblyResult("notest-assembly.dll", "net-4.6.2"), - new ExpectedAssemblyResult("notest-assembly.dll", "netcore-3.1"), - new ExpectedAssemblyResult("notest-assembly.dll", "netstandard-2.0") - } -}; - -static PackageTest Net462Test = new PackageTest( - 1, "Net462Test", - "Run mock-assembly.dll under .NET 4.6.2", - "net462/mock-assembly.dll", - MockAssemblyExpectedResult("net-4.6.2")); - -static PackageTest Net462X86Test = new PackageTest( - 1, "Net462X86Test", - "Run mock-assembly-x86.dll under .NET 4.6.2", - "net462/mock-assembly-x86.dll", - MockAssemblyX86ExpectedResult("net-4.6.2")); - -static PackageTest Net462ExeTest = new PackageTest( - 1, "Net462ExeTest", - "Run nunit.engine.core.tests.exe under .NET 4.6.2", - "net462/nunit.engine.core.tests.exe", - new ExpectedResult("Passed") { Assemblies = new[] { new ExpectedAssemblyResult("nunit.engine.core.tests.exe")}}); - -static PackageTest Net462PlusNet462Test = new PackageTest( - 1, "Net462PlusNet462Test", - "Run two copies of mock-assembly together", - "net462/mock-assembly.dll net462/mock-assembly.dll", - MockAssemblyExpectedResult("net-4.6.2", "net-4.6.2")); - -static PackageTest Net80Test = new PackageTest( - 1, "Net80Test", - "Run mock-assembly.dll under .NET 8.0", - "net8.0/mock-assembly.dll", - MockAssemblyExpectedResult("netcore-8.0")); - -static PackageTest Net80X86Test = new PackageTest( - 1, "Net80X86Test", - "Run mock-assembly-x86.dll under .NET 8.0", - "net8.0/mock-assembly-x86.dll", - MockAssemblyX86ExpectedResult("netcore-8.0")); - -static PackageTest Net70Test = new PackageTest( - 1, "Net70Test", - "Run mock-assembly.dll under .NET 7.0", - "net7.0/mock-assembly.dll", - MockAssemblyExpectedResult("netcore-7.0")); - -static PackageTest Net70X86Test = new PackageTest( - 1, "Net70X86Test", - "Run mock-assembly-x86.dll under .NET 7.0", - "net7.0/mock-assembly-x86.dll", - MockAssemblyX86ExpectedResult("netcore-7.0")); - -static PackageTest Net60Test = new PackageTest( - 1, "Net60Test", - "Run mock-assembly.dll under .NET 6.0", - "net6.0/mock-assembly.dll", - MockAssemblyExpectedResult("netcore-6.0")); - -static PackageTest Net60X86Test = new PackageTest( - 1, "Net60X86Test", - "Run mock-assembly-x86.dll under .NET 6.0", - "net6.0/mock-assembly-x86.dll", - MockAssemblyX86ExpectedResult("netcore-6.0")); - -static PackageTest NetCore31Test = new PackageTest( - 1, "NetCore31Test", - "Run mock-assembly.dll under .NET Core 3.1", - "netcoreapp3.1/mock-assembly.dll", - MockAssemblyExpectedResult("netcore-3.1")); - -static PackageTest NetCore31X86Test = new PackageTest( - 1, "NetCore31X86Test", - "Run mock-assembly-x86.dll under .NET Core 3.1", - "netcoreapp3.1/mock-assembly-x86.dll", - MockAssemblyX86ExpectedResult("netcore-3.1")); - -static PackageTest Net60PlusNet80Test = new PackageTest( - 1, "Net60PlusNet80Test", - "Run mock-assembly under .NET6.0 and 8.0 together", - "net6.0/mock-assembly.dll net8.0/mock-assembly.dll", - MockAssemblyExpectedResult("netcore-6.0", "netcore-8.0")); - -static PackageTest Net462PlusNet60Test = new PackageTest( - 1, "Net462PlusNet60Test", - "Run mock-assembly under .Net Framework 4.6.2 and .Net 6.0 together", - "net462/mock-assembly.dll net6.0/mock-assembly.dll", - MockAssemblyExpectedResult("net-4.6.2", "netcore-6.0")); - -// Test with latest released version of each of our extensions - -static ExtensionSpecifier NUnitProjectLoader = KnownExtensions.NUnitProjectLoader.SetVersion("3.8.0"); -static ExtensionSpecifier NUnitV2ResultWriter = KnownExtensions.NUnitV2ResultWriter.SetVersion("3.8.0"); -static ExtensionSpecifier VSProjectLoader = KnownExtensions.VSProjectLoader.SetVersion("3.9.0"); - -static PackageTest NUnitProjectTest = new PackageTest( - 1, "NUnitProjectTest", - "Run project with both copies of mock-assembly", - "../../NetFXTests.nunit --config=Release --trace=Debug", - MockAssemblyExpectedResult("net-4.6.2", "netcore-6.0"), - NUnitProjectLoader); - -static PackageTest V2ResultWriterTest = new PackageTest( - 1, "V2ResultWriterTest", - "Run mock-assembly under .NET 6.0 and produce V2 output", - "net6.0/mock-assembly.dll --result=TestResult.xml --result=NUnit2TestResult.xml;format=nunit2", - MockAssemblyExpectedResult("netcore-6.0"), - NUnitV2ResultWriter); - -static PackageTest VSProjectLoaderTest_Project = new PackageTest( - 1, "VSProjectLoaderTest_Project", - "Run mock-assembly using the .csproj file", - "../../src/NUnitEngine/mock-assembly/mock-assembly.csproj --config=Release", - MockAssemblyExpectedResult("net462", "netcore-3.1", "netcore-6.0", "netcore-7.0", "netcore-8.0"), - VSProjectLoader); - -static PackageTest VSProjectLoaderTest_Solution = new PackageTest( - 1, "VSProjectLoaderTest_Solution", - "Run mock-assembly using the .sln file", - "../../src/NUnitEngine/mock-assembly/mock-assembly.sln --config=Release", - MockAssemblySolutionResult, - VSProjectLoader); - ////////////////////////////////////////////////////////////////////// // LISTS OF FILES USED IN CHECKING PACKAGES ////////////////////////////////////////////////////////////////////// diff --git a/package-tests.cake b/package-tests.cake new file mode 100644 index 000000000..82ed7bc82 --- /dev/null +++ b/package-tests.cake @@ -0,0 +1,250 @@ +// Tests run for all runner packages except NETCORE runner +var StandardRunnerTests = new List(); + +// Tests run for the NETCORE runner package +var NetCoreRunnerTests = new List(); + +// Method for adding to both lists +void AddToBothLists(PackageTest test) +{ + StandardRunnerTests.Add(test); + NetCoreRunnerTests.Add(test); +} + +////////////////////////////////////////////////////////////////////// +// RUN MOCK-ASSEMBLY UNDER EACH RUNTIME +////////////////////////////////////////////////////////////////////// + +class MockAssemblyExpectedResult : ExpectedResult +{ + public MockAssemblyExpectedResult(params string[] runtimes) : base("Failed") + { + int nCopies = runtimes.Length; + Total = 37 * nCopies; + Passed = 23 * nCopies; + Failed = 5 * nCopies; + Warnings = 1 * nCopies; + Inconclusive = 1 * nCopies; + Skipped = 7 * nCopies; + Assemblies = new ExpectedAssemblyResult[nCopies]; + for (int i = 0; i < nCopies; i++) + Assemblies[i] = new ExpectedAssemblyResult("mock-assembly.dll", runtimes[i]); + } +} + +StandardRunnerTests.Add(new PackageTest( + 1, "Net462Test", + "Run mock-assembly.dll under .NET 4.6.2", + "net462/mock-assembly.dll", + new MockAssemblyExpectedResult("net-4.6.2"))); + +AddToBothLists(new PackageTest( + 1, "Net80Test", + "Run mock-assembly.dll under .NET 8.0", + "net8.0/mock-assembly.dll", + new MockAssemblyExpectedResult("netcore-8.0"))); + +AddToBothLists(new PackageTest( + 1, "Net70Test", + "Run mock-assembly.dll under .NET 7.0", + "net7.0/mock-assembly.dll", + new MockAssemblyExpectedResult("netcore-7.0"))); + +AddToBothLists(new PackageTest( + 1, "Net60Test", + "Run mock-assembly.dll under .NET 6.0", + "net6.0/mock-assembly.dll", + new MockAssemblyExpectedResult("netcore-6.0"))); + +AddToBothLists(new PackageTest( + 1, "NetCore31Test", + "Run mock-assembly.dll under .NET Core 3.1", + "netcoreapp3.1/mock-assembly.dll", + new MockAssemblyExpectedResult("netcore-3.1"))); + +////////////////////////////////////////////////////////////////////// +// RUN MOCK-ASSEMBLY-X86 UNDER EACH RUNTIME +////////////////////////////////////////////////////////////////////// + +const string DOTNET_EXE_X86 = @"C:\Program Files (x86)\dotnet\dotnet.exe"; +// TODO: Remove the limitation to Windows +bool dotnetX86Available = IsRunningOnWindows() && System.IO.File.Exists(DOTNET_EXE_X86); + +class MockAssemblyX86ExpectedResult : MockAssemblyExpectedResult +{ + public MockAssemblyX86ExpectedResult(params string[] runtimes) : base(runtimes) + { + for (int i = 0; i < runtimes.Length; i++) + Assemblies[i] = new ExpectedAssemblyResult("mock-assembly-x86.dll", runtimes[i]); + } +} + +// X86 is always available for .NET Framework +StandardRunnerTests.Add(new PackageTest( + 1, "Net462X86Test", + "Run mock-assembly-x86.dll under .NET 4.6.2", + "net462/mock-assembly-x86.dll", + new MockAssemblyX86ExpectedResult("net-4.6.2"))); + +if (dotnetX86Available) +{ + // TODO: Make tests run on all build platforms + bool onAppVeyor = BuildSystem.IsRunningOnAppVeyor; + bool onGitHubActions = BuildSystem.IsRunningOnGitHubActions; + + if (!onAppVeyor) + StandardRunnerTests.Add(new PackageTest( + 1, "Net80X86Test", + "Run mock-assembly-x86.dll under .NET 8.0", + "net8.0/mock-assembly-x86.dll", + new MockAssemblyX86ExpectedResult("netcore-8.0"))); + + if (!onAppVeyor && !onGitHubActions) + StandardRunnerTests.Add(new PackageTest( + 1, "Net70X86Test", + "Run mock-assembly-x86.dll under .NET 7.0", + "net7.0/mock-assembly-x86.dll", + new MockAssemblyX86ExpectedResult("netcore-7.0"))); + + StandardRunnerTests.Add(new PackageTest( + 1, "Net60X86Test", + "Run mock-assembly-x86.dll under .NET 6.0", + "net6.0/mock-assembly-x86.dll", + new MockAssemblyX86ExpectedResult("netcore-6.0"))); + + if (!onAppVeyor && !onGitHubActions) + StandardRunnerTests.Add(new PackageTest( + 1, "NetCore31X86Test", + "Run mock-assembly-x86.dll under .NET Core 3.1", + "netcoreapp3.1/mock-assembly-x86.dll", + new MockAssemblyX86ExpectedResult("netcore-3.1"))); +} + +////////////////////////////////////////////////////////////////////// +// RUN MULTIPLE COPIES OF MOCK-ASSEMBLY +////////////////////////////////////////////////////////////////////// + +StandardRunnerTests.Add(new PackageTest( + 1, "Net462PlusNet462Test", + "Run two copies of mock-assembly together", + "net462/mock-assembly.dll net462/mock-assembly.dll", + new MockAssemblyExpectedResult("net-4.6.2", "net-4.6.2"))); + +StandardRunnerTests.Add(new PackageTest( + 1, "Net60PlusNet80Test", + "Run mock-assembly under .NET6.0 and 8.0 together", + "net6.0/mock-assembly.dll net8.0/mock-assembly.dll", + new MockAssemblyExpectedResult("netcore-6.0", "netcore-8.0"))); + +StandardRunnerTests.Add(new PackageTest( + 1, "Net462PlusNet60Test", + "Run mock-assembly under .Net Framework 4.6.2 and .Net 6.0 together", + "net462/mock-assembly.dll net6.0/mock-assembly.dll", + new MockAssemblyExpectedResult("net-4.6.2", "netcore-6.0"))); + +////////////////////////////////////////////////////////////////////// +// ASP.NETCORE TESTS +////////////////////////////////////////////////////////////////////// + +StandardRunnerTests.Add(new PackageTest( + 1, "Net60AspNetCoreTest", "Run test using AspNetCore targeting .NET 6.0", + "net6.0/aspnetcore-test.dll", new ExpectedResult("Passed") + { + Total = 2, Passed = 2, Failed = 0, Warnings = 0, Inconclusive = 0, Skipped = 0, + Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("aspnetcore-test.dll", "netcore-6.0") } + })); + +StandardRunnerTests.Add(new PackageTest( + 1, "Net80AspNetCoreTest", "Run test using AspNetCore targeting .NET 8.0", + "net8.0/aspnetcore-test.dll", new ExpectedResult("Passed") + { + Total = 2, Passed = 2, Failed = 0, Warnings = 0, Inconclusive = 0, Skipped = 0, + Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("aspnetcore-test.dll", "netcore-8.0") } + })); + +////////////////////////////////////////////////////////////////////// +// WINDOWS FORMS TESTS +////////////////////////////////////////////////////////////////////// + +StandardRunnerTests.Add(new PackageTest( + 1, "Net60WindowsFormsTest", "Run test using windows forms under .NET 6.0", + "net6.0-windows/windows-forms-test.dll", new ExpectedResult("Passed") + { + Total = 2, Passed = 2, Failed = 0, Warnings = 0, Inconclusive = 0, Skipped = 0, + Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("windows-forms-test.dll", "netcore-6.0") } + })); + +StandardRunnerTests.Add(new PackageTest( + 1, "Net80WindowsFormsTest", "Run test using windows forms under .NET 8.0", + "net8.0-windows/windows-forms-test.dll", new ExpectedResult("Passed") + { + Total = 2, Passed = 2, Failed = 0, Warnings = 0, Inconclusive = 0, Skipped = 0, + Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("windows-forms-test.dll", "netcore-8.0") } + })); + +////////////////////////////////////////////////////////////////////// +// WPF TESTS +////////////////////////////////////////////////////////////////////// + +StandardRunnerTests.Add(new PackageTest( + 1, "Net60WPFTest", "Run test using WPF under .NET 6.0", + "net6.0-windows/WpfTest.dll --trace=Debug", + new ExpectedResult("Passed") { Assemblies = new[] { new ExpectedAssemblyResult("WpfTest.dll", "netcore-6.0") } })); + +StandardRunnerTests.Add(new PackageTest( + 1, "Net80WPFTest", "Run test using WPF under .NET 8.0", + "net8.0-windows/WpfTest.dll --trace=Debug", + new ExpectedResult("Passed") { Assemblies = new[] { new ExpectedAssemblyResult("WpfTest.dll", "netcore-8.0") } })); + +////////////////////////////////////////////////////////////////////// +// RUN TESTS USING EACH OF OUR EXTENSIONS +////////////////////////////////////////////////////////////////////// + +StandardRunnerTests.Add(new PackageTest( + 1, "NUnitProjectTest", + "Run project with both copies of mock-assembly", + "../../NetFXTests.nunit --config=Release --trace=Debug", + new MockAssemblyExpectedResult("net-4.6.2", "netcore-6.0"), + KnownExtensions.NUnitProjectLoader.SetVersion("3.8.0"))); + +StandardRunnerTests.Add(new PackageTest( + 1, "V2ResultWriterTest", + "Run mock-assembly under .NET 6.0 and produce V2 output", + "net6.0/mock-assembly.dll --result=TestResult.xml --result=NUnit2TestResult.xml;format=nunit2", + new MockAssemblyExpectedResult("netcore-6.0"), + KnownExtensions.NUnitV2ResultWriter.SetVersion("3.8.0"))); + +StandardRunnerTests.Add(new PackageTest( + 1, "VSProjectLoaderTest_Project", + "Run mock-assembly using the .csproj file", + "../../src/TestData/mock-assembly/mock-assembly.csproj --config=Release", + new MockAssemblyExpectedResult("net462", "netcore-3.1", "netcore-6.0", "netcore-7.0", "netcore-8.0"), + KnownExtensions.VSProjectLoader.SetVersion("3.9.0"))); + +static ExpectedResult MockAssemblySolutionResult = new ExpectedResult("Failed") +{ + Total = 37 * 5, + Passed = 23 * 5, + Failed = 5 * 5, + Warnings = 1 * 5, + Inconclusive = 1 * 5, + Skipped = 7 * 5, + Assemblies = new ExpectedAssemblyResult[] + { + new ExpectedAssemblyResult("mock-assembly.dll", "net-4.6.2"), + new ExpectedAssemblyResult("mock-assembly.dll", "netcore-3.1"), + new ExpectedAssemblyResult("mock-assembly.dll", "netcore-6.0"), + new ExpectedAssemblyResult("mock-assembly.dll", "netcore-7.0"), + new ExpectedAssemblyResult("mock-assembly.dll", "netcore-8.0"), + new ExpectedAssemblyResult("notest-assembly.dll", "net-4.6.2"), + new ExpectedAssemblyResult("notest-assembly.dll", "netcore-3.1"), + new ExpectedAssemblyResult("notest-assembly.dll", "netstandard-2.0") + } +}; + +StandardRunnerTests.Add(new PackageTest( + 1, "VSProjectLoaderTest_Solution", + "Run mock-assembly using the .sln file", + "../../src/TestData/TestData.sln --config=Release --trace=Debug", + MockAssemblySolutionResult, + KnownExtensions.VSProjectLoader.SetVersion("3.9.0"))); diff --git a/src/NUnitConsole/nunit3-console.tests/nunit3-console.tests.csproj b/src/NUnitConsole/nunit3-console.tests/nunit3-console.tests.csproj index f740358e0..a9f1aec4d 100644 --- a/src/NUnitConsole/nunit3-console.tests/nunit3-console.tests.csproj +++ b/src/NUnitConsole/nunit3-console.tests/nunit3-console.tests.csproj @@ -43,7 +43,7 @@ - + diff --git a/src/NUnitEngine/nunit.engine.core.tests/nunit.engine.core.tests.csproj b/src/NUnitEngine/nunit.engine.core.tests/nunit.engine.core.tests.csproj index 66047d496..c89e0b00b 100644 --- a/src/NUnitEngine/nunit.engine.core.tests/nunit.engine.core.tests.csproj +++ b/src/NUnitEngine/nunit.engine.core.tests/nunit.engine.core.tests.csproj @@ -34,7 +34,7 @@ - + diff --git a/src/NUnitEngine/nunit.engine.core/Internal/TestAssemblyResolver.cs b/src/NUnitEngine/nunit.engine.core/Internal/TestAssemblyResolver.cs index fe9d53336..1e8d82573 100644 --- a/src/NUnitEngine/nunit.engine.core/Internal/TestAssemblyResolver.cs +++ b/src/NUnitEngine/nunit.engine.core/Internal/TestAssemblyResolver.cs @@ -69,7 +69,7 @@ public Assembly Resolve(AssemblyLoadContext context, AssemblyName name) private Assembly OnResolving(AssemblyLoadContext context, AssemblyName name) { context = context ?? _loadContext; - + if (TryLoadFromTrustedPlatformAssemblies(context, name, out var loadedAssembly)) { log.Info("'{0}' assembly is loaded from trusted path '{1}'", name, loadedAssembly.Location); diff --git a/src/NUnitEngine/nunit.engine.tests/nunit.engine.tests.csproj b/src/NUnitEngine/nunit.engine.tests/nunit.engine.tests.csproj index 3373d6904..52e36ebdd 100644 --- a/src/NUnitEngine/nunit.engine.tests/nunit.engine.tests.csproj +++ b/src/NUnitEngine/nunit.engine.tests/nunit.engine.tests.csproj @@ -34,7 +34,7 @@ - + diff --git a/src/NUnitEngine/mock-assembly/mock-assembly.sln b/src/TestData/TestData.sln similarity index 89% rename from src/NUnitEngine/mock-assembly/mock-assembly.sln rename to src/TestData/TestData.sln index 9b4908fa7..2364ee3ab 100644 --- a/src/NUnitEngine/mock-assembly/mock-assembly.sln +++ b/src/TestData/TestData.sln @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34525.116 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mock-assembly", "mock-assembly.csproj", "{FB3F6F62-37AB-4193-87A9-197C2E0CBC1B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mock-assembly", "mock-assembly\mock-assembly.csproj", "{FB3F6F62-37AB-4193-87A9-197C2E0CBC1B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "notest-assembly", "..\notest-assembly\notest-assembly.csproj", "{F412390F-E7C4-41B4-A84E-8FC4DC3FB2F7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "notest-assembly", "notest-assembly\notest-assembly.csproj", "{F412390F-E7C4-41B4-A84E-8FC4DC3FB2F7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/TestData/aspnetcore-test/AspNetCoreTest.cs b/src/TestData/aspnetcore-test/AspNetCoreTest.cs new file mode 100644 index 000000000..e4ba287b8 --- /dev/null +++ b/src/TestData/aspnetcore-test/AspNetCoreTest.cs @@ -0,0 +1,25 @@ +// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt + +using NUnit.Framework; +using Microsoft.AspNetCore.Components.Forms; + +// Test which resolves issue #1203 +namespace Test1 +{ + [TestFixture] + public class AspNetCoreTest + { + [Test] + public void WithoutFramework() + { + Assert.Pass(); + } + + [Test] + public void WithFramework() + { + InputCheckbox checkbox = new InputCheckbox(); + Assert.Pass(); + } + } +} \ No newline at end of file diff --git a/src/TestData/aspnetcore-test/aspnetcore-test.csproj b/src/TestData/aspnetcore-test/aspnetcore-test.csproj new file mode 100644 index 000000000..46fe89800 --- /dev/null +++ b/src/TestData/aspnetcore-test/aspnetcore-test.csproj @@ -0,0 +1,13 @@ + + + + net6.0;net8.0 + Library + false + + + + + + + diff --git a/src/NUnitEngine/mock-assembly-x86/mock-assembly-x86.csproj b/src/TestData/mock-assembly-x86/mock-assembly-x86.csproj similarity index 100% rename from src/NUnitEngine/mock-assembly-x86/mock-assembly-x86.csproj rename to src/TestData/mock-assembly-x86/mock-assembly-x86.csproj diff --git a/src/NUnitEngine/mock-assembly/AccessesCurrentTestContextDuringDiscovery.cs b/src/TestData/mock-assembly/AccessesCurrentTestContextDuringDiscovery.cs similarity index 100% rename from src/NUnitEngine/mock-assembly/AccessesCurrentTestContextDuringDiscovery.cs rename to src/TestData/mock-assembly/AccessesCurrentTestContextDuringDiscovery.cs diff --git a/src/NUnitEngine/mock-assembly/MockAssembly.cs b/src/TestData/mock-assembly/MockAssembly.cs similarity index 100% rename from src/NUnitEngine/mock-assembly/MockAssembly.cs rename to src/TestData/mock-assembly/MockAssembly.cs diff --git a/src/NUnitEngine/mock-assembly/mock-assembly.csproj b/src/TestData/mock-assembly/mock-assembly.csproj similarity index 100% rename from src/NUnitEngine/mock-assembly/mock-assembly.csproj rename to src/TestData/mock-assembly/mock-assembly.csproj diff --git a/src/NUnitEngine/mock-cpp-clr/AssemblyInfo.cpp b/src/TestData/mock-cpp-clr/AssemblyInfo.cpp similarity index 100% rename from src/NUnitEngine/mock-cpp-clr/AssemblyInfo.cpp rename to src/TestData/mock-cpp-clr/AssemblyInfo.cpp diff --git a/src/NUnitEngine/mock-cpp-clr/TestClass.cpp b/src/TestData/mock-cpp-clr/TestClass.cpp similarity index 100% rename from src/NUnitEngine/mock-cpp-clr/TestClass.cpp rename to src/TestData/mock-cpp-clr/TestClass.cpp diff --git a/src/NUnitEngine/mock-cpp-clr/TestClass.h b/src/TestData/mock-cpp-clr/TestClass.h similarity index 100% rename from src/NUnitEngine/mock-cpp-clr/TestClass.h rename to src/TestData/mock-cpp-clr/TestClass.h diff --git a/src/NUnitEngine/mock-cpp-clr/mock-cpp-clr-x64.vcxproj b/src/TestData/mock-cpp-clr/mock-cpp-clr-x64.vcxproj similarity index 100% rename from src/NUnitEngine/mock-cpp-clr/mock-cpp-clr-x64.vcxproj rename to src/TestData/mock-cpp-clr/mock-cpp-clr-x64.vcxproj diff --git a/src/NUnitEngine/mock-cpp-clr/mock-cpp-clr-x86.vcxproj b/src/TestData/mock-cpp-clr/mock-cpp-clr-x86.vcxproj similarity index 100% rename from src/NUnitEngine/mock-cpp-clr/mock-cpp-clr-x86.vcxproj rename to src/TestData/mock-cpp-clr/mock-cpp-clr-x86.vcxproj diff --git a/src/NUnitEngine/notest-assembly/Properties/AssemblyInfo.cs b/src/TestData/notest-assembly/Properties/AssemblyInfo.cs similarity index 100% rename from src/NUnitEngine/notest-assembly/Properties/AssemblyInfo.cs rename to src/TestData/notest-assembly/Properties/AssemblyInfo.cs diff --git a/src/NUnitEngine/notest-assembly/notest-assembly.csproj b/src/TestData/notest-assembly/notest-assembly.csproj similarity index 100% rename from src/NUnitEngine/notest-assembly/notest-assembly.csproj rename to src/TestData/notest-assembly/notest-assembly.csproj diff --git a/src/TestData/windows-forms-test/WindowsFormsTest.cs b/src/TestData/windows-forms-test/WindowsFormsTest.cs new file mode 100644 index 000000000..64686341b --- /dev/null +++ b/src/TestData/windows-forms-test/WindowsFormsTest.cs @@ -0,0 +1,25 @@ +// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt + +using System.Windows.Forms; +using NUnit.Framework; + +// Test which resolves issue #1203 +namespace Test1 +{ + [TestFixture] + public class WindowsFormsTest + { + [Test] + public void WithoutFramework() + { + Assert.Pass(); + } + + [Test] + public void WithFramework() + { + var checkbox = new CheckBox(); + Assert.Pass(); + } + } +} \ No newline at end of file diff --git a/src/TestData/windows-forms-test/windows-forms-test.csproj b/src/TestData/windows-forms-test/windows-forms-test.csproj new file mode 100644 index 000000000..9ad93a3c3 --- /dev/null +++ b/src/TestData/windows-forms-test/windows-forms-test.csproj @@ -0,0 +1,13 @@ + + + + net6.0-windows;net8.0-windows + true + false + + + + + + + diff --git a/src/TestData/wpf-test/WpfTest.cs b/src/TestData/wpf-test/WpfTest.cs new file mode 100644 index 000000000..d2b3632b0 --- /dev/null +++ b/src/TestData/wpf-test/WpfTest.cs @@ -0,0 +1,26 @@ +// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt + +using System; +using System.Windows.Controls; +using NUnit.Framework; + +// Test which resolves issue #1203 +namespace Test1 +{ + [TestFixture] + public class WPFTest + { + [Test] + public void WithoutFramework() + { + Assert.Pass(); + } + + [Test] + public void WithFramework() + { + //CheckBox checkbox; + + } + } +} \ No newline at end of file diff --git a/src/TestData/wpf-test/WpfTest.csproj b/src/TestData/wpf-test/WpfTest.csproj new file mode 100644 index 000000000..a4c0ff808 --- /dev/null +++ b/src/TestData/wpf-test/WpfTest.csproj @@ -0,0 +1,12 @@ + + + + net6.0-windows;net8.0-windows + true + + + + + + + From 7ce369e3b2351ff76fa795066970e91f156ac4d3 Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Mon, 9 Sep 2024 10:36:39 -0700 Subject: [PATCH 2/2] Hadnle unmanaged executables without throwing --- NUnitConsole.sln | 10 ++ package-tests.cake | 3 +- .../Runners/NotRunnableTestRunner.cs | 131 ++++++++++++++++++ .../nunit.engine/Runners/MasterTestRunner.cs | 2 +- .../Services/DefaultTestRunnerFactory.cs | 4 + .../Services/RuntimeFrameworkService.cs | 43 +++--- src/TestData/TestData.sln | 6 + src/TestData/WpfApp/Program.cs | 17 +++ src/TestData/WpfApp/WpfApp.csproj | 10 ++ 9 files changed, 208 insertions(+), 18 deletions(-) create mode 100644 src/NUnitEngine/nunit.engine.core/Runners/NotRunnableTestRunner.cs create mode 100644 src/TestData/WpfApp/Program.cs create mode 100644 src/TestData/WpfApp/WpfApp.csproj diff --git a/NUnitConsole.sln b/NUnitConsole.sln index 6726812b1..acd529631 100644 --- a/NUnitConsole.sln +++ b/NUnitConsole.sln @@ -130,6 +130,9 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfTest", "src\TestData\wpf-test\WpfTest.csproj", "{A96876EE-1A1F-4096-9B6A-5739E66B3364}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestData", "TestData", "{2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F}" + ProjectSection(SolutionItems) = preProject + src\TestData\TestData.sln = src\TestData\TestData.sln + EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mock-assembly", "src\TestData\mock-assembly\mock-assembly.csproj", "{C3FF8716-052B-4D6C-81FF-E80F89AF9A80}" EndProject @@ -137,6 +140,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mock-assembly-x86", "src\Te EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "notest-assembly", "src\TestData\notest-assembly\notest-assembly.csproj", "{81E63A90-3191-4E99-92FF-01F9B1D3E3C5}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfApp", "src\TestData\WpfApp\WpfApp.csproj", "{6B550F25-1CA5-4F3E-B631-1ECCD4CB94E4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -203,6 +208,10 @@ Global {81E63A90-3191-4E99-92FF-01F9B1D3E3C5}.Debug|Any CPU.Build.0 = Debug|Any CPU {81E63A90-3191-4E99-92FF-01F9B1D3E3C5}.Release|Any CPU.ActiveCfg = Release|Any CPU {81E63A90-3191-4E99-92FF-01F9B1D3E3C5}.Release|Any CPU.Build.0 = Release|Any CPU + {6B550F25-1CA5-4F3E-B631-1ECCD4CB94E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6B550F25-1CA5-4F3E-B631-1ECCD4CB94E4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6B550F25-1CA5-4F3E-B631-1ECCD4CB94E4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6B550F25-1CA5-4F3E-B631-1ECCD4CB94E4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -234,6 +243,7 @@ Global {C3FF8716-052B-4D6C-81FF-E80F89AF9A80} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} {8FE8378E-5A8B-4708-8F86-35BE0DE121F7} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} {81E63A90-3191-4E99-92FF-01F9B1D3E3C5} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} + {6B550F25-1CA5-4F3E-B631-1ECCD4CB94E4} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D8E4FC26-5422-4C51-8BBC-D1AC0A578711} diff --git a/package-tests.cake b/package-tests.cake index 82ed7bc82..bd1faf66e 100644 --- a/package-tests.cake +++ b/package-tests.cake @@ -238,7 +238,8 @@ static ExpectedResult MockAssemblySolutionResult = new ExpectedResult("Failed") new ExpectedAssemblyResult("mock-assembly.dll", "netcore-8.0"), new ExpectedAssemblyResult("notest-assembly.dll", "net-4.6.2"), new ExpectedAssemblyResult("notest-assembly.dll", "netcore-3.1"), - new ExpectedAssemblyResult("notest-assembly.dll", "netstandard-2.0") + new ExpectedAssemblyResult("notest-assembly.dll", "netstandard-2.0"), + new ExpectedAssemblyResult("WpfApp.exe") } }; diff --git a/src/NUnitEngine/nunit.engine.core/Runners/NotRunnableTestRunner.cs b/src/NUnitEngine/nunit.engine.core/Runners/NotRunnableTestRunner.cs new file mode 100644 index 000000000..b6e0fc5d0 --- /dev/null +++ b/src/NUnitEngine/nunit.engine.core/Runners/NotRunnableTestRunner.cs @@ -0,0 +1,131 @@ +// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection.Emit; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace NUnit.Engine.Runners +{ + public abstract class NotRunnableTestRunner : ITestEngineRunner + { + private const string LOAD_RESULT_FORMAT = + "" + + "" + + "" + + "" + + ""; + + private const string RUN_RESULT_FORMAT = + "" + + "" + + "" + + "" + + "" + + "{7}" + + "" + + ""; + + private string _name; + private string _fullname; + private string _message; + private string _type; + + protected string _runstate; + protected string _result; + protected string _label; + + public NotRunnableTestRunner(string assemblyPath, string message) + { + _name = Escape(Path.GetFileName(assemblyPath)); + _fullname = Escape(Path.GetFullPath(assemblyPath)); + _message = Escape(message); + _type = new List { ".dll", ".exe" }.Contains(Path.GetExtension(assemblyPath)) ? "Assembly" : "Unknown"; + } + + public string ID { get; set; } + + TestEngineResult ITestEngineRunner.Load() + { + return GetLoadResult(); + } + + void ITestEngineRunner.Unload() + { + } + + TestEngineResult ITestEngineRunner.Reload() + { + return GetLoadResult(); + } + + int ITestEngineRunner.CountTestCases(TestFilter filter) + { + return 0; + } + + TestEngineResult ITestEngineRunner.Run(ITestEventListener listener, TestFilter filter) + { + return new TestEngineResult(string.Format(RUN_RESULT_FORMAT, + _type, TestID, _name, _fullname, _runstate, _result, _label, _message)); + } + + AsyncTestEngineResult ITestEngineRunner.RunAsync(ITestEventListener listener, TestFilter filter) + { + throw new NotImplementedException(); + } + + void ITestEngineRunner.StopRun(bool force) + { + } + + TestEngineResult ITestEngineRunner.Explore(TestFilter filter) + { + return GetLoadResult(); + } + + void IDisposable.Dispose() + { + // Nothing to do here + } + + private static string Escape(string original) + { + return original + .Replace("&", "&") + .Replace("\"", """) + .Replace("'", "'") + .Replace("<", "<") + .Replace(">", ">"); + } + + private TestEngineResult GetLoadResult() + { + return new TestEngineResult(string.Format( + LOAD_RESULT_FORMAT, + _type, TestID, _name, _fullname, _runstate, _message)); + } + + private string TestID + { + get + { + return string.IsNullOrEmpty(ID) + ? "1" + : ID + "-1"; + } + } + } + + public class UnmanagedExecutableTestRunner : NotRunnableTestRunner + { + public UnmanagedExecutableTestRunner(string assemblyPath) + : base (assemblyPath, "Unmanaged libraries or applications are not supported") + { } + } +} diff --git a/src/NUnitEngine/nunit.engine/Runners/MasterTestRunner.cs b/src/NUnitEngine/nunit.engine/Runners/MasterTestRunner.cs index f23c70572..3418ce60e 100644 --- a/src/NUnitEngine/nunit.engine/Runners/MasterTestRunner.cs +++ b/src/NUnitEngine/nunit.engine/Runners/MasterTestRunner.cs @@ -22,7 +22,7 @@ public class MasterTestRunner : ITestRunner // MasterTestRunner is the only runner that is passed back // to users asking for an ITestRunner. The actual details of // execution are handled by various internal runners, which - // impement ITestEngineRunner. + // implement ITestEngineRunner. // // Explore and execution results from MasterTestRunner are // returned as XmlNodes, created from the internal diff --git a/src/NUnitEngine/nunit.engine/Services/DefaultTestRunnerFactory.cs b/src/NUnitEngine/nunit.engine/Services/DefaultTestRunnerFactory.cs index 5fdb79de4..b53a66995 100644 --- a/src/NUnitEngine/nunit.engine/Services/DefaultTestRunnerFactory.cs +++ b/src/NUnitEngine/nunit.engine/Services/DefaultTestRunnerFactory.cs @@ -43,6 +43,10 @@ public ITestEngineRunner MakeTestRunner(TestPackage package) } #else + // Unmanaged code is handled in-process irrespective of the process model + if (package.GetSetting(InternalEnginePackageSettings.ImageTargetFrameworkName, "").StartsWith("Unmanaged,")) + return new UnmanagedExecutableTestRunner(package.FullName); + ProcessModel processModel = (ProcessModel)System.Enum.Parse( typeof(ProcessModel), package.GetSetting(EnginePackageSettings.ProcessModel, "Default")); diff --git a/src/NUnitEngine/nunit.engine/Services/RuntimeFrameworkService.cs b/src/NUnitEngine/nunit.engine/Services/RuntimeFrameworkService.cs index 1d9c067fb..a977fbdb7 100644 --- a/src/NUnitEngine/nunit.engine/Services/RuntimeFrameworkService.cs +++ b/src/NUnitEngine/nunit.engine/Services/RuntimeFrameworkService.cs @@ -160,6 +160,8 @@ private RuntimeFramework SelectRuntimeFrameworkInner(TestPackage package) targetRuntime = RuntimeType.NetCore; targetVersion = new Version(3, 1); break; + case "Unmanaged": + return null; default: throw new NUnitEngineException("Unsupported Target Framework: " + imageTargetFrameworkNameSetting); } @@ -283,26 +285,35 @@ private static void ApplyImageData(TestPackage package) } else if (File.Exists(packageName) && PathUtils.IsAssemblyFileType(packageName)) { - using (var assembly = AssemblyDefinition.ReadAssembly(packageName)) + try { - targetVersion = assembly.GetRuntimeVersion(); - log.Debug($"Assembly {packageName} uses version {targetVersion}"); - - frameworkName = assembly.GetFrameworkName(); - log.Debug($"Assembly {packageName} targets {frameworkName}"); - - if (assembly.RequiresX86()) + using (var assembly = AssemblyDefinition.ReadAssembly(packageName)) { - requiresX86 = true; - log.Debug($"Assembly {packageName} will be run x86"); - } - - if (assembly.HasAttribute("NUnit.Framework.TestAssemblyDirectoryResolveAttribute")) - { - requiresAssemblyResolver = true; - log.Debug($"Assembly {packageName} requires default app domain assembly resolver"); + targetVersion = assembly.GetRuntimeVersion(); + log.Debug($"Assembly {packageName} uses version {targetVersion}"); + + frameworkName = assembly.GetFrameworkName(); + log.Debug($"Assembly {packageName} targets {frameworkName}"); + + if (assembly.RequiresX86()) + { + requiresX86 = true; + log.Debug($"Assembly {packageName} will be run x86"); + } + + if (assembly.HasAttribute("NUnit.Framework.TestAssemblyDirectoryResolveAttribute")) + { + requiresAssemblyResolver = true; + log.Debug($"Assembly {packageName} requires default app domain assembly resolver"); + } } } + catch (BadImageFormatException) + { + // "Unmanaged" is not a valid framework identifier but we handle it upstream + // using UnmanagedCodeTestRunner, which doesn't actually try to run it. + frameworkName = "Unmanaged,Version=0.0"; + } } if (targetVersion.Major > 0) diff --git a/src/TestData/TestData.sln b/src/TestData/TestData.sln index 2364ee3ab..ac4378dac 100644 --- a/src/TestData/TestData.sln +++ b/src/TestData/TestData.sln @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mock-assembly", "mock-assem EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "notest-assembly", "notest-assembly\notest-assembly.csproj", "{F412390F-E7C4-41B4-A84E-8FC4DC3FB2F7}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfApp", "WpfApp\WpfApp.csproj", "{F831D879-E806-4DE7-8D80-9B94AD64744A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {F412390F-E7C4-41B4-A84E-8FC4DC3FB2F7}.Debug|Any CPU.Build.0 = Debug|Any CPU {F412390F-E7C4-41B4-A84E-8FC4DC3FB2F7}.Release|Any CPU.ActiveCfg = Release|Any CPU {F412390F-E7C4-41B4-A84E-8FC4DC3FB2F7}.Release|Any CPU.Build.0 = Release|Any CPU + {F831D879-E806-4DE7-8D80-9B94AD64744A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F831D879-E806-4DE7-8D80-9B94AD64744A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F831D879-E806-4DE7-8D80-9B94AD64744A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F831D879-E806-4DE7-8D80-9B94AD64744A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/TestData/WpfApp/Program.cs b/src/TestData/WpfApp/Program.cs new file mode 100644 index 000000000..db1e92a02 --- /dev/null +++ b/src/TestData/WpfApp/Program.cs @@ -0,0 +1,17 @@ +// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt + +namespace WpfApp +{ + internal class Program + { + static void Main() { } + } +} diff --git a/src/TestData/WpfApp/WpfApp.csproj b/src/TestData/WpfApp/WpfApp.csproj new file mode 100644 index 000000000..0dee5c4b5 --- /dev/null +++ b/src/TestData/WpfApp/WpfApp.csproj @@ -0,0 +1,10 @@ + + + + WinExe + net8.0-windows + ..\..\bin\$(Configuration)\ + true + + +