From 857280a7b350794ff567c18b99fe65a08c4e18d0 Mon Sep 17 00:00:00 2001 From: Kevin Willford Date: Wed, 21 Aug 2019 14:20:54 -0600 Subject: [PATCH] Add a global setup when using a --test= option --- Scalar.FunctionalTests/Program.cs | 1 + Scalar.Tests/NUnitRunner.cs | 9 +++++++++ Scalar.UnitTests/Program.cs | 1 + 3 files changed, 11 insertions(+) diff --git a/Scalar.FunctionalTests/Program.cs b/Scalar.FunctionalTests/Program.cs index ca45b0fe5e..c2872bac4d 100644 --- a/Scalar.FunctionalTests/Program.cs +++ b/Scalar.FunctionalTests/Program.cs @@ -15,6 +15,7 @@ public static void Main(string[] args) { Properties.Settings.Default.Initialize(); NUnitRunner runner = new NUnitRunner(args); + runner.AddGlobalSetupIfNeeded("Scalar.FunctionalTests.GlobalSetup"); if (runner.HasCustomArg("--no-shared-scalar-cache")) { diff --git a/Scalar.Tests/NUnitRunner.cs b/Scalar.Tests/NUnitRunner.cs index d91c9ad127..a768b49cc1 100644 --- a/Scalar.Tests/NUnitRunner.cs +++ b/Scalar.Tests/NUnitRunner.cs @@ -33,6 +33,15 @@ public bool HasCustomArg(string arg) return this.args.Remove(arg); } + public void AddGlobalSetupIfNeeded(string globalSetup) + { + // If there are any test filters, the GlobalSetup still needs to run so add it. + if (this.args.Any(x => x.StartsWith("--test="))) + { + this.args.Add($"--test={globalSetup}"); + } + } + public int RunTests(ICollection includeCategories, ICollection excludeCategories) { string filters = GetFiltersArgument(includeCategories, excludeCategories); diff --git a/Scalar.UnitTests/Program.cs b/Scalar.UnitTests/Program.cs index 47c57f06cd..bc57bb2e7f 100644 --- a/Scalar.UnitTests/Program.cs +++ b/Scalar.UnitTests/Program.cs @@ -11,6 +11,7 @@ public class Program public static void Main(string[] args) { NUnitRunner runner = new NUnitRunner(args); + runner.AddGlobalSetupIfNeeded("Scalar.UnitTests.Setup"); List excludeCategories = new List();