From 607907e45410af945c68476e50527dc85a2d59e4 Mon Sep 17 00:00:00 2001 From: lrieger Date: Thu, 7 Apr 2016 16:58:58 +0200 Subject: [PATCH 1/2] demonstrate https://github.com/fsharp/FAKE/issues/1187 --- FAKE.sln | 7 +++-- build.fsx | 30 +++++++++++++++++++ .../fake-powershell-redirected.fsx | 7 +++++ .../fake-powershell-redirected.ps1 | 11 +++++++ .../run-fake-powershell-redirected.bat | 1 + 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/test/testscripts/fake-powershell-redirected.fsx create mode 100644 src/test/testscripts/fake-powershell-redirected.ps1 create mode 100644 src/test/testscripts/run-fake-powershell-redirected.bat diff --git a/FAKE.sln b/FAKE.sln index cec77a348e5..3eec2b2a0ba 100644 --- a/FAKE.sln +++ b/FAKE.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0F0488CC-2580-4C07-9E16-3997480F0221}" ProjectSection(SolutionItems) = preProject @@ -120,6 +120,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assemblyinfo", "assemblyinf EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "testscripts", "testscripts", "{16D0306A-E2D0-444B-87F8-22605A1EC57C}" ProjectSection(SolutionItems) = preProject + src\test\testscripts\fake-powershell-redirected.fsx = src\test\testscripts\fake-powershell-redirected.fsx + src\test\testscripts\fake-powershell-redirected.ps1 = src\test\testscripts\fake-powershell-redirected.ps1 + src\test\testscripts\run-fake-powershell-redirected.bat = src\test\testscripts\run-fake-powershell-redirected.bat src\test\testscripts\test1.fsx = src\test\testscripts\test1.fsx EndProjectSection EndProject diff --git a/build.fsx b/build.fsx index 415375a5a2a..54300b675aa 100644 --- a/build.fsx +++ b/build.fsx @@ -167,6 +167,35 @@ Target "Test" (fun _ -> |> xUnit id ) +Target "RunTestScripts" (fun _ -> + + // copy all test scripts into the test directory and run them there so they don't mess up the source tree + + let testScriptDir = testDir @@ "testScripts" + + !! ("src/test/testscripts/*.*") + |> CopyFiles testScriptDir + + !! (testScriptDir @@ "run-*.bat") + |> Seq.iter (fun ts -> + let currentDir = System.Environment.CurrentDirectory + try + System.Environment.CurrentDirectory <- testScriptDir + let result = + ExecProcess (fun info -> + info.FileName <- ts + info.WorkingDirectory <- "." + info.EnvironmentVariables.["FAKE"] <- "build/FAKE.exe" |> Path.absolute + info.EnvironmentVariables.["FAKE_DIR"] <- "build" |> Path.absolute + ) (System.TimeSpan.FromMinutes 3.0) + + if result <> 0 then + failwithf "TestScript %s failed with %i" (Path.GetFileName ts) result + finally + System.Environment.CurrentDirectory <- currentDir + ) +) + Target "Bootstrap" (fun _ -> let buildScript = "build.fsx" let testScript = "testbuild.fsx" @@ -364,6 +393,7 @@ Target "Default" DoNothing ==> "BuildSolution" //==> "ILRepack" ==> "Test" + ==> "RunTestScripts" ==> "Bootstrap" ==> "Default" ==> "CopyLicense" diff --git a/src/test/testscripts/fake-powershell-redirected.fsx b/src/test/testscripts/fake-powershell-redirected.fsx new file mode 100644 index 00000000000..80059b5ff36 --- /dev/null +++ b/src/test/testscripts/fake-powershell-redirected.fsx @@ -0,0 +1,7 @@ +#r @"FakeLib.dll" + +open Fake + +Target "Default" DoNothing + +RunTargetOrDefault "Default" diff --git a/src/test/testscripts/fake-powershell-redirected.ps1 b/src/test/testscripts/fake-powershell-redirected.ps1 new file mode 100644 index 00000000000..d8d31bb02df --- /dev/null +++ b/src/test/testscripts/fake-powershell-redirected.ps1 @@ -0,0 +1,11 @@ +$fake_exe = $env:FAKE +$fake_dir = $env:FAKE_DIR +if ([string]::IsNullOrWhiteSpace($fake_exe)) { + $fake_dir = "..\..\..\build" + $fake_exe = "$fake_dir\fake.exe" +} + +# when this is set, powershell throws an exception when any process writes to STDERR +$ErrorActionPreference = "Stop" +# this issue only appears if the FAKE output is redirected to a file +&"$fake_exe" "fake-powershell-redirected.fsx" 2>&1 > out-run-fake-powershell-redirected.log diff --git a/src/test/testscripts/run-fake-powershell-redirected.bat b/src/test/testscripts/run-fake-powershell-redirected.bat new file mode 100644 index 00000000000..6c3855808d7 --- /dev/null +++ b/src/test/testscripts/run-fake-powershell-redirected.bat @@ -0,0 +1 @@ +powershell -ExecutionPolicy Bypass %cd%\fake-powershell-redirected.ps1 From 7bbcfd7689fc7644bfff78427e8ce2baf67a2176 Mon Sep 17 00:00:00 2001 From: lrieger Date: Sat, 9 Apr 2016 04:53:52 +0200 Subject: [PATCH 2/2] fix path issue in build.fsx:RunTestScripts --- build.fsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build.fsx b/build.fsx index 54300b675aa..75fe750031e 100644 --- a/build.fsx +++ b/build.fsx @@ -176,6 +176,9 @@ Target "RunTestScripts" (fun _ -> !! ("src/test/testscripts/*.*") |> CopyFiles testScriptDir + let absFakeExe = "build/FAKE.exe" |> Path.absolute + let absBuildDir = "build" |> Path.absolute + !! (testScriptDir @@ "run-*.bat") |> Seq.iter (fun ts -> let currentDir = System.Environment.CurrentDirectory @@ -185,8 +188,8 @@ Target "RunTestScripts" (fun _ -> ExecProcess (fun info -> info.FileName <- ts info.WorkingDirectory <- "." - info.EnvironmentVariables.["FAKE"] <- "build/FAKE.exe" |> Path.absolute - info.EnvironmentVariables.["FAKE_DIR"] <- "build" |> Path.absolute + info.EnvironmentVariables.["FAKE"] <- absFakeExe + info.EnvironmentVariables.["FAKE_DIR"] <- absBuildDir ) (System.TimeSpan.FromMinutes 3.0) if result <> 0 then