diff --git a/CHANGELOG.md b/CHANGELOG.md index 81d6b2d4..803435cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## Version ? - Rename `Property.failOnFalse` to `Property.falseToFailure` ([#384][384], [@TysonMN][TysonMN]) +- 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`. Now this results in a return type of `Property`. The previous behavior can now be expressed by piping the `Property` instance into `Property.falseToFailure`. ## Version 0.11.1 (2021-11-19) @@ -188,6 +190,8 @@ https://github.com/hedgehogqa/fsharp-hedgehog/pull/381 [380]: https://github.com/hedgehogqa/fsharp-hedgehog/pull/380 +[364]: + https://github.com/hedgehogqa/fsharp-hedgehog/pull/364 [363]: https://github.com/hedgehogqa/fsharp-hedgehog/pull/363 [362]: diff --git a/src/Hedgehog/Property.fs b/src/Hedgehog/Property.fs index 5f239072..aadf1640 100644 --- a/src/Hedgehog/Property.fs +++ b/src/Hedgehog/Property.fs @@ -310,6 +310,12 @@ module PropertyBuilder = member __.Return(b : bool) : Property = Property.ofBool b + member __.BindReturn(m : Gen<'a>, f: 'a -> 'b) = + m + |> Gen.map (fun a -> (Journal.empty, Success a)) + |> Property.ofGen + |> Property.map f + member __.ReturnFrom(m : Property<'a>) : Property<'a> = m diff --git a/tests/Hedgehog.Benchmarks/Program.fs b/tests/Hedgehog.Benchmarks/Program.fs index 08973ded..11c1fe2a 100644 --- a/tests/Hedgehog.Benchmarks/Program.fs +++ b/tests/Hedgehog.Benchmarks/Program.fs @@ -15,6 +15,7 @@ type Benchmarks () = let! i = Gen.int32 (Range.constant 0 10000) return i >= 0 } + |> Property.falseToFailure |> Property.check [] @@ -23,6 +24,7 @@ type Benchmarks () = let! i = Gen.string (Range.constant 0 100) Gen.ascii return i.Length >= 0 } + |> Property.falseToFailure |> Property.check [] diff --git a/tests/Hedgehog.Tests/GenTests.fs b/tests/Hedgehog.Tests/GenTests.fs index 05a49487..e4f4a4b0 100644 --- a/tests/Hedgehog.Tests/GenTests.fs +++ b/tests/Hedgehog.Tests/GenTests.fs @@ -82,6 +82,7 @@ let genTests = testList "Gen tests" [ let! _ = Gen.int64 (Range.exponentialBounded ()) return true } + |> Property.falseToFailure |> Property.check fableIgnore "uint64 can create exponentially bounded integer" <| fun _ -> @@ -89,6 +90,7 @@ let genTests = testList "Gen tests" [ let! _ = Gen.uint64 (Range.exponentialBounded ()) return true } + |> Property.falseToFailure |> Property.check testCase "apply is chainable" <| fun _ -> diff --git a/tests/Hedgehog.Tests/PropertyTests.fs b/tests/Hedgehog.Tests/PropertyTests.fs index afa047b9..40947a41 100644 --- a/tests/Hedgehog.Tests/PropertyTests.fs +++ b/tests/Hedgehog.Tests/PropertyTests.fs @@ -11,6 +11,7 @@ let propertyTests = testList "Property tests" [ let! xs = Range.singleton 0 |> Gen.int32 |> Gen.list (Range.singleton 5) |> Gen.map ResizeArray return false } + |> Property.falseToFailure |> Property.renderWith (PropertyConfig.withShrinks 0 PropertyConfig.defaultConfig) Expect.isNotMatch report "\.\.\." "Abbreviation (...) found" @@ -57,6 +58,7 @@ let propertyTests = testList "Property tests" [ let! opt = Gen.constant () |> Gen.option return opt |> Option.isSome } + |> Property.falseToFailure |> Property.report |> Report.render |> ignore diff --git a/tests/Hedgehog.Tests/ShrinkTests.fs b/tests/Hedgehog.Tests/ShrinkTests.fs index 3057be53..fee6a2ce 100644 --- a/tests/Hedgehog.Tests/ShrinkTests.fs +++ b/tests/Hedgehog.Tests/ShrinkTests.fs @@ -207,6 +207,7 @@ let shrinkTests = testList "Shrink tests" [ let! actual = Range.linear 1 1_000_000 |> Gen.int32 return actual < 500_000 } + |> Property.falseToFailure |> Property.reportWith propConfig match report.Status with | Failed failureData ->