From a7bdf1670272d8ac0b00985eee378190b687fc96 Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Thu, 8 May 2025 12:24:36 -0700 Subject: [PATCH] Cleanup code --- NuGet.config | 10 + build.cake | 100 +++---- net80-pluggable-agent.sln | 1 - ...cessesCurrentTestContextDuringDiscovery.cs | 28 -- src/testdata/mock-assembly/MockAssembly.cs | 267 +++--------------- src/tests/Program.cs | 3 +- .../nunit-agent-launcher-net80.tests.csproj | 2 +- 7 files changed, 90 insertions(+), 321 deletions(-) create mode 100644 NuGet.config delete mode 100644 src/testdata/mock-assembly/AccessesCurrentTestContextDuringDiscovery.cs diff --git a/NuGet.config b/NuGet.config new file mode 100644 index 0000000..fe24e8f --- /dev/null +++ b/NuGet.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/build.cake b/build.cake index 4f22ecb..8c6e315 100644 --- a/build.cake +++ b/build.cake @@ -1,5 +1,5 @@ // Load the recipe -#load nuget:?package=NUnit.Cake.Recipe&version=1.5.0-alpha.1 +#load nuget:?package=NUnit.Cake.Recipe&version=1.5.0-alpha.4 // Comment out above line and uncomment below for local tests of recipe changes //#load ../NUnit.Cake.Recipe/recipe/*.cake @@ -13,104 +13,96 @@ BuildSettings.Initialize githubRepository: "net80-pluggable-agent" ); -var MockAssemblyResult1 = new ExpectedResult("Failed") -{ - Total = 36, - Passed = 23, - Failed = 5, - Warnings = 1, - Inconclusive = 1, - Skipped = 7, - Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("mock-assembly.dll") } -}; - -var MockAssemblyResult2 = new ExpectedResult("Failed") -{ - Total = 37, - Passed = 23, - Failed = 5, - Warnings = 1, - Inconclusive = 1, - Skipped = 7, - Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("mock-assembly.dll") } -}; - -var AspNetCoreResult = new ExpectedResult("Passed") -{ - Total = 2, - Passed = 2, - Failed = 0, - Warnings = 0, - Inconclusive = 0, - Skipped = 0, - Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("aspnetcore-test.dll") } -}; - -var WindowsFormsResult = new ExpectedResult("Passed") -{ - Total = 2, - Passed = 2, - Failed = 0, - Warnings = 0, - Inconclusive = 0, - Skipped = 0, - Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("windows-test.dll") } -}; - var PackageTests = new PackageTest[] { //new PackageTest(1, "NetCore11PackageTest") //{ // Description = "Run mock-assembly.dll targeting .NET Core 1.1", // Arguments = "tests/netcoreapp1.1/mock-assembly.dll", - // ExpectedResult = MockAssemblyResult1 + // ExpectedResult = new ExpectedResult("Failed") + // { + // Total = 35, Passed = 21, Failed = 5, Warnings = 1, Inconclusive = 1, Skipped = 7, + // Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("mock-assembly.dll") } + // } //}, //new PackageTest(1, "NetCore21PackageTest") //{ // Description = "Run mock-assembly.dll targeting .NET Core 2.1", // Arguments = "tests/netcoreapp2.1/mock-assembly.dll", - // ExpectedResult = MockAssemblyResult2 + // ExpectedResult = new ExpectedResult("Failed") + // { + // Total = 35, Passed = 21, Failed = 5, Warnings = 1, Inconclusive = 1, Skipped = 7, + // Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("mock-assembly.dll") } + // } //}, new PackageTest(1, "NetCore31PackageTest") { Description = "Run mock-assembly.dll targeting .NET Core 3.1", Arguments = "testdata/netcoreapp3.1/mock-assembly.dll", - ExpectedResult = MockAssemblyResult2, + ExpectedResult = new ExpectedResult("Failed") + { + Total = 35, Passed = 21, Failed = 5, Warnings = 1, Inconclusive = 1, Skipped = 7, + Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("mock-assembly.dll") } + } }, //new PackageTest(1, "Net50PackageTest") //{ // Description = "Run mock-assembly.dll targeting .NET 5.0", // Arguments = "testdata/net5.0/mock-assembly.dll", - // ExpectedResult = MockAssemblyResult2, + // ExpectedResult = new ExpectedResult("Failed") + // { + // Total = 35, Passed = 21, Failed = 5, Warnings = 1, Inconclusive = 1, Skipped = 7, + // Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("mock-assembly.dll") } + // } //}, new PackageTest(1, "Net60PackageTest") { Description = "Run mock-assembly.dll targeting .NET 6.0", Arguments = "testdata/net6.0/mock-assembly.dll", - ExpectedResult = MockAssemblyResult2, + ExpectedResult = new ExpectedResult("Failed") + { + Total = 35, Passed = 21, Failed = 5, Warnings = 1, Inconclusive = 1, Skipped = 7, + Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("mock-assembly.dll") } + } }, new PackageTest(1, "Net70PackageTest") { Description = "Run mock-assembly.dll targeting .NET 7.0", Arguments = "testdata/net7.0/mock-assembly.dll", - ExpectedResult = MockAssemblyResult2, + ExpectedResult = new ExpectedResult("Failed") + { + Total = 35, Passed = 21, Failed = 5, Warnings = 1, Inconclusive = 1, Skipped = 7, + Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("mock-assembly.dll") } + } }, new PackageTest(1, "Net80PackageTest") { Description = "Run mock-assembly.dll targeting .NET 8.0", Arguments = "testdata/net8.0/mock-assembly.dll", - ExpectedResult = MockAssemblyResult2 + ExpectedResult = new ExpectedResult("Failed") + { + Total = 35, Passed = 21, Failed = 5, Warnings = 1, Inconclusive = 1, Skipped = 7, + Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("mock-assembly.dll") } + } }, new PackageTest(1, "AspNetCore80Test") { Description = "Run test using AspNetCore targeting .NET 8.0", Arguments = "testdata/net8.0/aspnetcore-test.dll", - ExpectedResult = AspNetCoreResult + ExpectedResult = new ExpectedResult("Passed") + { + Total = 2, Passed = 2, Failed = 0, Warnings = 0, Inconclusive = 0, Skipped = 0, + Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("aspnetcore-test.dll") } + } }, new PackageTest(1, "Net80WindowsFormsTest") { Description = "Run test using windows forms under .NET 8.0", Arguments = "testdata/net8.0-windows/windows-test.dll", - ExpectedResult = WindowsFormsResult + ExpectedResult = new ExpectedResult("Passed") + { + Total = 2, Passed = 2, Failed = 0, Warnings = 0, Inconclusive = 0, Skipped = 0, + Assemblies = new ExpectedAssemblyResult[] { new ExpectedAssemblyResult("windows-test.dll") } + } } }; diff --git a/net80-pluggable-agent.sln b/net80-pluggable-agent.sln index 552b85a..eb2a0a1 100644 --- a/net80-pluggable-agent.sln +++ b/net80-pluggable-agent.sln @@ -22,7 +22,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{34216BD6-51BE-44BE-9E0D-503ACB44B54C}" ProjectSection(SolutionItems) = preProject - nuget\DotnetToolSettings.xml = nuget\DotnetToolSettings.xml nuget\Net80PluggableAgent.nuspec = nuget\Net80PluggableAgent.nuspec EndProjectSection EndProject diff --git a/src/testdata/mock-assembly/AccessesCurrentTestContextDuringDiscovery.cs b/src/testdata/mock-assembly/AccessesCurrentTestContextDuringDiscovery.cs deleted file mode 100644 index 4427a15..0000000 --- a/src/testdata/mock-assembly/AccessesCurrentTestContextDuringDiscovery.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt - -using NUnit.Framework; - -namespace NUnit.TestData -{ - public class AccessesCurrentTestContextDuringDiscovery - { - public const int Tests = 2; - public const int Suites = 1; - - public static int[] TestCases() - { - var _ = TestContext.CurrentContext; - return new[] { 0 }; - } - - [TestCaseSource(nameof(TestCases))] - public void Access_by_TestCaseSource(int arg) - { - } - - [Test] - public void Access_by_ValueSource([ValueSource(nameof(TestCases))] int arg) - { - } - } -} diff --git a/src/testdata/mock-assembly/MockAssembly.cs b/src/testdata/mock-assembly/MockAssembly.cs index 52bf172..5bd7da9 100644 --- a/src/testdata/mock-assembly/MockAssembly.cs +++ b/src/testdata/mock-assembly/MockAssembly.cs @@ -4,142 +4,26 @@ using NUnit.Framework; using NUnit.Framework.Internal; +/// +/// MockAssembly is intended for those few tests that can only +/// be made to work by loading an entire assembly. Please don't +/// add any other entries or use it for other purposes. +/// namespace NUnit.TestData { namespace Assemblies { - /// - /// MockAssembly is intended for those few tests that can only - /// be made to work by loading an entire assembly. Please don't - /// add any other entries or use it for other purposes. - /// - /// Most tests used as data for NUnit's own tests should be - /// in the testdata assembly. - /// - public class MockAssembly - { - public const int Classes = 9; - public const int NamespaceSuites = 6; // assembly, NUnit, Tests, Assemblies, Singletons, TestAssembly - - public const int Tests = MockTestFixture.Tests - + Singletons.OneTestCase.Tests - + TestAssembly.MockTestFixture.Tests - + IgnoredFixture.Tests - + ExplicitFixture.Tests - + BadFixture.Tests - + FixtureWithTestCases.Tests - + ParameterizedFixture.Tests - + GenericFixtureConstants.Tests - + AccessesCurrentTestContextDuringDiscovery.Tests - + FixtureWithDispose.Tests - + FixtureWithOneTimeTearDown.Tests - + TestSetUpFixture.SetUpFixture.TestsInNamespace; - - public const int Suites = MockTestFixture.Suites - + Singletons.OneTestCase.Suites - + TestAssembly.MockTestFixture.Suites - + IgnoredFixture.Suites - + ExplicitFixture.Suites - + BadFixture.Suites - + FixtureWithTestCases.Suites - + ParameterizedFixture.Suites - + GenericFixtureConstants.Suites - + AccessesCurrentTestContextDuringDiscovery.Suites - + NamespaceSuites - + FixtureWithDispose.Suites - + FixtureWithOneTimeTearDown.Suites; - - public const int TestStartedEvents = Tests - IgnoredFixture.Tests - BadFixture.Tests - ExplicitFixture.Tests; - public const int TestFinishedEvents = Tests; - - public const int TestOutputEvents = 1; - - public const int Nodes = Tests + Suites; - - public const int ExplicitFixtures = 1; - public const int SuitesRun = Suites - ExplicitFixtures; - - public const int Passed = MockTestFixture.Passed - + Singletons.OneTestCase.Tests - + TestAssembly.MockTestFixture.Tests - + FixtureWithTestCases.Tests - + ParameterizedFixture.Tests - + GenericFixtureConstants.Tests - + AccessesCurrentTestContextDuringDiscovery.Tests; - - public const int PassedButFailedInTearDown = FixtureWithDispose.Tests - + FixtureWithOneTimeTearDown.Tests - + TestSetUpFixture.SetUpFixture.TestsInNamespace; - - public const int Passed_Raw = Passed + PassedButFailedInTearDown; - - public const int Ignored = MockTestFixture.Ignored + IgnoredFixture.Tests; - public const int Explicit = MockTestFixture.Explicit + ExplicitFixture.Tests; - public const int Skipped = Ignored + Explicit; - - public const int Failures = MockTestFixture.Failures; - public const int Errors_Raw = MockTestFixture.Errors; - public const int Errors = MockTestFixture.Errors + PassedButFailedInTearDown; - public const int NotRunnable = MockTestFixture.NotRunnable + BadFixture.Tests; - public const int Failed = Failures + Errors + NotRunnable; - public const int Failed_Raw = Failures + Errors_Raw + NotRunnable; - - public const int Warnings = MockTestFixture.Warnings; - - public const int Inconclusive = MockTestFixture.Inconclusive; - - public static readonly string AssemblyPath = AssemblyHelper.GetAssemblyPath(typeof(MockAssembly).Assembly); - - // Method run manually to verify that the counts are set up correctly - public static void DisplayCounts() - { - Console.WriteLine($"Test Count: {Tests}"); - Console.WriteLine($" Passed: {Passed}"); - Console.WriteLine($" Failed: {Failed}"); - Console.WriteLine($" Failures: {Failures}"); - Console.WriteLine($" Errors: {Errors}"); - Console.WriteLine($" Invalid: {NotRunnable}"); - Console.WriteLine($" Warnings: {Warnings}"); - Console.WriteLine($" Skipped: {Skipped}"); - Console.WriteLine($" Explicit: {Explicit}"); - Console.WriteLine($" Ignored: {Ignored}"); - Console.WriteLine($" Inconclusive: {Inconclusive}"); - } - } - [TestFixture(Description="Fake Test Fixture")] [Category("FixtureCategory")] public class MockTestFixture { - public const int Tests = 9; - public const int Suites = 1; - - public const int Passed = 1; - - public const int Ignored = 1; - public const int Explicit = 1; - public const int Skipped = Ignored + Explicit; - - public const int Failures = 1; - public const int Errors = 1; - public const int NotRunnable = 2; - public const int Failed = Errors + Failures + NotRunnable; - - public const int Warnings = 1; - - public const int Inconclusive = 1; - [Test(Description="Mock Test #1")] [Category("MockCategory")] [Property("Severity", "Critical")] - public void TestWithDescription() - { - } + public void TestWithDescription() { } [Test] - protected static void NonPublicTest() - { - } + protected static void NonPublicTest() { } [Test] public void FailingTest() @@ -155,19 +39,13 @@ public void WarningTest() } [Test, Ignore("Ignore Message")] - public void IgnoreTest() - { - } + public void IgnoreTest() { } [Test, Explicit] - public void ExplicitTest() - { - } + public void ExplicitTest() { } [Test] - public void NotRunnableTest(int a, int b) - { - } + public void NotRunnableTest(int a, int b) { } [Test] public void InconclusiveTest() @@ -193,13 +71,8 @@ namespace Singletons [TestFixture] public class OneTestCase { - public const int Tests = 1; - public const int Suites = 1; - [Test] - public virtual void TestCase() - { - } + public virtual void TestCase() { } } } @@ -208,78 +81,46 @@ namespace TestAssembly [TestFixture] public class MockTestFixture { - public const int Tests = 1; - public const int Suites = 1; - [Test] - public void MyTest() - { - } + public void MyTest() { } } } [TestFixture, Ignore("BECAUSE")] public class IgnoredFixture { - public const int Tests = 3; - public const int Suites = 1; - [Test] - public void Test1() - { - } + public void Test1() { } [Test] - public void Test2() - { - } + public void Test2() { } [Test] - public void Test3() - { - } + public void Test3() { } } [TestFixture, Explicit] public class ExplicitFixture { - public const int Tests = 2; - public const int Suites = 1; - public const int Nodes = Tests + Suites; - [Test] - public void Test1() - { - } + public void Test1() { } [Test] - public void Test2() - { - } + public void Test2() { } } [TestFixture] public class BadFixture { - public const int Tests = 1; - public const int Suites = 1; - - public BadFixture(int val) - { - } + public BadFixture(int val) { } [Test] - public void SomeTest() - { - } + public void SomeTest() { } } [TestFixture] public class FixtureWithTestCases { - public const int Tests = 4; - public const int Suites = 3; - [TestCase(2, 2, ExpectedResult=4)] [TestCase(9, 11, ExpectedResult=20)] public int MethodWithParameters(int x, int y) @@ -289,73 +130,43 @@ public int MethodWithParameters(int x, int y) [TestCase(2, 4)] [TestCase(9.2, 11.7)] - public void GenericMethod(T x, T y) - { - } + public void GenericMethod(T x, T y) { } } [TestFixture(5)] [TestFixture(42)] public class ParameterizedFixture { - public const int Tests = 4; - public const int Suites = 3; - - public ParameterizedFixture(int num) - { - } + public ParameterizedFixture(int num) { } [Test] - public void Test1() - { - } + public void Test1() { } [Test] - public void Test2() - { - } - } - - public class GenericFixtureConstants - { - public const int Tests = 4; - public const int Suites = 3; + public void Test2() { } } [TestFixture(5)] [TestFixture(11.5)] public class GenericFixture { - public GenericFixture(T num) - { - } + public GenericFixture(T num) { } [Test] - public void Test1() - { - } + public void Test1() { } [Test] - public void Test2() - { - } + public void Test2() { } } [TestFixture] public class FixtureWithDispose : IDisposable { - public const int Suites = 1; - public const int Tests = 2; - [Test] - public void Test1() - { - } + public void Test1() { } [Test] - public void Test2() - { - } + public void Test2() { } #pragma warning disable CA1816 public void Dispose() @@ -368,18 +179,11 @@ public void Dispose() [TestFixture] public class FixtureWithOneTimeTearDown { - public const int Suites = 1; - public const int Tests = 2; - [Test] - public void Test1() - { - } + public void Test1() { } [Test] - public void Test2() - { - } + public void Test2() { } [OneTimeTearDown] public void OneTimeTearDown() @@ -393,9 +197,6 @@ namespace TestSetUpFixture [SetUpFixture] public class SetUpFixture { - public const int SuitesInNamespace = 2; - public const int TestsInNamespace = 2; - [OneTimeTearDown] public void OneTimeTearDown() { @@ -407,18 +208,14 @@ public void OneTimeTearDown() public class Fixture1 { [Test] - public void Test1() - { - } + public void Test1() { } } [TestFixture] public class Fixture2 { [Test] - public void Test1() - { - } + public void Test1() { } } } } diff --git a/src/tests/Program.cs b/src/tests/Program.cs index 8faaee1..1663b2b 100644 --- a/src/tests/Program.cs +++ b/src/tests/Program.cs @@ -1,9 +1,8 @@ // Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt -using System.Reflection; using NUnitLite; -namespace TestCentric.Engine +namespace NUnit.Engine.Agents { class Program { diff --git a/src/tests/nunit-agent-launcher-net80.tests.csproj b/src/tests/nunit-agent-launcher-net80.tests.csproj index 242a2ab..1d2007e 100644 --- a/src/tests/nunit-agent-launcher-net80.tests.csproj +++ b/src/tests/nunit-agent-launcher-net80.tests.csproj @@ -23,7 +23,7 @@ - +