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

Show fscheck num tests and distribution on test pass #514

Merged
merged 16 commits into from
Feb 13, 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
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
Loading