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

Add isTestSkipped to TestPrinters.beforeEach #516

Merged
merged 4 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Expecto.Tests.CSharp/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Test.CSharp
{
public class CSharpPrinter : ITestPrinter
{
Task ITestPrinter.BeforeEach(string value)
Task ITestPrinter.BeforeEach(string value, bool isTestSkipped)
{
return Task.CompletedTask;
}
Expand Down
4 changes: 2 additions & 2 deletions Expecto/CSharp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ open Expecto.Impl
// C# is weak and can't really handle Async or partial application
type ITestPrinter =
abstract member BeforeRun : Test -> Task
abstract member BeforeEach : string -> Task
abstract member BeforeEach : name: string * isTestSkipped: bool -> Task
abstract member Info : string -> Task
abstract member Passed : string * TimeSpan -> Task
abstract member Ignored : string * string -> Task
Expand All @@ -28,7 +28,7 @@ module Runner =

let private printerFromInterface (i : ITestPrinter) =
{ beforeRun = fun t -> async { return! i.BeforeRun(t) |> Async.AwaitTask }
beforeEach = fun s -> async { return! i.BeforeEach(s) |> Async.AwaitTask }
beforeEach = fun s e -> async { return! i.BeforeEach(s, e) |> Async.AwaitTask }
passed = fun n d -> async { return! i.Passed(n, d) |> Async.AwaitTask }
info = fun s -> async { return! i.Info(s) |> Async.AwaitTask }
ignored = fun n m -> async { return! i.Ignored(n, m) |> Async.AwaitTask }
Expand Down
20 changes: 11 additions & 9 deletions Expecto/Expecto.Impl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ module Impl =
type TestPrinters =
{ /// Called before a test run (e.g. at the top of your main function)
beforeRun: Test -> Async<unit>
/// Called before atomic test (TestCode) is executed.
beforeEach: string -> Async<unit>
/// test name -> isTestSkipped -> unit. Called before a test is executed (when isTestSkipped = true) or skipped (when isTestSkipped = false)
beforeEach: string -> bool -> Async<unit>
/// info
info: string -> Async<unit>
/// test name -> time taken -> unit
Expand All @@ -232,7 +232,7 @@ module Impl =

static member silent =
{ beforeRun = fun _ -> async.Zero()
beforeEach = fun _ -> async.Zero()
beforeEach = fun _ _ -> async.Zero()
info = fun _ -> async.Zero()
passed = fun _ _ -> async.Zero()
ignored = fun _ _ -> async.Zero()
Expand All @@ -244,7 +244,7 @@ module Impl =
{ beforeRun = fun _tests ->
logger.logWithAck Info (eventX "EXPECTO? Running tests...")

beforeEach = fun n ->
beforeEach = fun n _ ->
logger.logWithAck Debug (
eventX "{testName} starting..."
>> setField "testName" n)
Expand Down Expand Up @@ -404,8 +404,8 @@ module Impl =
tcLog "testSuiteStarted" [
"name", "ExpectoTestSuite" ] }

beforeEach = fun n -> async {
do! innerPrinter.beforeEach n
beforeEach = fun n e -> async {
do! innerPrinter.beforeEach n e
tcLog "testStarted" [
"flowId", formatName n
"name", formatName n ] }
Expand Down Expand Up @@ -439,7 +439,7 @@ module Impl =
"duration", d.TotalMilliseconds |> int |> string ] }

exn = fun n e d -> async {
do! innerPrinter.beforeEach n
do! innerPrinter.beforeEach n true
tcLog "testFailed" [
"flowId", formatName n
"name", formatName n
Expand All @@ -460,7 +460,7 @@ module Impl =
do! b
}
{ beforeRun = fun _tests -> runTwoAsyncs (first.beforeRun _tests) (second.beforeRun _tests)
beforeEach = fun n -> runTwoAsyncs (first.beforeEach n) (second.beforeEach n)
beforeEach = fun n e -> runTwoAsyncs (first.beforeEach n e) (second.beforeEach n e)
info = fun s -> runTwoAsyncs (first.info s) (second.info s)
passed = fun n d -> runTwoAsyncs (first.passed n d) (second.passed n d)
ignored = fun n m -> runTwoAsyncs (first.ignored n m) (second.ignored n m)
Expand Down Expand Up @@ -648,12 +648,14 @@ module Impl =

let beforeEach (test:FlatTest) =
let name = config.joinWith.format test.name
config.printer.beforeEach name

config.printer.beforeEach name <| Option.isSome test.shouldSkipEvaluation

async {
let! beforeAsync = beforeEach test |> Async.StartChild
let! result = execTestAsync ct config test
do! beforeAsync

do! TestPrinters.printResult config test result

if progressStarted && Option.isNone test.shouldSkipEvaluation then
Expand Down
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 11.0.0-alpha5 - 2025-01-13
* Add `isTestSkipped` parameter to `TestPrinters.beforeEach`, allowing to avoid printing skipped tests to the console

### 11.0.0-alpha4 - 2025-01-06
* Breaking change: Add third item to `FsCheckConfig.replay` indicating the size
* Fixes issue where the replay seed without the size was playing all tests leading up to the failure, making debugging
Expand Down
Loading