You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If (say) an array is declared before the generator binds in a property computation expression, it doesn't get cleared when shrinking after a test failure. If the declaration is moved after the let! then it's ok.
This can produce misleading failure messages where the reported state is a combination of what happened during the shrinkage, not what caused the original failure.
As a (contrived) repro case, this test takes 10 integers and copies the distinct values into an array of int options. It then tests that the Some values are the sorted distinct values (so it fails).
letcopyIntoArray(target :array<_>)source =
source |> Array.iteri (fun i x -> target.[i]<- Some x)[<Test>]let``strange`` ()=
property {letbuffer= Array.zeroCreate 10let!input=
Gen.int (Range.constant 1100)|> Gen.array (Range.constant 1010)// Failure message is sensible if buffer is declared here instead// let buffer = Array.zeroCreate 10letactual=
input |> Array.distinct |> copyIntoArray buffer
buffer |> Array.choose id
letexpected=
input |> Array.distinct |> Array.sort
printfn "testing %A vs %A" actual expected
test <@ actual = expected @>}|> Property.check
During shrinkage, the input array is made shorter but the buffer array has items left-over. The output reads:
If (say) an array is declared before the generator binds in a property computation expression, it doesn't get cleared when shrinking after a test failure. If the declaration is moved after the
let!
then it's ok.This can produce misleading failure messages where the reported state is a combination of what happened during the shrinkage, not what caused the original failure.
As a (contrived) repro case, this test takes 10 integers and copies the distinct values into an array of int options. It then tests that the
Some
values are the sorted distinct values (so it fails).During shrinkage, the
input
array is made shorter but thebuffer
array has items left-over. The output reads:But if the buffer declaration is moved, the shrinkage works properly and the message reads:
Even if this is by-design behaviour, it might be worth noting it in the docs
The text was updated successfully, but these errors were encountered: