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

408 fix recheck #415

Merged
merged 2 commits into from
Jul 23, 2022
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Version TBD

- Fix bug in `Property.recheck` where the result is always `Failed`. ([#415][415], [@TysonMN][TysonMN])

## Version 0.12.1 (2021-12-31)

- Add `Tree.apply`. Change `Gen.apply` from monadic to applicative. Revert runtime optimization of `Gen.integral`. ([#398][398], [@TysonMN][TysonMN])
Expand Down Expand Up @@ -192,6 +196,8 @@
[porges]:
https://github.com/porges

[415]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/415
[401]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/401
[400]:
Expand Down
14 changes: 9 additions & 5 deletions src/Hedgehog/Property.fs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,15 @@ module Property =
let rec skipPassedChild children shrinkPath =
match children, shrinkPath with
| _, [] ->
Failed {
Shrinks = 0<shrinks>
Journal = root.Value |> fst
RecheckInfo = None
}
let journal, outcome = root.Value
match outcome with
| Failure ->
{ Shrinks = 0<shrinks>
Journal = journal
RecheckInfo = None }
|> Failed
| Success _ -> OK
| Discard -> failwith "Unexpected 'Discard' result when rechecking. This should never happen."
| [], _ -> failwith "The shrink path lead to a dead end. This should never happen."
| _ :: childrenTail, ShrinkOutcome.Pass :: shrinkPathTail -> skipPassedChild childrenTail shrinkPathTail
| childrenHead :: _, ShrinkOutcome.Fail :: shrinkPathTail -> followShrinkPath childrenHead shrinkPathTail
Expand Down
27 changes: 26 additions & 1 deletion tests/Hedgehog.Tests/PropertyTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,31 @@ let propertyTests = testList "Property tests" [
count =! 1
//render.Contains "actual: 1" =! true // comment out for now since it causes the Fable test to fail


testCase "recheck passes after code is fixed" <| fun () ->
TysonMN marked this conversation as resolved.
Show resolved Hide resolved
let mutable b = false
let prop =
property {
let! _ = Gen.bool
Expect.isTrue b
}

let report1 = Property.report prop
match report1.Status with
| OK -> failwith "Initial report should be Failed, not OK"
| GaveUp -> failwith "Initial report should be Failed, not GaveUp"
| Failed failure1 ->
b <- true // "fix code"
let report2 =
Property.reportRecheck
(RecheckData.serialize failure1.RecheckInfo.Value.Data)
prop
match report2.Status with
| OK -> ()
| GaveUp -> failwith "Recheck report should be OK, not GaveUp"
| Failed _ -> failwith "Recheck report should be OK, not Failed"


testCase "BindReturn adds value to Journal" <| fun () ->
let actual =
property {
Expand All @@ -107,9 +132,9 @@ let propertyTests = testList "Property tests" [
|> Report.render
|> (fun x -> x.Split ([|Environment.NewLine|], StringSplitOptions.None))
|> Array.item 1

actual =! "false"


testCase "and! syntax is applicative" <| fun () ->
// Based on https://well-typed.com/blog/2019/05/integrated-shrinking/#:~:text=For%20example%2C%20consider%20the%20property%20that
let actual =
Expand Down