Skip to content

Commit

Permalink
Merge pull request #395 from vilinski/list-pending-tests
Browse files Browse the repository at this point in the history
add options to list focused tests
  • Loading branch information
haf authored Nov 5, 2020
2 parents 965fd07 + 26c5565 commit 2733bea
Show file tree
Hide file tree
Showing 8 changed files with 559 additions and 510 deletions.
988 changes: 494 additions & 494 deletions .paket/Paket.Restore.targets

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Expecto.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ let expecto =
"--filter-test-case"; "f case"
"--run"; "a"; "b"; "c"
"--list-tests"
"--list-tests"; "normal"; "FOCUSED"; "Pending"
"--summary"
"--version"
"--summary-location"
Expand All @@ -515,7 +516,8 @@ let expecto =
Filter_Test_List "f list"
Filter_Test_Case "f case"
Run ["a";"b";"c"]
List_Tests
List_Tests []
List_Tests [Normal; Focused; Pending]
Summary
Version
Summary_Location
Expand Down Expand Up @@ -1665,4 +1667,4 @@ let cancel =
)
}
)
]
]
4 changes: 2 additions & 2 deletions Expecto/CSharp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module Runner =
let RunTestsWithCLIArgs(cliArgs, args, tests) = runTestsWithCLIArgs cliArgs args tests
let RunTestsInAssembly(config, args) = runTestsInAssembly config args
let RunTestsInAssemblyWithCLIArgs(cliArgs, args) = runTestsInAssemblyWithCLIArgs cliArgs args
let ListTests(tests) = listTests tests
let ListTests(config, tests) = listTests config tests
let TestList(name, tests: IEnumerable<Test>) = testList name (List.ofSeq tests)
[<CompiledName("TestCase")>]
let TestCaseA(name, test: System.Action) = testCase name test.Invoke
Expand Down Expand Up @@ -242,4 +242,4 @@ type Function() =
a)
message
result <- r
b
b
3 changes: 3 additions & 0 deletions Expecto/Expecto.Impl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ module Impl =
/// An optional filter function. Useful if you only would
/// like to run a subset of all the tests defined in your assembly.
filter : Test -> Test
/// List tests of specified state
listStates : FocusState list
/// Allows the test printer to be parametised to your liking.
printer : TestPrinters
/// Verbosity level (default: Info).
Expand Down Expand Up @@ -528,6 +530,7 @@ module Impl =
stressTimeout = TimeSpan.FromMinutes 5.0
stressMemoryLimit = 100.0
filter = id
listStates = []
failOnFocusedTests = false
printer =
let tc = Environment.GetEnvironmentVariable "TEAMCITY_PROJECT_NAME"
Expand Down
48 changes: 38 additions & 10 deletions Expecto/Expecto.fs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ module Tests =

let inline parse case: Parser<'a> = parseWith tryParse case
let inline number case: Parser<'a> = parseWith tryParseNumber case
let inline focusState case: Parser<'a> = parseWith tryParseFocusState case


[<ReferenceEquality>]
Expand Down Expand Up @@ -341,7 +342,7 @@ module Tests =
/// Runs only provided list of tests.
| Run of tests:string list
/// Don't run tests, but prints out list of tests instead.
| List_Tests
| List_Tests of listStates: FocusState list
/// Print out a summary after all tests are finished.
| Summary
/// Put an NUnit-like summary XML file at the given file.
Expand Down Expand Up @@ -383,7 +384,7 @@ module Tests =
"--filter-test-list", "Filters the list of test lists by a given substring.", Args.string Filter_Test_List
"--filter-test-case", "Filters the list of test cases by a given substring.", Args.string Filter_Test_Case
"--run", "Runs only provided list of tests.", Args.list Args.string Run
"--list-tests", "Don't run tests, but prints out list of tests instead.", Args.none List_Tests
"--list-tests", "Don't run tests, but prints out list of tests instead. Lists only tests with specified state(s), or all tests if not.", Args.list (Args.focusState) List_Tests
"--summary", "Print out a summary after all tests are finished.", Args.none Summary
"--nunit-summary", "Put an NUnit-like summary XML file at the given file.", Args.string NUnit_Summary
"--junit-summary", "Put a JUnit-like summary XML file at the given file.", Args.string JUnit_Summary
Expand Down Expand Up @@ -431,7 +432,7 @@ module Tests =
| Filter_Test_List name -> fun o -> {o with filter = Test.filter o.joinWith.asString (fun s -> s |> getTestList |> List.exists(fun s -> s.Contains name )) }
| Filter_Test_Case name -> fun o -> { o with filter = Test.filter o.joinWith.asString (fun s -> s |> getTestCase |> fun s -> s.Contains name )}
| Run tests -> fun o -> {o with filter = Test.filter o.joinWith.asString (fun s -> tests |> List.exists ((=) (o.joinWith.format s)) )}
| List_Tests -> id
| List_Tests states -> fun o -> { o with listStates = states }
| Summary -> fun o -> {o with printer = TestPrinters.summaryPrinter o.printer}
| NUnit_Summary path -> fun o -> o.AddNUnitSummary(path)
| JUnit_Summary path -> fun o -> o.AddJUnitSummary(path)
Expand Down Expand Up @@ -470,7 +471,7 @@ module Tests =
| Ok cliArguments ->
let config =
Seq.fold (fun s a -> foldCLIArgumentToConfig a s) baseConfig cliArguments
if List.contains List_Tests cliArguments then
if List.exists(function List_Tests _ -> true | _ -> false) cliArguments then
ArgsList config
elif List.contains Version cliArguments then
ArgsVersion config
Expand All @@ -484,9 +485,37 @@ module Tests =
ArgsUsage (Args.usage commandName options, errors)

