From 131ce0c3ec95bdbc115c483bba0eda3efc9273db Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Tue, 27 Dec 2022 19:37:03 -0800 Subject: [PATCH] Restore ability to debug packages --- build.cake | 74 ++++++------ cake/build-settings.cake | 207 ++++++++++++++++++++++++++++++++-- cake/constants.cake | 28 ++--- cake/package-definitions.cake | 27 ++++- cake/package-tests.cake | 172 ---------------------------- cake/packages.cake | 57 +++++----- cake/utilities.cake | 52 +++------ 7 files changed, 311 insertions(+), 306 deletions(-) diff --git a/build.cake b/build.cake index 5a731158f..e1992c37e 100644 --- a/build.cake +++ b/build.cake @@ -1,6 +1,4 @@ -static string Target; Target = GetArgument("target|t", "Default"); -static string Configuration; Configuration = GetArgument("configuration|c", "Release"); -static bool NoPush; NoPush = HasArgument("nopush"); +static string Target; Target = Argument("target", Argument("t", "Default")); #load cake/constants.cake #load cake/build-settings.cake @@ -30,10 +28,6 @@ Setup(context => Information($"Building {settings.Configuration} version {settings.ProductVersion} of NUnit Console/Engine."); Information($"PreReleaseLabel is {settings.PreReleaseLabel}"); - // TODO: Hide this in a lower-level file - if (IsRunningOnWindows()) - StandardRunnerTests.Add(Net60WindowsFormsTest); - if (BuildSystem.IsRunningOnAppVeyor) AppVeyor.UpdateBuildVersion(settings.ProductVersion + "-" + AppVeyor.Environment.Build.Number); @@ -145,9 +139,9 @@ Task("TestNet20EngineCore") .Description("Tests the engine core assembly") .IsDependentOn("Build") .OnError(exception => { UnreportedErrors.Add(exception.Message); }) - .Does(() => + .Does(settings => { - RunNUnitLiteTests(ENGINE_CORE_TESTS_PROJECT, "net35"); + RunNUnitLiteTests(ENGINE_CORE_TESTS_PROJECT, settings.Configuration, "net35"); }); ////////////////////////////////////////////////////////////////////// @@ -158,9 +152,9 @@ Task("TestNetStandard20EngineCore") .Description("Tests the .NET Standard Engine core assembly") .IsDependentOn("Build") .OnError(exception => { UnreportedErrors.Add(exception.Message); }) - .Does(() => + .Does(settings => { - RunDotnetNUnitLiteTests(ENGINE_CORE_TESTS_PROJECT, "netcoreapp2.1"); + RunDotnetNUnitLiteTests(ENGINE_CORE_TESTS_PROJECT, settings.Configuration, "netcoreapp2.1"); }); ////////////////////////////////////////////////////////////////////// @@ -171,9 +165,9 @@ Task("TestNetCore31EngineCore") .Description("Tests the .NET Core 3.1 Engine core assembly") .IsDependentOn("Build") .OnError(exception => { UnreportedErrors.Add(exception.Message); }) - .Does(() => + .Does(settings => { - RunDotnetNUnitLiteTests(ENGINE_CORE_TESTS_PROJECT, "netcoreapp3.1"); + RunDotnetNUnitLiteTests(ENGINE_CORE_TESTS_PROJECT, settings.Configuration, "netcoreapp3.1"); }); ////////////////////////////////////////////////////////////////////// @@ -184,9 +178,9 @@ Task("TestNetFxEngine") .Description("Tests the .NET Framework build of the engine") .IsDependentOn("Build") .OnError(exception => { UnreportedErrors.Add(exception.Message); }) - .Does(() => + .Does(settings => { - RunNUnitLiteTests(ENGINE_TESTS_PROJECT, "NET462"); + RunNUnitLiteTests(ENGINE_TESTS_PROJECT, settings.Configuration, "NET462"); }); ////////////////////////////////////////////////////////////////////// @@ -197,9 +191,9 @@ Task("TestNetStandard20Engine") .Description("Tests the .NET Standard Engine") .IsDependentOn("Build") .OnError(exception => { UnreportedErrors.Add(exception.Message); }) - .Does(() => + .Does(settings => { - RunDotnetNUnitLiteTests(ENGINE_TESTS_PROJECT, "netcoreapp2.1"); + RunDotnetNUnitLiteTests(ENGINE_TESTS_PROJECT, settings.Configuration, "netcoreapp2.1"); }); ////////////////////////////////////////////////////////////////////// @@ -210,9 +204,9 @@ Task("TestNetCore31Engine") .Description("Tests the .NET Core 3.1 Engine") .IsDependentOn("Build") .OnError(exception => { UnreportedErrors.Add(exception.Message); }) - .Does(() => + .Does(settings => { - RunDotnetNUnitLiteTests(ENGINE_TESTS_PROJECT, "netcoreapp3.1"); + RunDotnetNUnitLiteTests(ENGINE_TESTS_PROJECT, settings.Configuration, "netcoreapp3.1"); }); ////////////////////////////////////////////////////////////////////// @@ -223,9 +217,9 @@ Task("TestNetFxConsole") .Description("Tests the .NET 4.6.2 console runner") .IsDependentOn("Build") .OnError(exception => { UnreportedErrors.Add(exception.Message); }) - .Does(() => + .Does(settings => { - RunNetFxConsole(CONSOLE_TESTS_PROJECT, NETFX_CONSOLE_TARGET); + RunNetFxConsole(CONSOLE_TESTS_PROJECT, settings.Configuration, NETFX_CONSOLE_TARGET); }); ////////////////////////////////////////////////////////////////////// @@ -236,9 +230,9 @@ Task("TestNetCoreConsole") .Description("Tests the .NET 6.0 console runner") .IsDependentOn("Build") .OnError(exception => { UnreportedErrors.Add(exception.Message); }) - .Does(() => + .Does(settings => { - RunNetCoreConsole(CONSOLE_TESTS_PROJECT, NETCORE_CONSOLE_TARGET); + RunNetCoreConsole(CONSOLE_TESTS_PROJECT, settings.Configuration, NETCORE_CONSOLE_TARGET); }); ////////////////////////////////////////////////////////////////////// @@ -277,7 +271,7 @@ Task("CreateZipImage") CopyFiles( new FilePath[] { "LICENSE.txt", "NOTICES.txt", "CHANGES.txt", "nunit.ico" }, zipImageDirectory); - CopyDirectory(NETFX_CONSOLE_DIR, zipImageDirectory + "bin/"); + CopyDirectory(settings.NetFxConsoleBinDir, zipImageDirectory + "bin/"); CopyFileToDirectory(PROJECT_DIR + "zip/nunit.bundle.addins", zipImageDirectory + "bin/"); // Currently, only the .NET Framework runner accepts extensions @@ -456,17 +450,17 @@ Task("PublishToMyGet") { if (!settings.ShouldPublishToMyGet) Information("Nothing to publish to MyGet from this run."); + else if (settings.NoPush) + Information("NoPush option suppressing publication to MyGet"); else { - var apiKey = EnvironmentVariable(MYGET_API_KEY); - foreach (var package in settings.AllPackages) try { if (package is NuGetPackageDefinition) - PushNuGetPackage(package.PackageFilePath, apiKey, MYGET_PUSH_URL); + PushNuGetPackage(package.PackageFilePath, settings.MyGetApiKey, MYGET_PUSH_URL); else if (package is ChocolateyPackageDefinition) - PushChocolateyPackage(package.PackageFilePath, apiKey, MYGET_PUSH_URL); + PushChocolateyPackage(package.PackageFilePath, settings.MyGetApiKey, MYGET_PUSH_URL); } catch(Exception) { @@ -483,15 +477,15 @@ Task("PublishToNuGet") { if (!settings.ShouldPublishToNuGet) Information("Nothing to publish to NuGet from this run."); + else if (settings.NoPush) + Information("NoPush option suppressing publication to NuGet"); else { - var apiKey = EnvironmentVariable(NUGET_API_KEY); - foreach (var package in settings.AllPackages) if (package is NuGetPackageDefinition) try { - PushNuGetPackage(package.PackageFilePath, apiKey, NUGET_PUSH_URL); + PushNuGetPackage(package.PackageFilePath, settings.NuGetApiKey, NUGET_PUSH_URL); } catch (Exception) { @@ -508,15 +502,15 @@ Task("PublishToChocolatey") { if (!settings.ShouldPublishToChocolatey) Information("Nothing to publish to Chocolatey from this run."); + else if (settings.NoPush) + Information("NoPush option suppressing publication to Chocolatey"); else { - var apiKey = EnvironmentVariable(CHOCO_API_KEY); - foreach (var package in settings.AllPackages) if (package is ChocolateyPackageDefinition) try { - PushChocolateyPackage(package.PackageFilePath, apiKey, CHOCO_PUSH_URL); + PushChocolateyPackage(package.PackageFilePath, settings.ChocolateyApiKey, CHOCO_PUSH_URL); } catch (Exception) { @@ -556,10 +550,12 @@ Task("CreateDraftRelease") Information($"Creating draft release for {releaseName}"); - if (!NoPush) + if (settings.NoPush) + Information("NoPush option suppressed creation of draft release"); + else try { - GitReleaseManagerCreate(EnvironmentVariable(GITHUB_ACCESS_TOKEN), GITHUB_OWNER, GITHUB_REPO, new GitReleaseManagerCreateSettings() + GitReleaseManagerCreate(settings.GitHubAccessToken, GITHUB_OWNER, GITHUB_REPO, new GitReleaseManagerCreateSettings() { Name = releaseName, Milestone = milestone @@ -588,7 +584,7 @@ Task("CreateProductionRelease") { if (settings.IsProductionRelease) { - string token = EnvironmentVariable(GITHUB_ACCESS_TOKEN); + string token = settings.GitHubAccessToken; string tagName = settings.ProductVersion; var assetList = new List(); @@ -598,9 +594,9 @@ Task("CreateProductionRelease") Information($"Publishing release {tagName} to GitHub"); - if (NoPush) + if (settings.NoPush) { - Information($"Assets:"); + Information("NoPush option suppressed publishing of assets:"); foreach (var asset in assetList) Information(" " + asset); } diff --git a/cake/build-settings.cake b/cake/build-settings.cake index af53006fc..db58bb3d3 100644 --- a/cake/build-settings.cake +++ b/cake/build-settings.cake @@ -14,19 +14,129 @@ public class BuildSettings Target = context.TargetTask.Name; TasksToExecute = context.TasksToExecute.Select(t => t.Name); - Configuration = context.Argument("configuration", "Release"); + Configuration = context.Argument("configuration", context.Argument("c", "Release")); + NoPush = context.HasArgument("nopush"); BuildVersion = new BuildVersion(context); + Net35Test = new PackageTest( + "Net35Test", + "Run mock-assembly.dll under .NET 3.5", + $"src/NUnitEngine/mock-assembly/bin/{Configuration}/net35/mock-assembly.dll", + MockAssemblyExpectedResult(1)); + Net40Test = new PackageTest( + "Net40Test", + "Run mock-assembly.dll under .NET 4.x", + $"src/NUnitEngine/mock-assembly/bin/{Configuration}/net462/mock-assembly.dll", + MockAssemblyExpectedResult(1)); + NetCore21Test = new PackageTest( + "NetCore21Test", + "Run mock-assembly.dll targeting .NET Core 2.1", + $"src/NUnitEngine/mock-assembly/bin/{Configuration}/netcoreapp2.1/mock-assembly.dll", + MockAssemblyExpectedResult(1)); + NetCore31Test = new PackageTest( + "NetCore31Test", + "Run mock-assembly.dll under .NET Core 3.1", + $"src/NUnitEngine/mock-assembly/bin/{Configuration}/netcoreapp3.1/mock-assembly.dll", + MockAssemblyExpectedResult(1)); + Net50Test = new PackageTest( + "Net50Test", + "Run mock-assembly.dll under .NET 5.0", + $"src/NUnitEngine/mock-assembly/bin/{Configuration}/net5.0/mock-assembly.dll", + MockAssemblyExpectedResult(1)); + Net60Test = new PackageTest( + "Net60Test", + "Run mock-assembly.dll under .NET 6.0", + $"src/NUnitEngine/mock-assembly/bin/{Configuration}/net6.0/mock-assembly.dll", + MockAssemblyExpectedResult(1)); + Net70Test = new PackageTest( + "Net70Test", + "Run mock-assembly.dll under .NET 7.0", + $"src/NUnitEngine/mock-assembly/bin/{Configuration}/net7.0/mock-assembly.dll", + MockAssemblyExpectedResult(1)); + Net35X86Test = new PackageTest( + "Net35X86Test", + "Run mock-assembly-x86.dll under .NET 3.5", + $"src/NUnitEngine/mock-assembly-x86/bin/{Configuration}/net35/mock-assembly-x86.dll", + MockAssemblyExpectedResult(1)); + Net40X86Test = new PackageTest( + "Net40X86Test", + "Run mock-assembly-x86.dll under .NET 4.x", + $"src/NUnitEngine/mock-assembly-x86/bin/{Configuration}/net462/mock-assembly-x86.dll", + MockAssemblyExpectedResult(1)); + NetCore31X86Test = new PackageTest( + "NetCore31X86Test", + "Run mock-assembly-x86.dll under .NET Core 3.1", + $"src/NUnitEngine/mock-assembly-x86/bin/{Configuration}/netcoreapp3.1/mock-assembly-x86.dll", + MockAssemblyExpectedResult(1)); + Net60WindowsFormsTest = new PackageTest( + "Net60WindowsFormsTest", + "Run test using windows forms under .NET 6.0", + $"src/NUnitEngine/windows-test/bin/{Configuration}/net6.0-windows/windows-test.dll", + new ExpectedResult("Passed")); + Net60AspNetCoreTest = new PackageTest( + "Net60AspNetCoreTest", + "Run test using AspNetCore under .NET 6.0", + $"src/NUnitEngine/aspnetcore-test/bin/{Configuration}/net6.0/aspnetcore-test.dll", + new ExpectedResult("Passed")); + Net35PlusNet40Test = new PackageTest( + "Net35PlusNet40Test", + "Run both copies of mock-assembly together", + $"src/NUnitEngine/mock-assembly/bin/{Configuration}/net35/mock-assembly.dll src/NUnitEngine/mock-assembly/bin/{Configuration}/net462/mock-assembly.dll", + MockAssemblyExpectedResult(2)); + Net40PlusNet60Test = new PackageTest( + "Net40PlusNet60Test", + "Run mock-assembly under .Net Framework 4.0 and .Net 6.0 together", + $"src/NUnitEngine/mock-assembly/bin/{Configuration}/net462/mock-assembly.dll src/NUnitEngine/mock-assembly/bin/{Configuration}/net6.0/mock-assembly.dll", + MockAssemblyExpectedResult(2)); + Net50PlusNet60Test = new PackageTest( + "Net50PlusNet60Test", + "Run mock-assembly under .Net 5.0 and .Net 6.0 together", + $"src/NUnitEngine/mock-assembly/bin/{Configuration}/net5.0/mock-assembly.dll src/NUnitEngine/mock-assembly/bin/{Configuration}/net6.0/mock-assembly.dll", + MockAssemblyExpectedResult(2)); + NUnitProjectTest = new PackageTest( + "NUnitProjectTest", + "Run project with both copies of mock-assembly", + $"NetFXTests.nunit --config={Configuration}", + MockAssemblyExpectedResult(2)); + + StandardRunnerTests = new List + { + Net35Test, + Net40Test, + NetCore21Test, + NetCore31Test, + Net50Test, + Net60Test, + Net70Test, + Net35PlusNet40Test, + Net40PlusNet60Test, + Net50PlusNet60Test, + Net35X86Test, + Net40X86Test, + Net60AspNetCoreTest + }; + if (IsRunningOnWindows) + StandardRunnerTests.Add(Net60WindowsFormsTest); + + NetCoreRunnerTests = new List + { + NetCore21Test, + NetCore31Test, + Net50Test, + Net60Test, + Net50PlusNet60Test, + Net60AspNetCoreTest + }; AllPackages = new PackageDefinition[] { - ConsoleNuGetPackage = new NUnitConsoleNuGetPackage(context, ProductVersion), - ConsoleRunnerNuGetPackage = new NUnitConsoleRunnerNuGetPackage(context, ProductVersion), - DotNetConsoleRunnerNuGetPackage = new NUnitNetCoreConsoleRunnerPackage(context, ProductVersion), - ConsoleRunnerChocolateyPackage = new NUnitConsoleRunnerChocolateyPackage(context, ProductVersion), - ConsoleMsiPackage = new NUnitConsoleMsiPackage(context, SemVer), - ConsoleZipPackage = new NUnitConsoleZipPackage(context, ProductVersion), - EngineNuGetPackage = new NUnitEngineNuGetPackage(context, ProductVersion), - EngineApiNuGetPackage = new NUnitEngineApiNuGetPackage(context, ProductVersion) + ConsoleNuGetPackage = new NUnitConsoleNuGetPackage(this), + ConsoleRunnerNuGetPackage = new NUnitConsoleRunnerNuGetPackage(this), + DotNetConsoleRunnerNuGetPackage = new NUnitNetCoreConsoleRunnerPackage(this), + ConsoleRunnerChocolateyPackage = new NUnitConsoleRunnerChocolateyPackage(this), + ConsoleMsiPackage = new NUnitConsoleMsiPackage(this), + ConsoleZipPackage = new NUnitConsoleZipPackage(this), + EngineNuGetPackage = new NUnitEngineNuGetPackage(this), + EngineApiNuGetPackage = new NUnitEngineApiNuGetPackage(this) }; } @@ -37,6 +147,9 @@ public class BuildSettings public string Configuration { get; } + public string NetFxConsoleBinDir => NETFX_CONSOLE_DIR + $"bin/{Configuration}/{NETFX_CONSOLE_TARGET}/"; + public string NetCoreConsoleBinDir => NETCORE_CONSOLE_DIR + $"bin/{Configuration}/{NETCORE_CONSOLE_TARGET}"; + public BuildVersion BuildVersion { get; } public string SemVer => BuildVersion.SemVer; public string ProductVersion => BuildVersion.ProductVersion; @@ -59,6 +172,59 @@ public class BuildSettings public bool ShouldPublishToChocolatey => !IsPreRelease || LABELS_WE_PUBLISH_ON_CHOCOLATEY.Contains(PreReleaseLabel); public bool IsProductionRelease => !IsPreRelease || LABELS_WE_RELEASE_ON_GITHUB.Contains(PreReleaseLabel); + public string MyGetApiKey => _context.EnvironmentVariable(MYGET_API_KEY); + public string NuGetApiKey => _context.EnvironmentVariable(NUGET_API_KEY); + public string ChocolateyApiKey => _context.EnvironmentVariable(CHOCO_API_KEY); + + public string GitHubAccessToken => _context.EnvironmentVariable(GITHUB_ACCESS_TOKEN); + + public bool NoPush { get; } + +////////////////////////////////////////////////////////////////////// +// 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 + }; + + //Single Assembly Tests using each agent + public PackageTest Net35Test { get; } + public PackageTest Net40Test { get; } + public PackageTest NetCore21Test { get; } + public PackageTest NetCore31Test { get; } + public PackageTest Net50Test { get; } + public PackageTest Net60Test { get; } + public PackageTest Net70Test { get; } + // X86 Tests + public PackageTest Net35X86Test { get; } + public PackageTest Net40X86Test { get; } + public PackageTest NetCore31X86Test { get; } + // Special Test Situations + public PackageTest Net60WindowsFormsTest { get; } + public PackageTest Net60AspNetCoreTest { get; } + // Multiple Assemblies + public PackageTest Net35PlusNet40Test { get; } + public PackageTest Net40PlusNet60Test { get; } + public PackageTest Net50PlusNet60Test { get; } + // NUnit Project + public PackageTest NUnitProjectTest { get; } + + // Tests run for all runner packages except NETCORE runner + public List StandardRunnerTests { get; } + // Tests run for the NETCORE runner package + public List NetCoreRunnerTests { get; } + +////////////////////////////////////////////////////////////////////// +// PACKAGE DEFINITIONS +////////////////////////////////////////////////////////////////////// + public PackageDefinition[] AllPackages { get; } public PackageDefinition ConsoleNuGetPackage; @@ -96,6 +262,19 @@ public class BuildSettings Console.WriteLine("BranchName: " + BranchName); Console.WriteLine("IsReleaseBranch: " + IsReleaseBranch); + Console.WriteLine("\nPUBLISHING"); + Console.WriteLine("MyGet Push URL: " + MYGET_PUSH_URL); + ShowApiKeyAvailability(MyGetApiKey); + Console.WriteLine("NuGet Push URL: " + NUGET_PUSH_URL); + ShowApiKeyAvailability(NuGetApiKey); + Console.WriteLine("Chocolatey Push URL: " + CHOCO_PUSH_URL); + ShowApiKeyAvailability(ChocolateyApiKey); + + if (string.IsNullOrEmpty(GitHubAccessToken)) + Console.WriteLine("GitHubAccessToken: NOT Available"); + else + Console.WriteLine("GitHubAccessToken: Available"); + Console.WriteLine("\nDIRECTORIES"); Console.WriteLine($"Project: {PROJECT_DIR}"); Console.WriteLine($"Package: {PACKAGE_DIR}"); @@ -106,8 +285,14 @@ public class BuildSettings Console.WriteLine("Solution and Projects"); Console.WriteLine($" Solution: {SOLUTION_FILE}"); Console.WriteLine($" NetFx Runner: {NETFX_CONSOLE_PROJECT}"); - Console.WriteLine($" Bin Dir: {NETFX_CONSOLE_PROJECT_BIN_DIR}"); Console.WriteLine($" NetCore Runner: {NETCORE_CONSOLE_PROJECT}"); - Console.WriteLine($" Bin Dir: {NETCORE_CONSOLE_PROJECT_BIN_DIR}"); + } + + private void ShowApiKeyAvailability(string apikey) + { + if (string.IsNullOrEmpty(apikey)) + Console.WriteLine(" API Key: NOT Available"); + else + Console.WriteLine(" API Key: Available"); } } diff --git a/cake/constants.cake b/cake/constants.cake index 23108109f..5fb98e041 100644 --- a/cake/constants.cake +++ b/cake/constants.cake @@ -16,6 +16,10 @@ string CombinePaths(string path1, string path2) // Useful Constants static readonly char SEPARATOR = System.IO.Path.DirectorySeparatorChar; +// We build two console runners. If version of either is upgraded, change it here +const string NETFX_CONSOLE_TARGET = "net462"; +const string NETCORE_CONSOLE_TARGET = "net6.0"; + // Directories // NOTE: All paths use '/' as a separator because some usage requires it and // most usage allows it. In a few cases, like installing an msi, we adjust the @@ -31,14 +35,17 @@ static string SOLUTION_FILE; SOLUTION_FILE = IsRunningOnWindows() ? PROJECT_DIR + "NUnitConsole.sln" : PROJECT_DIR + "NUnitConsole_Linux.sln"; -static string NETFX_CONSOLE_PROJECT; NETFX_CONSOLE_PROJECT = PROJECT_DIR + "src/NUnitConsole/nunit3-console/nunit3-console.csproj"; -static string NETCORE_CONSOLE_PROJECT; NETCORE_CONSOLE_PROJECT = PROJECT_DIR + "src/NUnitConsole/nunit3-netcore-console/nunit3-netcore-console.csproj"; +static string NETFX_CONSOLE_DIR; NETFX_CONSOLE_DIR = PROJECT_DIR + "src/NUnitConsole/nunit3-console/"; +static string NETFX_CONSOLE_PROJECT; NETFX_CONSOLE_PROJECT = NETFX_CONSOLE_DIR + "nunit3-console.csproj"; +static string NETCORE_CONSOLE_DIR; NETCORE_CONSOLE_DIR = PROJECT_DIR + "src/NUnitConsole/nunit3-netcore-console/"; +static string NETCORE_CONSOLE_PROJECT; NETCORE_CONSOLE_PROJECT = NETCORE_CONSOLE_DIR + "nunit3-netcore-console.csproj"; +static string CONSOLE_TESTS_PROJECT; CONSOLE_TESTS_PROJECT = PROJECT_DIR + "src/NUnitConsole/nunit3-console.tests/nunit3-console.tests.csproj"; + static string ENGINE_PROJECT; ENGINE_PROJECT = PROJECT_DIR + "src/NUnitEngine/nunit.engine/nunit.engine.csproj"; static string ENGINE_CORE_PROJECT; ENGINE_CORE_PROJECT = PROJECT_DIR + "src/NUnitEngine/nunit.engine.core/nunit.engine.core.csproj"; static string ENGINE_API_PROJECT; ENGINE_API_PROJECT = PROJECT_DIR + "src/NUnitEngine/nunit.engine.api/nunit.engine.api.csproj"; static string AGENT_PROJECT; AGENT_PROJECT = PROJECT_DIR + "src/NUnitEngine/nunit-agent/nunit-agent.csproj"; static string AGENT_X86_PROJECT; AGENT_X86_PROJECT = PROJECT_DIR + "src/NUnitEngine/nunit-agent-x86/nunit-agent-x86.csproj"; -static string CONSOLE_TESTS_PROJECT; CONSOLE_TESTS_PROJECT = PROJECT_DIR + "src/NUnitConsole/nunit3-console.tests/nunit3-console.tests.csproj"; static string ENGINE_TESTS_PROJECT; ENGINE_TESTS_PROJECT = PROJECT_DIR + "src/NUnitEngine/nunit.engine.tests/nunit.engine.tests.csproj"; static string ENGINE_CORE_TESTS_PROJECT; ENGINE_CORE_TESTS_PROJECT = PROJECT_DIR + "src/NUnitEngine/nunit.engine.core.tests/nunit.engine.core.tests.csproj"; static string MOCK_ASSEMBLY_PROJECT; MOCK_ASSEMBLY_PROJECT = PROJECT_DIR + "src/NUnitEngine/mock-assembly/mock-assembly.csproj"; @@ -47,21 +54,6 @@ static string NOTEST_PROJECT; NOTEST_PROJECT = PROJECT_DIR + "src/NUnitEngine/no static string WINDOWS_TEST_PROJECT; WINDOWS_TEST_PROJECT = PROJECT_DIR + "src/NUnitEngine/windows-test/windows-test.csproj"; static string ASPNETCORE_TEST_PROJECT; ASPNETCORE_TEST_PROJECT = PROJECT_DIR + "src/NUnitEngine/aspnetcore-test/aspnetcore-test.csproj"; -// Bin directories for selected projects -static string NETFX_CONSOLE_PROJECT_BIN_DIR; NETFX_CONSOLE_PROJECT_BIN_DIR = PROJECT_DIR + $"src/NUnitConsole/nunit3-console/bin/{Configuration}/"; -static string NETCORE_CONSOLE_PROJECT_BIN_DIR; NETCORE_CONSOLE_PROJECT_BIN_DIR = PROJECT_DIR + $"src/NUnitConsole/nunit3-netcore-console/bin/{Configuration}/"; -static string ENGINE_PROJECT_BIN_DIR; ENGINE_PROJECT_BIN_DIR = PROJECT_DIR + $"src/NUnitEngine/nunit.engine/bin/{Configuration}/"; -static string ENGINE_API_PROJECT_BIN_DIR; ENGINE_API_PROJECT_BIN_DIR = PROJECT_DIR + $"src/NUnitEngine/nunit.engine.api/bin/{Configuration}/"; - -// Console Runner -// We build two console runners. If version of either is upgraded, change it here -const string NETFX_CONSOLE_TARGET = "net462"; -const string NETCORE_CONSOLE_TARGET = "net6.0"; -static string NETFX_CONSOLE_DIR; NETFX_CONSOLE_DIR = $"{NETFX_CONSOLE_PROJECT_BIN_DIR}{NETFX_CONSOLE_TARGET}/"; -static string NETFX_CONSOLE; NETFX_CONSOLE = NETFX_CONSOLE_DIR + "nunit3-console.exe"; -static string NETCORE_CONSOLE_DIR; NETCORE_CONSOLE_DIR = $"{NETCORE_CONSOLE_PROJECT_BIN_DIR}{NETCORE_CONSOLE_TARGET}/"; -static string NETCORE_CONSOLE; NETCORE_CONSOLE = NETCORE_CONSOLE_DIR + "nunit3-netcore-console.dll"; - // Package sources for nuget restore var PACKAGE_SOURCE = new string[] { diff --git a/cake/package-definitions.cake b/cake/package-definitions.cake index a9dc9fa9d..04f40bd42 100644 --- a/cake/package-definitions.cake +++ b/cake/package-definitions.cake @@ -1,4 +1,23 @@ ////////////////////////////////////////////////////////////////////// +/// Representation of a single test to be run against a pre-built package. +////////////////////////////////////////////////////////////////////// + +public struct PackageTest +{ + public string Name; + public string Description; + public string Arguments; + public ExpectedResult ExpectedResult; + + public PackageTest(string name, string description, string arguments, ExpectedResult expectedResult) + { + Name = name; + Description = description; + Arguments = arguments; + ExpectedResult = expectedResult; + } +} +////////////////////////////////////////////////////////////////////// // PACKAGE DEFINITION ABSTRACT CLASS ////////////////////////////////////////////////////////////////////// @@ -7,15 +26,17 @@ /// public abstract class PackageDefinition { + protected BuildSettings _settings; protected ICakeContext _context; /// /// Construct without arguments - derived class must set properties /// - protected PackageDefinition(ICakeContext context, string packageVersion) + protected PackageDefinition(BuildSettings settings) { - _context = context; - PackageVersion = packageVersion; + _settings = settings; + _context = settings.Context; + PackageVersion = settings.ProductVersion; } public string PackageId { get; protected set; } diff --git a/cake/package-tests.cake b/cake/package-tests.cake index 252a0ad02..8b1378917 100644 --- a/cake/package-tests.cake +++ b/cake/package-tests.cake @@ -1,173 +1 @@ -////////////////////////////////////////////////////////////////////// -/// Representation of a single test to be run against a pre-built package. -////////////////////////////////////////////////////////////////////// -public struct PackageTest -{ - public string Name; - public string Description; - public string Arguments; - public ExpectedResult ExpectedResult; - - public PackageTest(string name, string description, string arguments, ExpectedResult expectedResult) - { - Name = name; - Description = description; - Arguments = arguments; - ExpectedResult = expectedResult; - } -} - -////////////////////////////////////////////////////////////////////// -// 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 -}; - -//Single Assembly Tests using each agent - -static PackageTest Net35Test = new PackageTest( - "Net35Test", - "Run mock-assembly.dll under .NET 3.5", - "src/NUnitEngine/mock-assembly/bin/Release/net35/mock-assembly.dll", - MockAssemblyExpectedResult(1)); - -static PackageTest Net40Test = new PackageTest( - "Net40Test", - "Run mock-assembly.dll under .NET 4.x", - "src/NUnitEngine/mock-assembly/bin/Release/net462/mock-assembly.dll", - MockAssemblyExpectedResult(1)); - -static PackageTest NetCore21Test = new PackageTest( - "NetCore21Test", - "Run mock-assembly.dll targeting .NET Core 2.1", - "src/NUnitEngine/mock-assembly/bin/Release/netcoreapp2.1/mock-assembly.dll", - MockAssemblyExpectedResult(1)); - -static PackageTest NetCore31Test = new PackageTest( - "NetCore31Test", - "Run mock-assembly.dll under .NET Core 3.1", - "src/NUnitEngine/mock-assembly/bin/Release/netcoreapp3.1/mock-assembly.dll", - MockAssemblyExpectedResult(1)); - -static PackageTest Net50Test = new PackageTest( - "Net50Test", - "Run mock-assembly.dll under .NET 5.0", - "src/NUnitEngine/mock-assembly/bin/Release/net5.0/mock-assembly.dll", - MockAssemblyExpectedResult(1)); - -static PackageTest Net60Test = new PackageTest( - "Net60Test", - "Run mock-assembly.dll under .NET 6.0", - "src/NUnitEngine/mock-assembly/bin/Release/net6.0/mock-assembly.dll", - MockAssemblyExpectedResult(1)); - -static PackageTest Net70Test = new PackageTest( - "Net70Test", - "Run mock-assembly.dll under .NET 7.0", - "src/NUnitEngine/mock-assembly/bin/Release/net7.0/mock-assembly.dll", - MockAssemblyExpectedResult(1)); - -// X86 Tests - -static PackageTest Net35X86Test = new PackageTest( - "Net35X86Test", - "Run mock-assembly-x86.dll under .NET 3.5", - "src/NUnitEngine/mock-assembly-x86/bin/Release/net35/mock-assembly-x86.dll", - MockAssemblyExpectedResult(1)); - -static PackageTest Net40X86Test = new PackageTest( - "Net40X86Test", - "Run mock-assembly-x86.dll under .NET 4.x", - "src/NUnitEngine/mock-assembly-x86/bin/Release/net462/mock-assembly-x86.dll", - MockAssemblyExpectedResult(1)); - -static PackageTest NetCore31X86Test = new PackageTest( - "NetCore31X86Test", - "Run mock-assembly-x86.dll under .NET Core 3.1", - "src/NUnitEngine/mock-assembly-x86/bin/Release/netcoreapp3.1/mock-assembly-x86.dll", - MockAssemblyExpectedResult(1)); - -// Special Test Situations - -static PackageTest Net60WindowsFormsTest = new PackageTest( - "Net60WindowsFormsTest", - "Run test using windows forms under .NET 6.0", - "src/NUnitEngine/windows-test/bin/Release/net6.0-windows/windows-test.dll", - new ExpectedResult("Passed")); - -static PackageTest Net60AspNetCoreTest = new PackageTest( - "Net60AspNetCoreTest", - "Run test using AspNetCore under .NET 6.0", - "src/NUnitEngine/aspnetcore-test/bin/Release/net6.0/aspnetcore-test.dll", - new ExpectedResult("Passed")); - -// Multiple Assemblies - -static PackageTest Net35PlusNet40Test = new PackageTest( - "Net35PlusNet40Test", - "Run both copies of mock-assembly together", - "src/NUnitEngine/mock-assembly/bin/Release/net35/mock-assembly.dll src/NUnitEngine/mock-assembly/bin/Release/net462/mock-assembly.dll", - MockAssemblyExpectedResult(2)); - -static PackageTest Net40PlusNet60Test = new PackageTest( - "Net40PlusNet60Test", - "Run mock-assembly under .Net Framework 4.0 and .Net 6.0 together", - "src/NUnitEngine/mock-assembly/bin/Release/net462/mock-assembly.dll src/NUnitEngine/mock-assembly/bin/Release/net6.0/mock-assembly.dll", - MockAssemblyExpectedResult(2)); - -static PackageTest Net50PlusNet60Test = new PackageTest( - "Net50PlusNet60Test", - "Run mock-assembly under .Net 5.0 and .Net 6.0 together", - "src/NUnitEngine/mock-assembly/bin/Release/net5.0/mock-assembly.dll src/NUnitEngine/mock-assembly/bin/Release/net6.0/mock-assembly.dll", - MockAssemblyExpectedResult(2)); - -// NUnit Project - -static PackageTest NUnitProjectTest; -NUnitProjectTest = new PackageTest( - "NUnitProjectTest", - "Run project with both copies of mock-assembly", - $"NetFXTests.nunit --config={Configuration}", - MockAssemblyExpectedResult(2)); - -////////////////////////////////////////////////////////////////////// -// LISTS OF PACKAGE TESTS -////////////////////////////////////////////////////////////////////// - -// Tests run for all runner packages except NETCORE runner -static List StandardRunnerTests = new List -{ - Net35Test, - Net40Test, - NetCore21Test, - NetCore31Test, - Net50Test, - Net60Test, - Net70Test, - Net35PlusNet40Test, - Net40PlusNet60Test, - Net50PlusNet60Test, - Net35X86Test, - Net40X86Test, - Net60AspNetCoreTest -}; - -// Tests run for the NETCORE runner package -static List NetCoreRunnerTests = new List -{ - NetCore21Test, - NetCore31Test, - Net50Test, - Net60Test, - Net50PlusNet60Test, - Net60AspNetCoreTest -}; diff --git a/cake/packages.cake b/cake/packages.cake index b8bf1ffa9..4e342f7e5 100644 --- a/cake/packages.cake +++ b/cake/packages.cake @@ -4,7 +4,7 @@ public abstract class NuGetPackageDefinition : PackageDefinition { - protected NuGetPackageDefinition(ICakeContext context, string packageVersion) : base(context, packageVersion) { } + protected NuGetPackageDefinition(BuildSettings settings) : base(settings) { } public override string PackageFileName => $"{PackageId}.{PackageVersion}.nupkg"; public override string SymbolPackageName => System.IO.Path.ChangeExtension(PackageFileName, ".snupkg"); @@ -42,7 +42,7 @@ public abstract class NuGetPackageDefinition : PackageDefinition public class NUnitConsoleNuGetPackage : NuGetPackageDefinition { - public NUnitConsoleNuGetPackage(ICakeContext context, string packageVersion) : base(context, packageVersion) + public NUnitConsoleNuGetPackage(BuildSettings settings) : base(settings) { PackageId = "NUnit.Console"; PackageSource = PROJECT_DIR + "nuget/runners/nunit.console-runner-with-extensions.nuspec"; @@ -60,11 +60,11 @@ public class NUnitConsoleNuGetPackage : NuGetPackageDefinition public class NUnitConsoleRunnerNuGetPackage : NuGetPackageDefinition { - public NUnitConsoleRunnerNuGetPackage(ICakeContext context, string packageVersion) : base(context, packageVersion) + public NUnitConsoleRunnerNuGetPackage(BuildSettings settings) : base(settings) { PackageId = "NUnit.ConsoleRunner"; PackageSource = PROJECT_DIR + "nuget/runners/nunit.console-runner.nuspec"; - BasePath = NETFX_CONSOLE_DIR; + BasePath = settings.NetFxConsoleBinDir; PackageChecks = new PackageCheck[] { HasFiles("LICENSE.txt", "NOTICES.txt"), HasDirectory("tools").WithFiles(CONSOLE_FILES).AndFiles(ENGINE_FILES).AndFile("nunit.console.nuget.addins"), @@ -85,19 +85,17 @@ public class NUnitConsoleRunnerNuGetPackage : NuGetPackageDefinition HasDirectory("tools/agents/net7.0").WithFiles(AGENT_PDB_FILES_NETCORE) }; TestExecutable = "tools/nunit3-console.exe"; - PackageTests = StandardRunnerTests; + PackageTests = settings.StandardRunnerTests; } } public class NUnitNetCoreConsoleRunnerPackage : NuGetPackageDefinition { - public NUnitNetCoreConsoleRunnerPackage(ICakeContext context, string packageVersion) : base(context, packageVersion) + public NUnitNetCoreConsoleRunnerPackage(BuildSettings settings) : base(settings) { PackageId = "NUnit.ConsoleRunner.NetCore"; - //PackageSource = PROJECT_DIR + "nuget/runners/nunit.console-runner.netcore.nuspec"; PackageSource = NETCORE_CONSOLE_PROJECT; - //BasePath = NETCORE_CONSOLE_DIR; - BasePath = NETCORE_CONSOLE_PROJECT_BIN_DIR; + BasePath = settings.NetCoreConsoleBinDir; PackageChecks = new PackageCheck[] { HasDirectory("content").WithFiles("LICENSE.txt", "NOTICES.txt"), HasDirectory($"tools/{NETCORE_CONSOLE_TARGET}/any").WithFiles(CONSOLE_FILES_NETCORE).AndFiles(ENGINE_FILES) @@ -106,7 +104,7 @@ public class NUnitNetCoreConsoleRunnerPackage : NuGetPackageDefinition HasDirectory($"tools/{NETCORE_CONSOLE_TARGET}/any").WithFile("nunit3-netcore-console.pdb").AndFiles(ENGINE_PDB_FILES) }; TestExecutable = $"tools/{NETCORE_CONSOLE_TARGET}/any/nunit3-netcore-console.dll"; - PackageTests = NetCoreRunnerTests; + PackageTests = settings.NetCoreRunnerTests; } // Build package from project file @@ -114,7 +112,7 @@ public class NUnitNetCoreConsoleRunnerPackage : NuGetPackageDefinition { var settings = new DotNetPackSettings() { - Configuration = Configuration, + Configuration = _settings.Configuration, OutputDirectory = PACKAGE_DIR, IncludeSymbols = HasSymbols, ArgumentCustomization = args => args.Append($"/p:Version={PackageVersion}") @@ -136,11 +134,11 @@ public class NUnitNetCoreConsoleRunnerPackage : NuGetPackageDefinition public class NUnitEngineNuGetPackage : NuGetPackageDefinition { - public NUnitEngineNuGetPackage(ICakeContext context, string packageVersion) : base(context, packageVersion) + public NUnitEngineNuGetPackage(BuildSettings settings) : base(settings) { PackageId = "NUnit.Engine"; PackageSource = PROJECT_DIR + "nuget/engine/nunit.engine.nuspec"; - BasePath = ENGINE_PROJECT_BIN_DIR; + BasePath = PROJECT_DIR + $"src/NUnitEngine/nunit.engine/bin/{settings.Configuration}/"; PackageChecks = new PackageCheck[] { HasFiles("LICENSE.txt", "NOTICES.txt"), HasDirectory("lib/net462").WithFiles(ENGINE_FILES), @@ -166,11 +164,11 @@ public class NUnitEngineNuGetPackage : NuGetPackageDefinition public class NUnitEngineApiNuGetPackage : NuGetPackageDefinition { - public NUnitEngineApiNuGetPackage(ICakeContext context, string packageVersion) : base(context, packageVersion) + public NUnitEngineApiNuGetPackage(BuildSettings settings) : base(settings) { PackageId = "NUnit.Engine.Api"; PackageSource = PROJECT_DIR + "nuget/engine/nunit.engine.api.nuspec"; - BasePath = ENGINE_API_PROJECT_BIN_DIR; + BasePath = PROJECT_DIR + $"src/NUnitEngine/nunit.engine.api/bin/{settings.Configuration}/"; PackageChecks = new PackageCheck[] { HasFile("LICENSE.txt"), HasDirectory("lib/net20").WithFile("nunit.engine.api.dll"), @@ -189,7 +187,7 @@ public class NUnitEngineApiNuGetPackage : NuGetPackageDefinition public abstract class ChocolateyPackageDefinition : PackageDefinition { - protected ChocolateyPackageDefinition(ICakeContext context, string packageVersion) : base(context, packageVersion) { } + protected ChocolateyPackageDefinition(BuildSettings settings) : base(settings) { } public override string PackageFileName => $"{PackageId}.{PackageVersion}.nupkg"; public override string InstallDirectory => PACKAGE_TEST_DIR + $"choco/{PackageId}/"; @@ -216,11 +214,11 @@ public abstract class ChocolateyPackageDefinition : PackageDefinition public class NUnitConsoleRunnerChocolateyPackage : ChocolateyPackageDefinition { - public NUnitConsoleRunnerChocolateyPackage(ICakeContext context, string packageVersion) : base(context, packageVersion) + public NUnitConsoleRunnerChocolateyPackage(BuildSettings settings) : base(settings) { PackageId = "nunit-console-runner"; PackageSource = PROJECT_DIR + "choco/nunit-console-runner.nuspec"; - BasePath = NETFX_CONSOLE_DIR; + BasePath = settings.NetFxConsoleBinDir; PackageChecks = new PackageCheck[] { HasDirectory("tools").WithFiles("LICENSE.txt", "NOTICES.txt", "VERIFICATION.txt").AndFiles(CONSOLE_FILES).AndFiles(ENGINE_FILES).AndFile("nunit.choco.addins"), HasDirectory("tools/agents/net20").WithFiles(AGENT_FILES).AndFile("nunit.agent.addins"), @@ -231,7 +229,7 @@ public class NUnitConsoleRunnerChocolateyPackage : ChocolateyPackageDefinition HasDirectory("tools/agents/net7.0").WithFiles(AGENT_FILES_NETCORE).AndFile("nunit.agent.addins") }; TestExecutable = "tools/nunit3-console.exe"; - PackageTests = StandardRunnerTests; + PackageTests = settings.StandardRunnerTests; } } @@ -241,7 +239,11 @@ public class NUnitConsoleRunnerChocolateyPackage : ChocolateyPackageDefinition public abstract class MsiPackageDefinition : PackageDefinition { - protected MsiPackageDefinition(ICakeContext context, string packageVersion) : base(context, packageVersion) { } + protected MsiPackageDefinition(BuildSettings settings) : base(settings) + { + // Required version format for MSI + PackageVersion = settings.BuildVersion.SemVer; + } public override string PackageFileName => $"{PackageId}-{PackageVersion}.msi"; public override string InstallDirectory => PACKAGE_TEST_DIR + $"msi/{PackageId}/"; @@ -251,7 +253,7 @@ public abstract class MsiPackageDefinition : PackageDefinition { _context.MSBuild(PackageSource, new MSBuildSettings() .WithTarget("Rebuild") - .SetConfiguration(Configuration) + .SetConfiguration(_settings.Configuration) .WithProperty("Version", PackageVersion) .WithProperty("DisplayVersion", PackageVersion) .WithProperty("OutDir", PACKAGE_DIR) @@ -274,11 +276,12 @@ public abstract class MsiPackageDefinition : PackageDefinition public class NUnitConsoleMsiPackage : MsiPackageDefinition { - public NUnitConsoleMsiPackage(ICakeContext context, string packageVersion) : base(context, packageVersion) + public NUnitConsoleMsiPackage(BuildSettings settings) : base(settings) { PackageId = "NUnit.Console"; PackageSource = PROJECT_DIR + "msi/nunit/nunit.wixproj"; - BasePath = NETFX_CONSOLE_DIR; + BasePath = settings.NetFxConsoleBinDir; + PackageVersion = settings.BuildVersion.SemVer; PackageChecks = new PackageCheck[] { HasDirectory("NUnit.org").WithFiles("LICENSE.txt", "NOTICES.txt", "nunit.ico"), HasDirectory("NUnit.org/nunit-console").WithFiles(CONSOLE_FILES).AndFiles(ENGINE_FILES).AndFile("nunit.bundle.addins"), @@ -291,7 +294,7 @@ public class NUnitConsoleMsiPackage : MsiPackageDefinition HasDirectory("Nunit.org/nunit-console/addins").WithFiles("nunit.core.dll", "nunit.core.interfaces.dll", "nunit.v2.driver.dll", "nunit-project-loader.dll", "vs-project-loader.dll", "nunit-v2-result-writer.dll", "teamcity-event-listener.dll") }; TestExecutable = "NUnit.org/nunit-console/nunit3-console.exe"; - PackageTests = StandardRunnerTests.Concat(new[] { NUnitProjectTest }); + PackageTests = settings.StandardRunnerTests.Concat(new[] { settings.NUnitProjectTest }); } } @@ -301,7 +304,7 @@ public class NUnitConsoleMsiPackage : MsiPackageDefinition public abstract class ZipPackageDefinition : PackageDefinition { - protected ZipPackageDefinition(ICakeContext context, string packageVersion) : base(context, packageVersion) { } + protected ZipPackageDefinition(BuildSettings settings) : base(settings) { } public override string PackageFileName => $"{PackageId}-{PackageVersion}.zip"; public override string InstallDirectory => PACKAGE_TEST_DIR + $"zip/{PackageId}/"; @@ -322,7 +325,7 @@ public abstract class ZipPackageDefinition : PackageDefinition public class NUnitConsoleZipPackage : ZipPackageDefinition { - public NUnitConsoleZipPackage(ICakeContext context, string packageVersion) : base(context, packageVersion) + public NUnitConsoleZipPackage(BuildSettings settings) : base(settings) { PackageId = "NUnit.Console"; PackageSource = ZipImageDirectory; @@ -337,7 +340,7 @@ public class NUnitConsoleZipPackage : ZipPackageDefinition HasDirectory("bin/agents/net7.0").WithFiles(AGENT_FILES_NETCORE).AndFiles(AGENT_PDB_FILES_NETCORE) }; TestExecutable = "bin/nunit3-console.exe"; - PackageTests = StandardRunnerTests.Concat(new [] { NUnitProjectTest }); + PackageTests = settings.StandardRunnerTests.Concat(new [] { settings.NUnitProjectTest }); } protected override string ZipImageDirectory => PACKAGE_DIR + "zip-image"; diff --git a/cake/utilities.cake b/cake/utilities.cake index cff7c2dd4..68b5dfb48 100644 --- a/cake/utilities.cake +++ b/cake/utilities.cake @@ -2,15 +2,6 @@ // HELPER METHODS - GENERAL ////////////////////////////////////////////////////////////////////// -T GetArgument(string pattern, T defaultValue) -{ - foreach (string name in pattern.Split('|')) - if (HasArgument(name)) - return Argument(name); - - return defaultValue; -} - bool CheckIfDotNetCoreInstalled() { try @@ -85,7 +76,7 @@ void BuildSolution(BuildSettings settings) MSBuildSettings CreateMSBuildSettings(string target, BuildSettings settings) { var msbuildSettings = new MSBuildSettings() - .SetConfiguration(Configuration) + .SetConfiguration(settings.Configuration) .SetVerbosity(Verbosity.Minimal) .WithProperty("Version", settings.ProductVersion) .WithProperty("ApiFileVersion", settings.SemVer + ".0") @@ -124,7 +115,7 @@ MSBuildSettings CreateMSBuildSettings(string target, BuildSettings settings) DotNetMSBuildSettings CreateDotNetMSBuildSettings(string target, BuildSettings settings) { return new DotNetMSBuildSettings() - .SetConfiguration(Configuration) + .SetConfiguration(settings.Configuration) .WithProperty("Version", settings.ProductVersion) .WithProperty("ApiFileVersion", settings.SemVer + ".0") .WithTarget(target); @@ -194,21 +185,16 @@ FilePath GetResultXmlPath(string testAssembly, string targetRuntime) return MakeAbsolute(new FilePath($@"test-results\{targetRuntime}\{assemblyName}.xml")); } -string GetProjectBinDir(string projectPath) +string GetProjectBinDir(string projectPath, string configuration) { var projectDir = System.IO.Path.GetDirectoryName(projectPath); - return projectDir + $"/bin/{Configuration}/"; + return projectDir + $"/bin/{configuration}/"; } -string GetProjectBinDir(string projectPath, string targetRuntime) -{ - return GetProjectBinDir(projectPath) + targetRuntime + "/"; -} - -void RunNUnitLiteTests(string projectPath, string targetRuntime, string additionalArgs="") +void RunNUnitLiteTests(string projectPath, string configuration, string targetRuntime, string additionalArgs="") { var testAssembly = System.IO.Path.GetFileNameWithoutExtension(projectPath) + ".exe"; - var workingDir = GetProjectBinDir(projectPath, targetRuntime); + var workingDir = GetProjectBinDir(projectPath, configuration) + targetRuntime + "/"; var resultPath = GetResultXmlPath( testAssembly, targetRuntime).FullPath; int rc = StartProcess( @@ -225,10 +211,10 @@ void RunNUnitLiteTests(string projectPath, string targetRuntime, string addition UnreportedErrors.Add($"{testAssembly}({targetRuntime}) returned rc = {rc}"); } -void RunDotnetNUnitLiteTests(string projectPath, string targetRuntime, string additionalArgs="") +void RunDotnetNUnitLiteTests(string projectPath, string configuration, string targetRuntime, string additionalArgs="") { var testAssembly = System.IO.Path.GetFileNameWithoutExtension(projectPath) + ".dll"; - var workingDir = GetProjectBinDir(projectPath, targetRuntime); + var workingDir = GetProjectBinDir(projectPath, configuration) + targetRuntime + "/"; var assemblyPath = workingDir + testAssembly; var resultPath = GetResultXmlPath(assemblyPath, targetRuntime).FullPath; @@ -246,15 +232,15 @@ void RunDotnetNUnitLiteTests(string projectPath, string targetRuntime, string ad UnreportedErrors.Add($"{testAssembly}({targetRuntime}) returned rc = {rc}"); } -void RunNetFxConsole(string projectPath, string targetRuntime, string additionalArgs="") +void RunNetFxConsole(string projectPath, string configuration, string targetRuntime, string additionalArgs="") { var testAssembly = System.IO.Path.GetFileNameWithoutExtension(projectPath) + ".dll"; - var workingDir = GetProjectBinDir(projectPath, targetRuntime); + var workingDir = GetProjectBinDir(projectPath, configuration) + targetRuntime + "/"; var assemblyPath = workingDir + testAssembly; var resultPath = GetResultXmlPath(assemblyPath, targetRuntime).FullPath; int rc = StartProcess( - NETFX_CONSOLE, + NETFX_CONSOLE_DIR + $"bin/{configuration}/{NETFX_CONSOLE_TARGET}/nunit3-console.exe", new ProcessSettings() { Arguments = $"\"{assemblyPath}\" --result:{resultPath} {additionalArgs}", @@ -267,10 +253,10 @@ void RunNetFxConsole(string projectPath, string targetRuntime, string additional UnreportedErrors.Add($"{testAssembly}({targetRuntime}) returned rc = {rc}"); } -void RunNetCoreConsole(string projectPath, string targetRuntime) +void RunNetCoreConsole(string projectPath, string configuration, string targetRuntime) { var testAssembly = System.IO.Path.GetFileNameWithoutExtension(projectPath) + ".dll"; - var workingDir = GetProjectBinDir(projectPath, targetRuntime); + var workingDir = GetProjectBinDir(projectPath, configuration) + targetRuntime + "/"; var assemblyPath = workingDir + testAssembly; var resultPath = GetResultXmlPath(assemblyPath, targetRuntime).FullPath; @@ -278,7 +264,7 @@ void RunNetCoreConsole(string projectPath, string targetRuntime) "dotnet", new ProcessSettings { - Arguments = $"\"{NETCORE_CONSOLE}\" \"{assemblyPath}\" --result:{resultPath}", + Arguments = $"\"{NETCORE_CONSOLE_DIR}bin/{configuration}/{NETCORE_CONSOLE_TARGET}/nunit3-netcore-console.dll\" \"{assemblyPath}\" --result:{resultPath}", WorkingDirectory = workingDir }); @@ -301,19 +287,13 @@ public void CopyPackageContents(DirectoryPath packageDir, DirectoryPath outDir) public void PushNuGetPackage(FilePath package, string apiKey, string url) { CheckPackageExists(package); - if (NoPush) - Information($"Push {package} to {url}"); - else - NuGetPush(package, new NuGetPushSettings() { ApiKey = apiKey, Source = url }); + NuGetPush(package, new NuGetPushSettings() { ApiKey = apiKey, Source = url }); } public void PushChocolateyPackage(FilePath package, string apiKey, string url) { CheckPackageExists(package); - if (NoPush) - Information($"Push {package} to {url}"); - else - ChocolateyPush(package, new ChocolateyPushSettings() { ApiKey = apiKey, Source = url }); + ChocolateyPush(package, new ChocolateyPushSettings() { ApiKey = apiKey, Source = url }); } private void CheckPackageExists(FilePath package)