From e9cc78598e3f7eb8c0fb4b8e1d8b1ebe1efbfa45 Mon Sep 17 00:00:00 2001 From: Robert Pickering Date: Tue, 25 Aug 2020 15:48:22 +0200 Subject: [PATCH 1/3] Allow users of nunit3 set environment variables in the runner I need this for an obscure reason, maybe other people will too? --- src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs b/src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs index 6855eda8df0..b6ff56b3aea 100644 --- a/src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs +++ b/src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs @@ -217,6 +217,9 @@ type NUnit3Params = /// A test parameter specified in the form name=value. Multiple parameters may be specified, separated by semicolons Params : string + + /// list or environment variables that will be set in the nunit-console.exe process + EnvironmentVariables : (string * string) list } /// The [NUnit3Params](fake-testing-nunit3-nunit3params.html) default parameters. @@ -245,6 +248,7 @@ type NUnit3Params = /// - `TraceLevel` - `Default` (By default NUnit3 sets this to off internally) /// - `SkipNonTestAssemblies` - `false` /// - `Params` - `""` +/// - `EnvironmentVariables` - `[]` /// ## Defaults let NUnit3Defaults = { @@ -273,6 +277,7 @@ let NUnit3Defaults = TraceLevel= NUnit3TraceLevel.Default SkipNonTestAssemblies = false Params = "" + EnvironmentVariables = [] } /// Tries to detect the working directory as specified in the parameters or via TeamCity settings @@ -331,6 +336,9 @@ let internal createProcess createTempFile (setParams : NUnit3Params -> NUnit3Par CreateProcess.fromRawCommandLine tool argLine |> CreateProcess.withFramework |> CreateProcess.withWorkingDirectory (getWorkingDir parameters) + |> fun cp -> + parameters.EnvironmentVariables + |> Seq.fold (fun acc (k,v)-> CreateProcess.setEnvironmentVariable k v acc) cp //|> CreateProcess.withTimeout processTimeout |> CreateProcess.addOnSetup (fun () -> File.WriteAllText(path, generatedArgs) From c164ddb5ee43f3512a46aa710f9d43a3a903b980 Mon Sep 17 00:00:00 2001 From: Robert Pickering Date: Wed, 9 Sep 2020 16:26:13 +0200 Subject: [PATCH 2/3] Implement env vars for nunuit3 the using the same technique as fsi, DotNet, MsBuild --- src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs b/src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs index b6ff56b3aea..cad8f6b06fb 100644 --- a/src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs +++ b/src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs @@ -219,8 +219,11 @@ type NUnit3Params = Params : string /// list or environment variables that will be set in the nunit-console.exe process - EnvironmentVariables : (string * string) list + Environment : Map } + /// Sets the current environment variables. + member x.WithEnvironment map = + { x with Environment = map } /// The [NUnit3Params](fake-testing-nunit3-nunit3params.html) default parameters. /// @@ -277,7 +280,7 @@ let NUnit3Defaults = TraceLevel= NUnit3TraceLevel.Default SkipNonTestAssemblies = false Params = "" - EnvironmentVariables = [] + Environment = Map.empty } /// Tries to detect the working directory as specified in the parameters or via TeamCity settings @@ -335,10 +338,7 @@ let internal createProcess createTempFile (setParams : NUnit3Params -> NUnit3Par let argLine = Args.toWindowsCommandLine [ (sprintf "@%s" path) ] CreateProcess.fromRawCommandLine tool argLine |> CreateProcess.withFramework - |> CreateProcess.withWorkingDirectory (getWorkingDir parameters) - |> fun cp -> - parameters.EnvironmentVariables - |> Seq.fold (fun acc (k,v)-> CreateProcess.setEnvironmentVariable k v acc) cp + |> CreateProcess.withEnvironment (parameters.Environment |> Map.toList) //|> CreateProcess.withTimeout processTimeout |> CreateProcess.addOnSetup (fun () -> File.WriteAllText(path, generatedArgs) From 2e19bfb1230a8a98ee584ec85a3b1f3c0d4c4ac8 Mon Sep 17 00:00:00 2001 From: Robert Pickering Date: Wed, 9 Sep 2020 16:50:02 +0200 Subject: [PATCH 3/3] fix copy / paste error --- src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs b/src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs index cad8f6b06fb..3cb483f5a2b 100644 --- a/src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs +++ b/src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs @@ -338,6 +338,7 @@ let internal createProcess createTempFile (setParams : NUnit3Params -> NUnit3Par let argLine = Args.toWindowsCommandLine [ (sprintf "@%s" path) ] CreateProcess.fromRawCommandLine tool argLine |> CreateProcess.withFramework + |> CreateProcess.withWorkingDirectory (getWorkingDir parameters) |> CreateProcess.withEnvironment (parameters.Environment |> Map.toList) //|> CreateProcess.withTimeout processTimeout |> CreateProcess.addOnSetup (fun () ->