From 85937851c5d961645dcb9dc5b1e1ba0e172e8106 Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Tue, 10 Sep 2024 12:19:55 -0600 Subject: [PATCH 1/3] Add option to skip printing skipped tests (#453) (cherry picked from commit 79f6e21881ae566036a22bbf0f1879454bf5784a) --- Expecto/Expecto.Impl.fs | 12 ++++++++++-- Expecto/Expecto.fs | 3 +++ RELEASE_NOTES.md | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Expecto/Expecto.Impl.fs b/Expecto/Expecto.Impl.fs index 7987a07d..a8b384df 100644 --- a/Expecto/Expecto.Impl.fs +++ b/Expecto/Expecto.Impl.fs @@ -498,6 +498,8 @@ module Impl = listStates : FocusState list /// Allows the test printer to be parametised to your liking. printer : TestPrinters + /// Whether to show skipped tests in the output. + printSkippedTests : bool /// Verbosity level (default: Info). verbosity : LogLevel /// Process name to log under (default: "Expecto") @@ -536,6 +538,7 @@ module Impl = TestPrinters.defaultPrinter else TestPrinters.teamCityPrinter TestPrinters.defaultPrinter + printSkippedTests = true verbosity = Info logName = None locate = fun _ -> SourceLocation.empty @@ -648,13 +651,18 @@ module Impl = let beforeEach (test:FlatTest) = let name = config.joinWith.format test.name - config.printer.beforeEach name + if config.printSkippedTests || test.shouldSkipEvaluation.IsNone then + config.printer.beforeEach name + else + async.Zero() async { let! beforeAsync = beforeEach test |> Async.StartChild let! result = execTestAsync ct config test do! beforeAsync - do! TestPrinters.printResult config test result + + if config.printSkippedTests || test.shouldSkipEvaluation.IsNone then + do! TestPrinters.printResult config test result if progressStarted && Option.isNone test.shouldSkipEvaluation then Fraction (Interlocked.Increment testsCompleted, testLength) diff --git a/Expecto/Expecto.fs b/Expecto/Expecto.fs index e8d6be2d..b0ba26c0 100644 --- a/Expecto/Expecto.fs +++ b/Expecto/Expecto.fs @@ -449,6 +449,8 @@ module Tests = | Colours of int /// Adds a test printer. | Printer of TestPrinters + /// Whether to show skipped tests in the output. + | PrintSkippedTests of bool /// Sets the verbosity level. | Verbosity of LogLevel /// Append a summary handler. @@ -540,6 +542,7 @@ module Tests = | _ -> JoinWith.Dot } | Printer p -> fun o -> { o with printer = p } + | PrintSkippedTests b -> fun o -> { o with printSkippedTests = b } | Verbosity l -> fun o -> { o with verbosity = l } | Append_Summary_Handler (SummaryHandler h) -> fun o -> o.appendSummaryHandler h diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 61192c29..319d2ef9 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +### 11.0.0-alpha4 - 2025-01-06 +* Add option to not print skipped tests + ### 11.0.0-alpha3 - 2024-10-13 * Add testParamAsync and testParamTask (#512), thanks @1eyewonder From af4ad6590c605001cdfa428097888f01cfd8d7c3 Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Mon, 13 Jan 2025 16:48:41 -0700 Subject: [PATCH 2/3] Add `isTestSkipped` argument to TestPrinters.beforeEach --- Expecto.Tests.CSharp/Tests.cs | 2 +- Expecto/CSharp.fs | 4 ++-- Expecto/Expecto.Impl.fs | 28 +++++++++++----------------- Expecto/Expecto.fs | 3 --- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/Expecto.Tests.CSharp/Tests.cs b/Expecto.Tests.CSharp/Tests.cs index a34f1150..cf7ad517 100644 --- a/Expecto.Tests.CSharp/Tests.cs +++ b/Expecto.Tests.CSharp/Tests.cs @@ -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; } diff --git a/Expecto/CSharp.fs b/Expecto/CSharp.fs index b238f627..f5a9646c 100644 --- a/Expecto/CSharp.fs +++ b/Expecto/CSharp.fs @@ -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 @@ -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 } diff --git a/Expecto/Expecto.Impl.fs b/Expecto/Expecto.Impl.fs index a8b384df..3c0b4674 100644 --- a/Expecto/Expecto.Impl.fs +++ b/Expecto/Expecto.Impl.fs @@ -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 - /// Called before atomic test (TestCode) is executed. - beforeEach: string -> Async + /// test name -> isTestSkipped -> unit. Called before a test is executed (when isTestSkipped = true) or skipped (when isTestSkipped = false) + beforeEach: string -> bool -> Async /// info info: string -> Async /// test name -> time taken -> unit @@ -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() @@ -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) @@ -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 ] } @@ -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 @@ -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) @@ -498,8 +498,6 @@ module Impl = listStates : FocusState list /// Allows the test printer to be parametised to your liking. printer : TestPrinters - /// Whether to show skipped tests in the output. - printSkippedTests : bool /// Verbosity level (default: Info). verbosity : LogLevel /// Process name to log under (default: "Expecto") @@ -538,7 +536,6 @@ module Impl = TestPrinters.defaultPrinter else TestPrinters.teamCityPrinter TestPrinters.defaultPrinter - printSkippedTests = true verbosity = Info logName = None locate = fun _ -> SourceLocation.empty @@ -651,18 +648,15 @@ module Impl = let beforeEach (test:FlatTest) = let name = config.joinWith.format test.name - if config.printSkippedTests || test.shouldSkipEvaluation.IsNone then - config.printer.beforeEach name - else - async.Zero() + + config.printer.beforeEach name <| Option.isSome test.shouldSkipEvaluation async { let! beforeAsync = beforeEach test |> Async.StartChild let! result = execTestAsync ct config test do! beforeAsync - if config.printSkippedTests || test.shouldSkipEvaluation.IsNone then - do! TestPrinters.printResult config test result + do! TestPrinters.printResult config test result if progressStarted && Option.isNone test.shouldSkipEvaluation then Fraction (Interlocked.Increment testsCompleted, testLength) diff --git a/Expecto/Expecto.fs b/Expecto/Expecto.fs index b0ba26c0..e8d6be2d 100644 --- a/Expecto/Expecto.fs +++ b/Expecto/Expecto.fs @@ -449,8 +449,6 @@ module Tests = | Colours of int /// Adds a test printer. | Printer of TestPrinters - /// Whether to show skipped tests in the output. - | PrintSkippedTests of bool /// Sets the verbosity level. | Verbosity of LogLevel /// Append a summary handler. @@ -542,7 +540,6 @@ module Tests = | _ -> JoinWith.Dot } | Printer p -> fun o -> { o with printer = p } - | PrintSkippedTests b -> fun o -> { o with printSkippedTests = b } | Verbosity l -> fun o -> { o with verbosity = l } | Append_Summary_Handler (SummaryHandler h) -> fun o -> o.appendSummaryHandler h From 60660b787ba95cabad599feeb125c0b8e14a6e7e Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Mon, 13 Jan 2025 17:34:01 -0700 Subject: [PATCH 3/3] Update RELEASE_NOTES.md --- RELEASE_NOTES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 1bf0f07c..18d8df60 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,5 @@ -### 11.0.0-alpha4 - 2025-01-13 -* Add option to not print skipped tests +### 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