nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
713 stars 119 forks source link

[Question / feature request] Inspect a Property, or expect a Property to always fail #320

Closed falsifian closed 5 months ago

falsifian commented 3 years ago

(Sorry, this would be more appropriate as a discussion forum post, but I couldn't find a forum for QuickCheck.)

I have implemented a new function returning Property and would like to test it. Some of my tests should assert that the Property fails in certain circumstances. Is there a way to do that?

expectFailure doesn't do what I want. For example, testProperty "XXX" (\ x y -> expectFailure (x == (y::Int))) passes, because x=y=0 is a counterexample for x==y. The combinator I'm looking for would cause that test to fail, because x == y does not always fail.

The implementation of Property is hidden, and I couldn't find any functions that inspect a Property in a way that would let me do what I want. Ideally I'd like to be able to inspect both the counterexample and whether the Property succeeded or not.

EDIT: By "counterexample" I mean the counterexample string. I'd like to check that it includes relevant values as a substring, to help the user figure out what went wrong.

MaximilianAlgehed commented 5 months ago

If your goal is to inspect the result of running quickCheck on a Property you can use quickCheckResult to obtain the Result that contains the information you're looking for in your final two paragraphs.

As for combinators for saying when you expect a property to fail, well that's really a case of writing your property so that it succeeds in those cases...