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 479c4c4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 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: 4 additions & 5 deletions src/Hedgehog/Property.fs
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,17 @@ module Property =
//

let private shrinkInput
(recheckType: RecheckType)
(data : RecheckData)
(recheckType: RecheckType option)
(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 = recheckType |> Option.map (fun rt -> { Type = rt; Data = recheckData })
}
match shrinkLimit, Seq.tryFind (Tree.outcome >> snd >> Outcome.isFailure) xs with
| Some shrinkLimit', _ when nshrinks >= shrinkLimit' -> failed
Expand Down Expand Up @@ -225,7 +224,7 @@ module Property =
let reportRecheckWith (recheckData: string) (config : PropertyConfig) (p : Property<unit>) : Report =
let args = {
PropertyArgs.init with
RecheckType = RecheckType.None
RecheckType = None
RecheckData = recheckData |> RecheckData.deserialize
}
p |> reportWith' args config
Expand Down
4 changes: 2 additions & 2 deletions src/Hedgehog/PropertyArgs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ namespace Hedgehog

[<Struct>]
type PropertyArgs = internal {
RecheckType : RecheckType
RecheckType : RecheckType option
RecheckData : RecheckData
}

module PropertyArgs =

let init = {
RecheckType = RecheckType.FSharp
RecheckType = Some RecheckType.FSharp
RecheckData = {
Size = 0
Seed = Seed.random ()
Expand Down
35 changes: 19 additions & 16 deletions src/Hedgehog/Report.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@ 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 =
| CSharp
| FSharp

[<RequireQualifiedAccess>]
type RecheckTypeData = {
Type : RecheckType
Data : RecheckData
}

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

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

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

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

| RecheckType.FSharp ->
| Some { Type = RecheckType.FSharp; Data = recheckData } ->
appendLinef sb "This failure can be reproduced by running:"
appendLinef sb "> Property.recheck \"%s\" <property>"
(RecheckData.serialize failure.RecheckData)

| RecheckType.CSharp ->
(RecheckData.serialize recheckData)
| Some { Type = RecheckType.CSharp; Data = 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 479c4c4

Please sign in to comment.