-
Notifications
You must be signed in to change notification settings - Fork 587
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
Expecto helper #1435
Merged
Merged
Expecto helper #1435
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/// Contains tasks to run [expecto](https://github.com/haf/expecto) v2 unit tests. | ||
module Fake.Testing.Expecto | ||
|
||
open System | ||
open System.IO | ||
open System.Text | ||
open Fake | ||
|
||
/// CLI parameters available if you use Tests.runTestsInAssembly defaultConfig argv in your code: | ||
type ExpectoParams = | ||
{ | ||
/// Extra verbose output for your tests | ||
Debug : bool | ||
/// Run all tests in parallel. Default is true | ||
Parallel : bool | ||
/// Filter a specific hierarchy to run | ||
Filter : string | ||
/// Filter a specific test case to run. | ||
FilterTestCase : string | ||
/// Filter a specific test list to run. | ||
FilterTestList : string | ||
/// Run only provided tests. | ||
Run : string list | ||
/// Doesn't run tests, print out list of tests instead. | ||
ListTests : bool | ||
/// Working directory | ||
WorkingDirectory : string | ||
} | ||
override this.ToString() = | ||
let append (s: string) (sb: StringBuilder) = sb.Append s | ||
let appendIfTrue p s sb = | ||
if p then append s sb else sb | ||
let appendIfNotNullOrWhiteSpace p s (sb: StringBuilder) = | ||
if String.IsNullOrWhiteSpace p |> not | ||
then sprintf "%s%s " s p |> sb.Append | ||
else sb | ||
let appendList list s (sb: StringBuilder) = | ||
let filtered = list |> List.filter (String.IsNullOrWhiteSpace >> not) | ||
if List.isEmpty filtered then sb | ||
else | ||
filtered |> separated " " |> sprintf "%s%s " s |> sb.Append | ||
StringBuilder() | ||
|> appendIfTrue this.Debug "--debug " | ||
|> appendIfTrue this.Parallel "--parallel " | ||
|> appendIfTrue (not this.Parallel) "--sequential " | ||
|> appendIfNotNullOrWhiteSpace this.Filter "--filter " | ||
|> appendIfNotNullOrWhiteSpace this.FilterTestCase "--filter-test-case " | ||
|> appendIfNotNullOrWhiteSpace this.FilterTestList "--filter-test-list " | ||
|> appendList this.Run "--run " | ||
|> toText | ||
|
||
static member DefaultParams = | ||
{ | ||
Debug = false | ||
Parallel = true | ||
Filter = "" | ||
FilterTestCase = "" | ||
FilterTestList = "" | ||
Run = [] | ||
ListTests = false | ||
WorkingDirectory = "" | ||
} | ||
|
||
let Expecto (setParams : ExpectoParams -> ExpectoParams) (assemblies : string seq) = | ||
let args = setParams ExpectoParams.DefaultParams | ||
use __ = assemblies |> separated ", " |> traceStartTaskUsing "Expecto" | ||
let argsString = string args | ||
let runAssembly testAssembly = | ||
let processTimeout = TimeSpan.MaxValue // Don't set a process timeout. The timeout is per test. | ||
let workingDir = | ||
if isNotNullOrEmpty args.WorkingDirectory | ||
then args.WorkingDirectory else DirectoryName testAssembly | ||
let exitCode = | ||
ExecProcess(fun info -> | ||
info.FileName <- testAssembly | ||
info.WorkingDirectory <- workingDir | ||
info.Arguments <- argsString | ||
) processTimeout | ||
testAssembly, exitCode | ||
let res = | ||
assemblies | ||
|> Seq.map runAssembly | ||
|> Seq.filter( snd >> (<>) 0) | ||
|> Seq.toList | ||
match res with | ||
| [] -> () | ||
| failedAssemblies -> | ||
failedAssemblies | ||
|> 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please trace the taskstart like in https://github.com/fsharp/FAKE/blob/master/src/app/FakeLib/DocFxHelper.fs#L45