diff --git a/Expecto.FsCheck/FsCheck.fs b/Expecto.FsCheck/FsCheck.fs index 16cb674..13514d4 100644 --- a/Expecto.FsCheck/FsCheck.fs +++ b/Expecto.FsCheck/FsCheck.fs @@ -29,7 +29,20 @@ module ExpectoFsCheck = /// Called whenever all tests are done, either True, False or Exhausted. member __.OnFinished (fsCheckTestName, testResult) = - config.finishedTest config fsCheckTestName + let testData = + match testResult with + | TestResult.True(testData, _) -> testData + | TestResult.False(testData, _, _, _, _) -> testData + | TestResult.Exhausted testData -> testData + + let testData = { + FsCheckTestData.Stamps = testData.Stamps + NumberOfTests = testData.NumberOfTests + NumberOfShrinks = testData.NumberOfShrinks + Labels = testData.Labels + } + + config.finishedTest config fsCheckTestName testData |> Async.RunSynchronously let numTests i = if i = 1 then "1 test" else sprintf "%i tests" i diff --git a/Expecto.FsCheck3/FsCheck3.fs b/Expecto.FsCheck3/FsCheck3.fs index 39d948e..1bcc330 100644 --- a/Expecto.FsCheck3/FsCheck3.fs +++ b/Expecto.FsCheck3/FsCheck3.fs @@ -28,9 +28,21 @@ module ExpectoFsCheck = |> Async.RunSynchronously /// Called whenever all tests are done, either True, False or Exhausted. - member __.OnFinished (fsCheckTestName, testResult) = - config.finishedTest config fsCheckTestName - |> Async.RunSynchronously + member __.OnFinished(fsCheckTestName, testResult) = + let testData = + match testResult with + | TestResult.Passed(testData, _) -> testData + | TestResult.Failed(testData, _, _, _, _, _, _) -> testData + | TestResult.Exhausted testData -> testData + + let testData = { + FsCheckTestData.Stamps = testData.Stamps + NumberOfTests = testData.NumberOfTests + NumberOfShrinks = testData.NumberOfShrinks + Labels = testData.Labels + } + + config.finishedTest config fsCheckTestName testData |> Async.RunSynchronously let numTests i = if i = 1 then "1 test" else sprintf "%i tests" i diff --git a/Expecto/Model.fs b/Expecto/Model.fs index 401869b..c5f910e 100644 --- a/Expecto/Model.fs +++ b/Expecto/Model.fs @@ -8,6 +8,12 @@ type SourceLocation = { sourcePath: string; lineNumber: int } static member empty = { sourcePath = ""; lineNumber = 0 } +type FsCheckTestData = + { Labels: Set + NumberOfShrinks: int + NumberOfTests: int + Stamps: seq> } + type FsCheckConfig = /// The maximum number of tests that are run. { maxTest: int @@ -36,6 +42,7 @@ type FsCheckConfig = /// Callback when the test case has finished finishedTest: FsCheckConfig -> (* test name *) string + -> FsCheckTestData -> Async } @@ -47,7 +54,7 @@ type FsCheckConfig = arbitrary = [] receivedArgs = fun _ _ _ _ -> async.Return () successfulShrink = fun _ _ _ -> async.Return () - finishedTest = fun _ _ -> async.Return () + finishedTest = fun _ _ _ -> async.Return () } /// Actual test function; either an async one, or a synchronous one. @@ -127,4 +134,3 @@ type private TestNameHolder() = static member Name with get () = TestNameHolder.name and set name = TestNameHolder.name <- name - diff --git a/README.md b/README.md index 61c96d2..cf0b6d0 100644 --- a/README.md +++ b/README.md @@ -744,6 +744,7 @@ type FsCheckConfig = /// Callback when the test case has finished finishedTest: FsCheckConfig -> (* test name *) string + -> FsCheckTestData -> Async } ``` diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index ab7a3c5..98c2a2f 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +### 11.0.0-alpha6 - 2025-02-12 +* Add third argument to `FsCheckConfig.testFinished` containing information about the finished test. + ### 11.0.0-alpha5 - 2025-01-13 * Breaking Change: Add `isTestSkipped` parameter to `TestPrinters.beforeEach`, allowing to avoid printing skipped tests to the console, thanks @rynoV * Requires a coordinated upgrade to YoloDev.Expecto.TestSdk 0.15+ for use with Visual Studio, Rider, Ionide, dotnet test, or any other test runner that depends on the vstest adapter system