quickcheck-with-counterexamples: Get counterexamples from QuickCheck as Haskell values

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain]

When QuickCheck finds a counterexample, it prints it out but doesn't save it so that the programmer can access it. This can be annoying when debugging.

This library provides a small extension to QuickCheck that returns counterexamples as normal Haskell values. To use it, just import Test.QuickCheck.Counterexamples instead of Test.QuickCheck. The library is largely compatible with normal QuickCheck, but the return types of Test.QuickCheck.Counterexamples.quickCheck and related functions are changed to include a counterexample.

For usage information, see the Test.QuickCheck.Counterexamples module.


[Skip to ReadMe]

Properties

Versions1.0, 1.1, 1.1
Change logNone available
Dependenciesbase (==4.*), QuickCheck (>=2.12), template-haskell [details]
LicenseBSD-3-Clause
AuthorNick Smallbone
Maintainernick@smallbone.se
CategoryTesting
Home pagehttp://www.github.com/nick8325/quickcheck-with-counterexamples
Source repositoryhead: git clone https://github.com/nick8325/quickcheck-with-counterexamples
this: git clone https://github.com/nick8325/quickcheck-with-counterexamples(tag 1.0)
UploadedMon Sep 3 07:42:49 UTC 2018 by NickSmallbone

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees


Readme for quickcheck-with-counterexamples-1.1

[back to package description]
When QuickCheck finds a counterexample, it prints it out but
doesn't save it so that the programmer can access it. This can be
annoying when debugging.

This library provides a small extension to QuickCheck that returns
counterexamples as normal Haskell values. To use it, just import
Test.QuickCheck.Counterexamples instead of Test.QuickCheck.
The library is largely compatible with normal QuickCheck, but the
return types of quickCheck and related functions are changed to
include a counterexample.

Here is an example of getting counterexamples.
Suppose we have the following property:

prop_reverse_append :: [Int] -> [Int] -> Property
prop_reverse_append xs ys =
  reverse (xs++ys) === reverse xs ++ reverse ys

If we look at the type of quickCheck, we see that it will return a
counterexample:

> :t quickCheck prop_reverse_append
quickCheck prop_reverse_append :: IO (Maybe ([Int] :&: [Int] :&: ()))

The Maybe is there because we get Nothing if the property succeeds;
":&:" is a datatype of pairs.

If we run QuickCheck, we can get the counterexample as a normal
Haskell value:

> Just (xs :&: ys :&: ()) <- quickCheck prop_reverse_append
*** Failed! Falsifiable (after 5 tests and 4 shrinks):    
[0]
[1]
[1,0] /= [0,1]

> :t xs
xs :: [Int]

> xs
[0]

> ys
[1]