Skip to content

Commit

Permalink
Add RecheckTypeData to simplify recheck reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
TysonMN committed Dec 5, 2021
1 parent ee09c2b commit 0222b38
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Add `BindReturn` to the `property` CE ([#364][364], [@TysonMN][TysonMN])
- A breaking change. Previously, returning a `bool` from a `property` CE (after using `let!`) caused the CE to have return type `Property<unit>`. Now this results in a return type of `Property<bool>`. The previous behavior can now be expressed by piping the `Property<bool>` instance into `Property.falseToFailure`.
- Change recheck API to accept recheck data encoded as `string` ([#385][385], [@TysonMN][TysonMN])
- Add RecheckTypeData to simplify recheck reporting ([#386][386], [@TysonMN][TysonMN])

## Version 0.11.1 (2021-11-19)

Expand Down Expand Up @@ -183,6 +184,8 @@
[porges]:
https://github.com/porges

[386]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/386
[385]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/385
[384]:
Expand Down
9 changes: 6 additions & 3 deletions src/Hedgehog/Property.fs
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,20 @@ module Property =

let private shrinkInput
(recheckType: RecheckType)
(data : RecheckData)
(recheckData : RecheckData)
(shrinkLimit : int<shrinks> Option) =
let rec loop
(nshrinks : int<shrinks>)
(Node ((journal, _), xs) : Tree<Journal * Outcome<'a>>) =
let failed =
Failed {
RecheckData = data
Shrinks = nshrinks
Journal = journal
RecheckType = recheckType
RecheckTypeData =
match recheckType with
| RecheckType.FSharp -> RecheckTypeData.FSharp recheckData
| RecheckType.CSharp -> RecheckTypeData.CSharp recheckData
| RecheckType.None -> RecheckTypeData.None
}
match shrinkLimit, Seq.tryFind (Tree.outcome >> snd >> Outcome.isFailure) xs with
| Some shrinkLimit', _ when nshrinks >= shrinkLimit' -> failed
Expand Down
34 changes: 19 additions & 15 deletions src/Hedgehog/Report.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@ namespace Hedgehog
[<Measure>] type tests
[<Measure>] type discards
[<Measure>] type shrinks

[<RequireQualifiedAccess>]
type RecheckType =
| None
| CSharp
| FSharp


[<Struct>]
type RecheckData = internal {
Size : Size
Seed : Seed
}

[<RequireQualifiedAccess>]
type RecheckType =
| None
| CSharp
| FSharp

[<RequireQualifiedAccess>]
type RecheckTypeData =
| None
| CSharp of RecheckData
| FSharp of RecheckData

type FailureData = {
RecheckData : RecheckData
Shrinks : int<shrinks>
Journal : Journal
RecheckType : RecheckType
RecheckTypeData : RecheckTypeData
}

type Status =
Expand Down Expand Up @@ -117,19 +121,19 @@ module Report =

Seq.iter (appendLine sb) (Journal.eval failure.Journal)

match failure.RecheckType with
| RecheckType.None ->
match failure.RecheckTypeData with
| RecheckTypeData.None ->
()

| RecheckType.FSharp ->
| RecheckTypeData.FSharp recheckData ->
appendLinef sb "This failure can be reproduced by running:"
appendLinef sb "> Property.recheck \"%s\" <property>"
(RecheckData.serialize failure.RecheckData)
(RecheckData.serialize recheckData)

| RecheckType.CSharp ->
| RecheckTypeData.CSharp recheckData ->
appendLinef sb "This failure can be reproduced by running:"
appendLinef sb "> property.Recheck(\"%s\")"
(RecheckData.serialize failure.RecheckData)
(RecheckData.serialize recheckData)

sb.ToString().Trim() // Exclude extra newline.

Expand Down

0 comments on commit 0222b38

Please sign in to comment.