From b08c3d831e25eb9c0a8870be008ebf3907c7fd24 Mon Sep 17 00:00:00 2001 From: Sebastian Brandt Date: Fri, 20 Feb 2015 22:21:36 +0100 Subject: [PATCH 1/3] nunit sequential now throws a FailedTestsException --- src/app/FakeLib/UnitTest/NUnit/Sequential.fs | 6 +++--- src/app/FakeLib/UnitTest/UnitTestCommon.fs | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/app/FakeLib/UnitTest/NUnit/Sequential.fs b/src/app/FakeLib/UnitTest/NUnit/Sequential.fs index 655d25b5704..54838dc2b6d 100644 --- a/src/app/FakeLib/UnitTest/NUnit/Sequential.fs +++ b/src/app/FakeLib/UnitTest/NUnit/Sequential.fs @@ -14,7 +14,7 @@ module Fake.NUnitSequential /// !! (testDir + @"\Test.*.dll") /// |> NUnit (fun p -> { p with ErrorLevel = DontFailBuild }) /// ) -let NUnit (setParams : NUnitParams -> NUnitParams) (assemblies : string seq) = +let NUnit (setParams : NUnitParams -> NUnitParams) (assemblies : string seq) = let details = assemblies |> separated ", " traceStartTask "NUnit" details let parameters = NUnitDefaults |> setParams @@ -38,8 +38,8 @@ let NUnit (setParams : NUnitParams -> NUnitParams) (assemblies : string seq) = | DontFailBuild -> match result with | OK | TestsFailed -> traceEndTask "NUnit" details - | _ -> failwith (errorDescription result) + | _ -> raise (FailedTestsException(errorDescription result)) | Error | FailOnFirstError -> match result with | OK -> traceEndTask "NUnit" details - | _ -> failwith (errorDescription result) + | _ -> raise (FailedTestsException(errorDescription result)) diff --git a/src/app/FakeLib/UnitTest/UnitTestCommon.fs b/src/app/FakeLib/UnitTest/UnitTestCommon.fs index 1f17e795cad..e653a59bf83 100644 --- a/src/app/FakeLib/UnitTest/UnitTestCommon.fs +++ b/src/app/FakeLib/UnitTest/UnitTestCommon.fs @@ -12,3 +12,6 @@ type TestRunnerErrorLevel = | FailOnFirstError /// With this option set, no exception is thrown if a test is broken. | DontFailBuild + +type FailedTestsException(msg) = + inherit System.Exception(msg) From 20a5d2cb6af87e73dac5cfd1c67e445b6e51eecf Mon Sep 17 00:00:00 2001 From: Sebastian Brandt Date: Fri, 20 Feb 2015 22:26:36 +0100 Subject: [PATCH 2/3] nunit parallel now throws typed exception --- src/app/FakeLib/UnitTest/NUnit/Parallel.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/FakeLib/UnitTest/NUnit/Parallel.fs b/src/app/FakeLib/UnitTest/NUnit/Parallel.fs index 3d41ca5b1b1..1c9268a9049 100644 --- a/src/app/FakeLib/UnitTest/NUnit/Parallel.fs +++ b/src/app/FakeLib/UnitTest/NUnit/Parallel.fs @@ -96,12 +96,12 @@ let NUnitParallel (setParams : NUnitParams -> NUnitParams) (assemblies : string List.fold (fun acc x -> { acc with WorseReturnCode = min acc.WorseReturnCode x.ReturnCode Messages = acc.Messages @ formatErrorMessages x }) AggFailedResult.Empty failedResults - + let fail() = List.iter traceError aggResult.Messages - failwithf "NUnitParallel test runs failed (%d of %d assemblies are failed)." (List.length failedResults) - (List.length testRunResults) - + raise (FailedTestsException (sprintf "NUnitParallel test runs failed (%d of %d assemblies are failed)." + (List.length failedResults) (List.length testRunResults))) + match parameters.ErrorLevel with | DontFailBuild -> match aggResult.WorseReturnCode with From 2ce4fb320f8c87932bd9038c22c164f58cd2a89d Mon Sep 17 00:00:00 2001 From: Sebastian Brandt Date: Fri, 20 Feb 2015 22:28:12 +0100 Subject: [PATCH 3/3] if the exception is a FailedTestsException it will not be reported to teamcity --- src/app/FAKE/Program.fs | 5 ++++- src/app/FakeLib/TargetHelper.fs | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app/FAKE/Program.fs b/src/app/FAKE/Program.fs index f00cf290afc..23df49f8e43 100644 --- a/src/app/FAKE/Program.fs +++ b/src/app/FAKE/Program.fs @@ -150,7 +150,10 @@ try |> traceError printUsage() - sendTeamCityError exn.Message + let isFailedTestsException = exn :? UnitTestCommon.FailedTestsException + if not isFailedTestsException then + sendTeamCityError exn.Message + Environment.ExitCode <- 1 if buildServer = BuildServer.TeamCity then diff --git a/src/app/FakeLib/TargetHelper.fs b/src/app/FakeLib/TargetHelper.fs index b0e6511d545..62800f03e28 100644 --- a/src/app/FakeLib/TargetHelper.fs +++ b/src/app/FakeLib/TargetHelper.fs @@ -196,8 +196,11 @@ let targetError targetName (exn:System.Exception) = let msg = sprintf "%s%s" (error exn) (if exn.InnerException <> null then "\n" + (exn.InnerException |> error) else "") traceError <| sprintf "Running build failed.\nError:\n%s" msg - sendTeamCityError <| error exn - + + let isFailedTestsException = exn :? UnitTestCommon.FailedTestsException + if not isFailedTestsException then + sendTeamCityError <| error exn + let addExecutedTarget target time = ExecutedTargets.Add (toLower target) |> ignore ExecutedTargetTimes.Add(toLower target,time) |> ignore