idris2-hedgehog icon indicating copy to clipboard operation
idris2-hedgehog copied to clipboard

Trivial test case is run 100 times

Open joelberkeley opened this issue 3 years ago • 3 comments
trafficstars

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?

joelberkeley avatar Apr 11 '22 22:04 joelberkeley

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).

stefan-hoeck avatar Apr 12 '22 04:04 stefan-hoeck

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

joelberkeley avatar Apr 12 '22 10:04 joelberkeley

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.

stefan-hoeck avatar Apr 18 '22 08:04 stefan-hoeck