idris2-hedgehog
idris2-hedgehog copied to clipboard
Trivial test case is run 100 times
The following test case that doesn't use a Gen is run 100 times
test : Property
test = property $ 0 === 0
The following does the same
test : Property
test = property $ do
x <- forAll $ constant 0
x === x
This is problematic when testing fixed values, and prohibitive for expensive tests. I don't know if this is the right way to test fixed values, but should this not pass after a single run?
I have to think about this. Right now, Property is just a wrapper around PropertyT (), which is itself a wrapper around
EitherT Failure (WriterT Journal Gen) ()
So, even if you don't use a Gen in your property, it is still there in the type. However, for the time being, you can solve your issue with the following workaround:
export
property1 : PropertyT () -> Property
property1 = withTests 1 . property
prop : Property
prop = property1 $ the Nat 0 === 0
main : IO ()
main = test $ [ MkGroup "foo" [("test", prop)] ]
This will run the test only once, even if you explicitly set the number successes required with build/exec/test -n 1000 (withTests 1 is treated specially in that regard because this is a common use case).
Thanks stefan. I should have looked for that. Definitely does what I need. I can see the general problem could be worth considering at some point
Just for your info: I am working on a larger update where it is possible to run single tests (pure ones and tests running in IO). A PR will follow in the next couple of days.