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

Detect when expecto should use the .NET CLI #2064

Merged
merged 2 commits into from
Aug 16, 2018
Merged
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
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 RunMode = | Direct | DotNetCli

let private getRunMode (assembly: string) =
match System.IO.Path.GetExtension(assembly).ToLowerInvariant() with
| ".dll" -> DotNetCli
| ".exe" -> Direct
| 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
| DotNetCli ->
"dotnet", sprintf "\"%s\" %O" testAssembly expectoParams
| Direct ->
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