Skip to content

Commit

Permalink
Reformat to be a try/finally
Browse files Browse the repository at this point in the history
  • Loading branch information
BlythMeister committed Sep 28, 2018
1 parent f5ef276 commit da51bea
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs
Original file line number Diff line number Diff line change
Expand Up @@ -317,34 +317,37 @@ let run (setParams : NUnit3Params -> NUnit3Params) (assemblies : string seq) =
if Array.isEmpty assemblies then failwith "NUnit: cannot run tests (the assembly list is empty)."
let tool = parameters.ToolPath
let generatedArgs = buildArgs parameters assemblies
let path = Path.Combine(Path.GetTempPath(), (sprintf "%s.txt" (Guid.NewGuid().ToString())))
File.WriteAllText(path, generatedArgs)
Trace.trace(sprintf "Saved args to '%s' with value: %s" path generatedArgs)
let args = (sprintf "@%s" path)
Trace.trace (tool + " " + args)
let processTimeout = TimeSpan.MaxValue // Don't set a process timeout. The timeout is per test.
let result =
Process.execSimple ((fun info ->
{ info with
FileName = tool
WorkingDirectory = getWorkingDir parameters
Arguments = args }) >> Process.withFramework) processTimeout

File.Delete(path)
let path = Path.GetTempFileName()

try
File.WriteAllText(path, generatedArgs)
Trace.trace(sprintf "Saved args to '%s' with value: %s" path generatedArgs)
let args = (sprintf "@%s" path)
Trace.trace (tool + " " + args)

let result = Process.execSimple ((fun info -> { info with
FileName = tool
WorkingDirectory = getWorkingDir parameters
Arguments = args }) >> Process.withFramework) processTimeout

let errorDescription error =
match error with
| OK -> "OK"
| TestsFailed -> sprintf "NUnit test failed (%d)." error
| FatalError x -> sprintf "NUnit test failed. Process finished with exit code %s (%d)." x error

match parameters.ErrorLevel with
| NUnit3ErrorLevel.DontFailBuild ->
match result with
| OK | TestsFailed -> ()
| _ -> raise (FailedTestsException(errorDescription result))
| NUnit3ErrorLevel.Error | FailOnFirstError ->
match result with
| OK -> ()
| _ -> raise (FailedTestsException(errorDescription result))

finally
File.Delete(path)

let errorDescription error =
match error with
| OK -> "OK"
| TestsFailed -> sprintf "NUnit test failed (%d)." error
| FatalError x -> sprintf "NUnit test failed. Process finished with exit code %s (%d)." x error

match parameters.ErrorLevel with
| NUnit3ErrorLevel.DontFailBuild ->
match result with
| OK | TestsFailed -> ()
| _ -> raise (FailedTestsException(errorDescription result))
| NUnit3ErrorLevel.Error | FailOnFirstError ->
match result with
| OK -> ()
| _ -> raise (FailedTestsException(errorDescription result))
__.MarkSuccess()

0 comments on commit da51bea

Please sign in to comment.