Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed exception when nunit tests fail will not reported to teamcity anymore #659

Merged
merged 3 commits into from
Feb 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/app/FAKE/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/app/FakeLib/TargetHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/app/FakeLib/UnitTest/NUnit/Parallel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/app/FakeLib/UnitTest/NUnit/Sequential.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
3 changes: 3 additions & 0 deletions src/app/FakeLib/UnitTest/UnitTestCommon.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)