Safe Haskell | Safe |
---|
Combinators for constructing properties.
- newtype Property = MkProperty {
- unProperty :: Gen Prop
- class Testable prop where
- property :: prop -> Property
- exhaustive :: prop -> Bool
- data Discard = Discard
- morallyDubiousIOProperty :: Testable prop => IO prop -> Property
- ioProperty :: Testable prop => IO prop -> Property
- protect :: (AnException -> a) -> IO a -> IO a
- newtype Prop = MkProp {}
- data Rose a
- ioRose :: IO (Rose Result) -> Rose Result
- joinRose :: Rose (Rose a) -> Rose a
- reduceRose :: Rose Result -> IO (Rose Result)
- onRose :: (a -> [Rose a] -> Rose a) -> Rose a -> Rose a
- protectRose :: IO (Rose Result) -> IO (Rose Result)
- protectResults :: Rose Result -> Rose Result
- data Callback
- = PostTest CallbackKind (State -> Result -> IO ())
- | PostFinalFailure CallbackKind (State -> Result -> IO ())
- data CallbackKind
- data Result = MkResult {}
- result :: Result
- exception :: String -> AnException -> Result
- formatException :: String -> AnException -> String
- protectResult :: IO Result -> IO Result
- succeeded :: Result
- failed :: Result
- rejected :: Result
- liftBool :: Bool -> Result
- mapResult :: Testable prop => (Result -> Result) -> prop -> Property
- mapTotalResult :: Testable prop => (Result -> Result) -> prop -> Property
- mapRoseResult :: Testable prop => (Rose Result -> Rose Result) -> prop -> Property
- mapProp :: Testable prop => (Prop -> Prop) -> prop -> Property
- mapSize :: Testable prop => (Int -> Int) -> prop -> Property
- shrinking :: Testable prop => (a -> [a]) -> a -> (a -> prop) -> Property
- noShrinking :: Testable prop => prop -> Property
- callback :: Testable prop => Callback -> prop -> Property
- counterexample :: Testable prop => String -> prop -> Property
- printTestCase :: Testable prop => String -> prop -> Property
- whenFail :: Testable prop => IO () -> prop -> Property
- whenFail' :: Testable prop => IO () -> prop -> Property
- verbose :: Testable prop => prop -> Property
- expectFailure :: Testable prop => prop -> Property
- once :: Testable prop => prop -> Property
- label :: Testable prop => String -> prop -> Property
- collect :: (Show a, Testable prop) => a -> prop -> Property
- classify :: Testable prop => Bool -> String -> prop -> Property
- cover :: Testable prop => Bool -> Int -> String -> prop -> Property
- (==>) :: Testable prop => Bool -> prop -> Property
- within :: Testable prop => Int -> prop -> Property
- forAll :: (Show a, Testable prop) => Gen a -> (a -> prop) -> Property
- forAllShrink :: (Show a, Testable prop) => Gen a -> (a -> [a]) -> (a -> prop) -> Property
- (.&.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property
- (.&&.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property
- conjoin :: Testable prop => [prop] -> Property
- (.||.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property
- disjoin :: Testable prop => [prop] -> Property
- (===) :: (Eq a, Show a) => a -> a -> Property
Property and Testable types
class Testable prop whereSource
The class of things which can be tested, i.e. turned into a property.
If a property returns Discard
, the current test case is discarded,
the same as if a precondition was false.
morallyDubiousIOProperty :: Testable prop => IO prop -> PropertySource
Deprecated: Use ioProperty instead
Do I/O inside a property. This can obviously lead to unrepeatable testcases, so use with care.
ioProperty :: Testable prop => IO prop -> PropertySource
Do I/O inside a property. This can obviously lead to unrepeatable testcases, so use with care.
For more advanced monadic testing you may want to look at Test.QuickCheck.Monadic.
Exception handling
protect :: (AnException -> a) -> IO a -> IO aSource
Type Prop
type Rose
Result type
Different kinds of callbacks
PostTest CallbackKind (State -> Result -> IO ()) | Called just after a test |
PostFinalFailure CallbackKind (State -> Result -> IO ()) | Called with the final failing test-case |
data CallbackKind Source
Counterexample | Affected by the |
NotCounterexample | Not affected by the |
The result of a single test.
MkResult | |
|
exception :: String -> AnException -> ResultSource
formatException :: String -> AnException -> StringSource
Lifting and mapping functions
Property combinators
mapSize :: Testable prop => (Int -> Int) -> prop -> PropertySource
Changes the maximum test case size for a property.
:: Testable prop | |
=> (a -> [a]) |
|
-> a | The original argument |
-> (a -> prop) | |
-> Property |
Shrinks the argument to property if it fails. Shrinking is done automatically for most types. This is only needed when you want to override the default behavior.
noShrinking :: Testable prop => prop -> PropertySource
Disables shrinking for a property altogether.
counterexample :: Testable prop => String -> prop -> PropertySource
Adds the given string to the counterexample.
printTestCase :: Testable prop => String -> prop -> PropertySource
Deprecated: Use counterexample instead
Adds the given string to the counterexample.
whenFail :: Testable prop => IO () -> prop -> PropertySource
Performs an IO
action after the last failure of a property.
whenFail' :: Testable prop => IO () -> prop -> PropertySource
Performs an IO
action every time a property fails. Thus,
if shrinking is done, this can be used to keep track of the
failures along the way.
verbose :: Testable prop => prop -> PropertySource
Prints out the generated testcase every time the property is tested.
Only variables quantified over inside the verbose
are printed.
expectFailure :: Testable prop => prop -> PropertySource
Indicates that a property is supposed to fail. QuickCheck will report an error if it does not fail.
once :: Testable prop => prop -> PropertySource
Modifies a property so that it only will be tested once.
label :: Testable prop => String -> prop -> PropertySource
Attaches a label to a property. This is used for reporting test case distribution.
collect :: (Show a, Testable prop) => a -> prop -> PropertySource
Labels a property with a value:
collect x = label (show x)
:: Testable prop | |
=> Bool |
|
-> String | Label. |
-> prop | |
-> Property |
Conditionally labels test case.
:: Testable prop | |
=> Bool |
|
-> Int | The required percentage (0-100) of test cases. |
-> String | Label for the test case class. |
-> prop | |
-> Property |
Checks that at least the given proportion of the test cases belong to the given class.
(==>) :: Testable prop => Bool -> prop -> PropertySource
Implication for properties: The resulting property holds if
the first argument is False
(in which case the test case is discarded),
or if the given property holds.
within :: Testable prop => Int -> prop -> PropertySource
Considers a property failed if it does not complete within the given number of microseconds.
forAll :: (Show a, Testable prop) => Gen a -> (a -> prop) -> PropertySource
Explicit universal quantification: uses an explicitly given test case generator.
forAllShrink :: (Show a, Testable prop) => Gen a -> (a -> [a]) -> (a -> prop) -> PropertySource
Like forAll
, but tries to shrink the argument for failing test cases.
(.&.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> PropertySource
Nondeterministic choice: p1
.&.
p2
picks randomly one of
p1
and p2
to test. If you test the property 100 times it
makes 100 random choices.
(.&&.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> PropertySource
Conjunction: p1
.&&.
p2
passes if both p1
and p2
pass.