-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add withCounterexample
to get a re-useable handle on counterexamples
#376
Conversation
The thing I don't like here is the use of the word "counterexample" as that already has a meaning in QuickCheck. I'm very open to suggestion!! |
I like it! But also a while back I made a wrapper around QuickCheck which changes the API to have typed counterexamples: https://hackage.haskell.org/package/quickcheck-with-counterexamples So I don't know if we should: (1) merge your patch, (2) merge my thingy into main QuickCheck, (3) both. What do you think? Your approach is much simpler and has a far smaller API surface, but needs a bit more work from the user to use it (but maybe not so much). |
Maybe we can do both? What I would love is if you could use the result of QuickCheck failing to re-run the same property with the counterexample - or with the counterexample slightly modified. That would open up a whole new way of doing testing whereby you would both be able to recheck the property after fixing things, modify the counterexample you have to better understand what's causing the property to fail, etc. etc. With this light-weight approach we can get most of that given a bit of work from the user without changing the API much, but if we are willing to take the plunge on your approach that would allow us to make things much more seamless. To reduce the burden on the user of this approach I would try first of all to integrate it with Another thing I would like to try is splitting the implementation of Property so that the points of quantification are explicit, that way one could implement replaying a property given The third thing if we really want to take the plunge is to make the One might think that type indexing and wrapping things with existentials or similar could reduce the amount of type casting necessary to deal with replaying a counterexample, but I worry that won't be the case so long as we wish to keep the API at least somewhat similar. So to sum up my views: I like the fact that this is a conservative extension to the API, I really like your approach making things nice and typed and making all quantification points explicit and repayable with a counterexample, and I think we can figure out a way of getting the best of both worlds. We should just settle on a couple of questions:
|
I discovered a seriously cool feature in ghci that I didn't know about today. It appears it will resolve the type of existentially quantified variables with
Interestingly, it appears to only work for
It also doesn't work for data types defined in the shell, but it does work for data types defined in the source code. The cool thing about this is that it might allow us a fairly good middle ground between the strongly typed approach in your thing @nick8325 and a smaller API footprint while not making it a PITA to work with in ghci. I think that's pretty cool! |
Cool! A couple of comments for now!
|
I think you're right on the re-runnig point - with the current design of Property. But that can possibly change to include the binding-sites. On the second point I agree and I would put that change under an |
Regarding changing the Property type - this might require both existential quantification and might not be entirely feasible. For that reason I don't think it's immediately obvious it can be done without a massive headache. But we can investigate it / put it on the "maybe later" pile. |
I'm uhming and ahing a bit about the idea of putting We could also introduce the interface in |
add recheck to quickly re-test a property
118c9f9
to
1bad5f4
Compare
To avoid naming confusion I've renamed the new |
+1 to naming things Witness instead of Counterexample, and I'm pro this pull request in general, but some comments by way of bikeshedding:
Suggestion: we could get rid of one of
Then rather than |
Done. This is probably the least bad option. As per the docs on
|
The lack of actual values returned by
quickCheck
when a property fails has been a long standing friction. This PR introduces a simple combinatorwithCounterexample :: (Typeable a, Show a, Testable prop) => a -> prop -> Property
that lets you "export" data to theFailure
result of a property.closes #117
closes #310