Skip to content

Commit

Permalink
Detect when expecto should use the .NET CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
vbfox committed Aug 14, 2018
1 parent da4bacf commit 9ac20dd
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions src/app/Fake.DotNet.Testing.Expecto/Expecto.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Params =
/// Doesn't run tests, print out list of tests instead.
ListTests : bool
/// Custom arguments to use in the case the helper not yet supports them
CustomArgs: string list
CustomArgs : string list
/// Prints the version on startup. Default is true
PrintVersion : bool
/// Working directory
Expand Down Expand Up @@ -92,40 +92,53 @@ type Params =
WorkingDirectory = ""
}

let run (setParams : Params -> Params) (assemblies : string seq) =
let details = assemblies |> String.separated ", "
use __ = Trace.traceTask "Expecto" details
type private ResolvedRunMode = | ResolvedDirect | ResolvedDotNet

let private getRunMode (assembly: string) =
match System.IO.Path.GetExtension(assembly).ToLowerInvariant() with
| ".dll" -> ResolvedDotNet
| ".exe" -> ResolvedDirect
| ext ->
failwithf "Unable to find a way to run expecto test executable with extension %s" ext

let runAssembly testAssembly =
let exitCode =
let fakeStartInfo testAssembly args =
let workingDir =
if String.isNotNullOrEmpty args.WorkingDirectory
then args.WorkingDirectory else Fake.IO.Path.getDirectory testAssembly
(fun (info: ProcStartInfo) ->
{ info with
FileName = testAssembly
Arguments = string args
WorkingDirectory = workingDir } )
let private runAssembly expectoParams testAssembly =
let fakeStartInfo =
let runMode = getRunMode testAssembly
let workingDir =
if String.isNotNullOrEmpty expectoParams.WorkingDirectory
then expectoParams.WorkingDirectory else Fake.IO.Path.getDirectory testAssembly
let fileName, argsString =
match runMode with
| ResolvedDotNet ->
"dotnet", sprintf "\"%s\" %O" testAssembly expectoParams
| ResolvedDirect ->
testAssembly, string expectoParams
(fun (info: ProcStartInfo) ->
{ info with
FileName = fileName
Arguments = argsString
WorkingDirectory = workingDir } )

let execWithExitCode testAssembly argsString timeout =
Process.execSimple (fakeStartInfo testAssembly argsString) timeout
let exitCode = Process.execSimple fakeStartInfo TimeSpan.MaxValue
testAssembly, exitCode

execWithExitCode testAssembly (setParams Params.DefaultParams) TimeSpan.MaxValue
let run (setParams : Params -> Params) (assemblies : string seq) =
let details = assemblies |> String.separated ", "
use __ = Trace.traceTask "Expecto" details

testAssembly, exitCode
let expectoParams = setParams Params.DefaultParams

let res =
assemblies
|> Seq.map runAssembly
|> Seq.map (runAssembly expectoParams)
|> Seq.filter( snd >> (<>) 0)
|> Seq.toList

match res with
| [] -> ()
| failedAssemblies ->
failedAssemblies
|> List.map (fun (testAssembly,exitCode) ->
|> List.map (fun (testAssembly,exitCode) ->
sprintf "Expecto test of assembly '%s' failed. Process finished with exit code %d." testAssembly exitCode )
|> String.concat System.Environment.NewLine
|> FailedTestsException |> raise
Expand Down

0 comments on commit 9ac20dd

Please sign in to comment.