Skip to content

Commit 36b06f0

Browse files
authored
Merge pull request #415 from TysonMN/408_fix_recheck
408 fix recheck
2 parents 014635c + 5a97699 commit 36b06f0

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Version TBD
2+
3+
- Fix bug in `Property.recheck` where the result is always `Failed`. ([#415][415], [@TysonMN][TysonMN])
4+
15
## Version 0.12.1 (2021-12-31)
26

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

199+
[415]:
200+
https://github.com/hedgehogqa/fsharp-hedgehog/pull/415
195201
[401]:
196202
https://github.com/hedgehogqa/fsharp-hedgehog/pull/401
197203
[400]:

src/Hedgehog/Property.fs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,15 @@ module Property =
163163
let rec skipPassedChild children shrinkPath =
164164
match children, shrinkPath with
165165
| _, [] ->
166-
Failed {
167-
Shrinks = 0<shrinks>
168-
Journal = root.Value |> fst
169-
RecheckInfo = None
170-
}
166+
let journal, outcome = root.Value
167+
match outcome with
168+
| Failure ->
169+
{ Shrinks = 0<shrinks>
170+
Journal = journal
171+
RecheckInfo = None }
172+
|> Failed
173+
| Success _ -> OK
174+
| Discard -> failwith "Unexpected 'Discard' result when rechecking. This should never happen."
171175
| [], _ -> failwith "The shrink path lead to a dead end. This should never happen."
172176
| _ :: childrenTail, ShrinkOutcome.Pass :: shrinkPathTail -> skipPassedChild childrenTail shrinkPathTail
173177
| childrenHead :: _, ShrinkOutcome.Fail :: shrinkPathTail -> followShrinkPath childrenHead shrinkPathTail

tests/Hedgehog.Tests/PropertyTests.fs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,31 @@ let propertyTests = testList "Property tests" [
9797
count =! 1
9898
//render.Contains "actual: 1" =! true // comment out for now since it causes the Fable test to fail
9999

100+
101+
testCase "recheck passes after code is fixed" <| fun () ->
102+
let mutable b = false
103+
let prop =
104+
property {
105+
let! _ = Gen.bool
106+
Expect.isTrue b
107+
}
108+
109+
let report1 = Property.report prop
110+
match report1.Status with
111+
| OK -> failwith "Initial report should be Failed, not OK"
112+
| GaveUp -> failwith "Initial report should be Failed, not GaveUp"
113+
| Failed failure1 ->
114+
b <- true // "fix code"
115+
let report2 =
116+
Property.reportRecheck
117+
(RecheckData.serialize failure1.RecheckInfo.Value.Data)
118+
prop
119+
match report2.Status with
120+
| OK -> ()
121+
| GaveUp -> failwith "Recheck report should be OK, not GaveUp"
122+
| Failed _ -> failwith "Recheck report should be OK, not Failed"
123+
124+
100125
testCase "BindReturn adds value to Journal" <| fun () ->
101126
let actual =
102127
property {
@@ -107,9 +132,9 @@ let propertyTests = testList "Property tests" [
107132
|> Report.render
108133
|> (fun x -> x.Split ([|Environment.NewLine|], StringSplitOptions.None))
109134
|> Array.item 1
110-
111135
actual =! "false"
112136

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

0 commit comments

Comments
 (0)