/// Prints out names of all tests for given test suite.
let listTests (join: JoinWith) test =
Test.toTestCodeList test
|> Seq.iter (fun t -> printfn "%s" (join.format t.name))
let listTests config test =
let toStateChar state =
match state with
| Normal -> "N"
| Pending -> "P"
| Focused -> "F"

let tests =
Test.toTestCodeList test
|> Seq.filter(fun t -> List.isEmpty config.listStates ||
List.contains t.state config.listStates)
|> Seq.map(fun t -> toStateChar t.state, config.joinWith.format t.name)
|> Seq.toList

let hideState = tests |> List.exists(fun (stateChar,_) -> stateChar <> "N") |> not

let result = System.Text.StringBuilder()
tests
|> Seq.iter (fun (stateChar, name) ->
if hideState then
Printf.bprintf result "\n%s" name
else
Printf.bprintf result "\n%s %s" stateChar name
)
Printf.bprintf result "\n"

logger.logWithAck Info (
Message.eventX "{result}"
>> Message.setField "result" (string result)
)
|> Async.RunSynchronously

/// Prints out names of all tests for given test suite.
let duplicatedNames (join: JoinWith) test =
Expand Down Expand Up @@ -544,8 +573,7 @@ module Tests =
printfn "EXPECTO! v%s\n\n%s" expectoVersion usage
if List.isEmpty errors then 0 else 1
| ArgsList config ->
config.filter tests
|> listTests config.joinWith
listTests config tests
0
| ArgsRun config ->
runTestsWithCancel ct config tests
Expand Down Expand Up @@ -599,4 +627,4 @@ module Tests =
/// Runs tests in this assembly with the supplied command-line options.
/// Returns 0 if all tests passed, otherwise 1
let runTestsInAssemblyWithCLIArgs cliArgs args =
runTestsInAssemblyWithCLIArgsAndCancel CancellationToken.None cliArgs args
runTestsInAssemblyWithCLIArgsAndCancel CancellationToken.None cliArgs args
8 changes: 8 additions & 0 deletions Expecto/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ let matchFocusAttributes = function
| "Expecto.PTestsAttribute" -> Some (3, Pending)
| _ -> None

let inline tryParseFocusState (input: string) =
let inline (=~) (input : string) (value: string) =
input.Equals(value, StringComparison.OrdinalIgnoreCase)
if input =~ "focused" then Some Focused
elif input =~ "pending" then Some Pending
elif input =~ "normal" then Some Normal
else None

let allTestAttributes =
Set [
typeof<FTestsAttribute>.FullName
Expand Down
6 changes: 5 additions & 1 deletion Expecto/Logging.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,7 @@ type LiterateConsoleTarget(name, minLevel, ?options, ?literateTokeniser, ?output
let colourWriter = outputWriter |> Option.defaultWith (fun () ->
ANSIOutputWriter.prettyPrint (minLevel <= Debug) sem
)
let flush() = ANSIOutputWriter.flush()

/// Converts the message to tokens, apply the theme, then output them using the `colourWriter`.
let writeColourisedThenNewLine message =
Expand All @@ -1202,7 +1203,10 @@ type LiterateConsoleTarget(name, minLevel, ?options, ?literateTokeniser, ?output
member __.name = name
member __.logWithAck level msgFactory =
if level >= minLevel then
async { do writeColourisedThenNewLine (msgFactory level) }
async {
writeColourisedThenNewLine (msgFactory level)
flush()
}
else
async.Return ()
member __.log level msgFactory =
Expand Down
6 changes: 5 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### 9.0.3 - 2020-07-27
* List focused tests if failed using `--fail-on-focused-tests`, #392, thanks @vilinski
* Add an option to specify test states in `--list-tests`, thanks @vilinski

#### 9.0.2 - 2020-06-25
* An eta-expansion caused ABI compatibility for dependents, #388, thanks @haf

Expand All @@ -8,7 +12,7 @@
* Add `Expect.wantError`, which returns the value inside the Result wrapper if successful, thanks @yreynhout

#### 9.0.0 - 2020-04-04
* Change the default test separator to `.` (dot). Override back, using `--join-with /` Big thanks @MNie
* Change the default test separator to `.` (dot). Override back, using `--join-with /` Big thanks @MNie
* Add `Expect.wantSome` and `Expect.wantOk`, which returns the value inside the Option/Result wrapper if successful, thanks @teo-tsirpanis
* Remove deprecated PackageIconUrl from the build props, replace with PackageIcon, thanks @teo-tsirpanis
* Add cmd file for building on Windows, thanks @teo-tsirpanis
Expand Down

0 comments on commit 2733bea

Please sign in to comment.