Skip to content

Commit

Permalink
Show fscheck num tests and distribution on test pass (haf#514)
Browse files Browse the repository at this point in the history
* Allow quietOnSuccess and maxRejected fscheck config

* Allow tests to pass with a message

* Docs for `passedWithMessage`

* Show number of tests and stamps on fscheck test pass

* Revert "Show number of tests and stamps on fscheck test pass"

This reverts commit 40cbf98.

* Revert "Docs for `passedWithMessage`"

This reverts commit ae8a68e.

* Revert "Allow tests to pass with a message"

This reverts commit 8d765df.

* Add logger field to fscheck config

* Log number of tests and test distribution on property test pass

* Add fscheck test data to `FsCheckConfig.finishedTest`

* Revert "Log number of tests and test distribution on property test pass"

This reverts commit 47d15bb.

* Revert "Add logger field to fscheck config"

This reverts commit 37098eb.

* Update RELEASE_NOTES.md and README.md

* Revert old changes: maxRejected, quietOnSuccess, replay
  • Loading branch information
rynoV authored Feb 13, 2025
1 parent 63c9433 commit 56c9ff5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
15 changes: 14 additions & 1 deletion Expecto.FsCheck/FsCheck.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions Expecto.FsCheck3/FsCheck3.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions Expecto/Model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ type SourceLocation =
{ sourcePath: string; lineNumber: int }
static member empty = { sourcePath = ""; lineNumber = 0 }

type FsCheckTestData =
{ Labels: Set<string>
NumberOfShrinks: int
NumberOfTests: int
Stamps: seq<int * list<string>> }

type FsCheckConfig =
/// The maximum number of tests that are run.
{ maxTest: int
Expand Down Expand Up @@ -36,6 +42,7 @@ type FsCheckConfig =
/// Callback when the test case has finished
finishedTest: FsCheckConfig
-> (* test name *) string
-> FsCheckTestData
-> Async<unit>
}

Expand All @@ -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.
Expand Down Expand Up @@ -127,4 +134,3 @@ type private TestNameHolder() =
static member Name
with get () = TestNameHolder.name
and set name = TestNameHolder.name <- name

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ type FsCheckConfig =
/// Callback when the test case has finished
finishedTest: FsCheckConfig
-> (* test name *) string
-> FsCheckTestData
-> Async<unit>
}
```
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-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
Expand Down

0 comments on commit 56c9ff5

Please sign in to comment.