Skip to content

Commit

Permalink
add test and fix #2180
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed Nov 10, 2018
1 parent 2996cf4 commit d6d596f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/app/Fake.DotNet.Testing.NUnit/NUnit3.fs
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,16 @@ let buildArgs (parameters:NUnit3Params) (assemblies: string seq) =
|> StringBuilder.appendFileNamesIfNotNull assemblies
|> StringBuilder.toText

let internal createProcess (setParams : NUnit3Params -> NUnit3Params) (assemblies : string[]) =
let internal createProcess createTempFile (setParams : NUnit3Params -> NUnit3Params) (assemblies : string[]) =
let parameters = NUnit3Defaults |> setParams
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 processTimeout = TimeSpan.MaxValue // Don't set a process timeout. The timeout is per test.

let path = Path.GetTempFileName()
let args = (sprintf "@%s" path)
CreateProcess.fromRawWindowsCommandLine tool args
let path = createTempFile()
let argLine = Args.toWindowsCommandLine [ (sprintf "@%s" path) ]
CreateProcess.fromRawWindowsCommandLine tool argLine
|> CreateProcess.withFramework
|> CreateProcess.withWorkingDirectory (getWorkingDir parameters)
//|> CreateProcess.withTimeout processTimeout
Expand Down Expand Up @@ -351,7 +351,7 @@ let run (setParams : NUnit3Params -> NUnit3Params) (assemblies : string seq) =
let assemblies = assemblies |> Seq.toArray
let details = assemblies |> String.separated ", "
use __ = Trace.traceTask "NUnit" details
createProcess setParams assemblies
createProcess Path.GetTempFileName setParams assemblies
|> Proc.run

__.MarkSuccess()
27 changes: 26 additions & 1 deletion src/test/Fake.Core.UnitTests/Fake.DotNet.Testing.NUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let tests =
testList "Fake.DotNet.Testing.NUnit.Tests" [
testCase "Test that we write and delete arguments file" <| fun _ ->
let cp =
NUnit3.createProcess (fun param ->
NUnit3.createProcess Path.GetTempFileName (fun param ->
{ param with
ToolPath = "mynunit.exe"
}) [| "assembly.dll" |]
Expand All @@ -33,4 +33,29 @@ let tests =
Expect.sequenceEqual args ["--noheader"; "assembly.dll"] "Expected arg file to be correct"
)
Expect.isFalse (File.Exists argFile) "File should be deleted"

testCase "Test that we support file-paths with space - #2180" <| fun _ ->
let d = Directory.CreateDirectory "some path"
let cp =
NUnit3.createProcess (fun _ -> "some path/with spaces.txt") (fun param ->
{ param with
ToolPath = "mynunit.exe"
}) [| "assembly.dll" |]
let file, args =
match cp.Command with
| RawCommand(file, args) -> file, args
| _ -> failwithf "expected RawCommand"
|> ArgumentHelper.checkIfMono
Expect.equal file "mynunit.exe" "Expected mynunit.exe"
Expect.equal args.Args.Length 1 "expected a single argument"
Expect.equal args.Args.[0] "@some path/with spaces.txt"
let argFile = args.Args.[0].Substring(1)

( use state = cp.Hook.PrepareState()
let contents = File.ReadAllText argFile
let args = Args.fromWindowsCommandLine contents
Expect.sequenceEqual args ["--noheader"; "assembly.dll"] "Expected arg file to be correct"
)
Expect.isFalse (File.Exists argFile) "File should be deleted"
d.Delete()
]

0 comments on commit d6d596f

Please sign in to comment.