hedgehogqa / fsharp-hedgehog

Release with confidence, state-of-the-art property testing for .NET.
https://hedgehogqa.github.io/fsharp-hedgehog/
Other
271 stars 31 forks source link

`recheck` always fails #408

Closed dharmaturtle closed 1 year ago

dharmaturtle commented 2 years ago

I have the following test:

    testCase "my test" <| fun () ->
        property {
            let! i = Gen.int32 (Range.linear 1 10)
            Expect.isTrue (i <= 5)
        }
        |> Property.check

It fails (as expected) with the following error:

    *** Failed! Falsifiable (after 60 tests):
    6
    Expecto.AssertException: Should be true. Actual value was false but had expected it to be true.
       at Expecto.Expect.isTrue@397.Invoke(String msg)
       at Expecto.Expect.isTrue(Boolean actual, String message)
       at Hedgehog.Tests.TestDsl.Expect.isTrue(Boolean value) in C:\Code\fsharp-hedgehog\tests\Hedgehog.Tests\TestDsl.fs:line 38
       at Hedgehog.Tests.PropertyTests.propertyTests@103-30.Invoke(Int32 _arg8) in C:\Code\fsharp-hedgehog\tests\Hedgehog.Tests\PropertyTests.fs:line 103
       at Hedgehog.Property.kTry@88.Invoke(a a) in C:\Code\fsharp-hedgehog\src\Hedgehog\Property.fs:line 89
    This failure can be reproduced by running:
    > Property.recheck "59_15683818216235017248_6890634259096173777_" <property>

I plug the suggested recheck into the test:

    testCase "my test" <| fun () ->
        property {
            let! i = Gen.int32 (Range.linear 1 10)
            Expect.isTrue (i <= 5)
        }
        |> Property.recheck "59_15683818216235017248_6890634259096173777_"

It fails with


    *** Failed! Falsifiable (after 1 test):
    6
    Expecto.AssertException: Should be true. Actual value was false but had expected it to be true.
       at Expecto.Expect.isTrue@397.Invoke(String msg)
       at Expecto.Expect.isTrue(Boolean actual, String message)
       at Hedgehog.Tests.TestDsl.Expect.isTrue(Boolean value) in C:\Code\fsharp-hedgehog\tests\Hedgehog.Tests\TestDsl.fs:line 38
       at Hedgehog.Tests.PropertyTests.propertyTests@103-30.Invoke(Int32 _arg8) in C:\Code\fsharp-hedgehog\tests\Hedgehog.Tests\PropertyTests.fs:line 103
       at Hedgehog.Property.kTry@88.Invoke(a a) in C:\Code\fsharp-hedgehog\src\Hedgehog\Property.fs:line 89

Great! Let's now make the test pass (trivially):

    testCase "my test" <| fun () ->
        property {
            let! i = Gen.int32 (Range.linear 1 10)
            Expect.isTrue true
        }
        |> Property.recheck "59_15683818216235017248_6890634259096173777_"

But it doesn't pass!

    *** Failed! Falsifiable (after 1 test):
    6

Is this intended behavior?

TysonMN commented 2 years ago

No. The actual behavior is not the intended behavior. The behavior you expected in the intended behavior.

I have a guess about the cause of the bug. When rechecking, I might have assumed failure. Clearly I should not be assuming that.

AlexeyRaga commented 1 year ago

Bump! I stumbled upon the same issue where recheck always fails. Which is extremely misleading, and also brings a lot of frustration to my colleagues adopting property-based testing and Hedgehog.

TysonMN commented 1 year ago

Sorry! I will fix this now.

TysonMN commented 1 year ago

First included in version 0.13.0

TysonMN commented 1 year ago

Sorry everyone for how long I waited before fixing this bug. In hindsight, it was an easy fix. I was expecting it to be difficult, so I kept putting it off.