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

Add RecheckInfo to simplify recheck reporting #386

Merged
merged 1 commit into from
Dec 7, 2021
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
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 `RecheckInfo` 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
11 changes: 5 additions & 6 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)
(language: Language 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
RecheckInfo = language |> Option.map (fun lang -> { Language = lang; Data = recheckData })
}
match shrinkLimit, Seq.tryFind (Tree.outcome >> snd >> Outcome.isFailure) xs with
| Some shrinkLimit', _ when nshrinks >= shrinkLimit' -> failed
Expand Down Expand Up @@ -190,7 +189,7 @@ module Property =
| Failure ->
{ Tests = tests + 1<tests>
Discards = discards
Status = shrinkInput args.RecheckType data config.ShrinkLimit result }
Status = shrinkInput args.Language data config.ShrinkLimit result }
| Success () ->
loop nextData (tests + 1<tests>) discards
| Discard ->
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
Language = 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
Language : Language option
RecheckData : RecheckData
}

module PropertyArgs =

let init = {
RecheckType = RecheckType.FSharp
Language = Some Language.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
}
TysonMN marked this conversation as resolved.
Show resolved Hide resolved

[<RequireQualifiedAccess>]
type Language =
| CSharp
| FSharp
TysonMN marked this conversation as resolved.
Show resolved Hide resolved

[<RequireQualifiedAccess>]
type RecheckInfo = {
Language : Language
Data : RecheckData
}

type FailureData = {
RecheckData : RecheckData
Shrinks : int<shrinks>
Journal : Journal
RecheckType : RecheckType
RecheckInfo : RecheckInfo 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.RecheckInfo with
| None ->
()

| RecheckType.FSharp ->
| Some { Language = Language.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 { Language = Language.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