QuickCheck-2.4.1.1: Automatic testing of Haskell programsSource codeContentsIndex
Test.QuickCheck.Property
Contents
Property and Testable types
Exception handling
Type Prop
type Rose
Result type
Lifting and mapping functions
Property combinators
Synopsis
type Property = Gen Prop
class Testable prop where
property :: prop -> Property
morallyDubiousIOProperty :: Testable prop => IO prop -> Property
protect :: (AnException -> a) -> IO a -> IO a
newtype Prop = MkProp {
unProp :: Rose Result
}
data Rose a
= MkRose a [Rose a]
| IORose (IO (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
= Counterexample
| NotCounterexample
data Result = MkResult {
ok :: Maybe Bool
expect :: Bool
reason :: String
interrupted :: Bool
stamp :: [(String, Int)]
callbacks :: [Callback]
}
result :: Result
exception :: String -> AnException -> Result
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
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
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
Property and Testable types
type Property = Gen PropSource
class Testable prop whereSource
The class of things which can be tested, i.e. turned into a property.
Methods
property :: prop -> PropertySource
morallyDubiousIOProperty :: Testable prop => IO prop -> PropertySource
Do I/O inside a property. This can obviously lead to unrepeatable testcases, so use with care.
Exception handling
protect :: (AnException -> a) -> IO a -> IO aSource
Type Prop
newtype Prop Source
Constructors
MkProp
unProp :: Rose Result
type Rose
data Rose a Source
Constructors
MkRose a [Rose a]
IORose (IO (Rose a))
ioRose :: IO (Rose Result) -> Rose ResultSource
joinRose :: Rose (Rose a) -> Rose aSource
reduceRose :: Rose Result -> IO (Rose Result)Source
onRose :: (a -> [Rose a] -> Rose a) -> Rose a -> Rose aSource
protectRose :: IO (Rose Result) -> IO (Rose Result)Source
protectResults :: Rose Result -> Rose ResultSource
Result type
data Callback Source
Different kinds of callbacks
Constructors
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
Constructors
CounterexampleAffected by the verbose combinator
NotCounterexampleNot affected by the verbose combinator
data Result Source
The result of a single test.
Constructors
MkResult
ok :: Maybe Boolresult of the test case; Nothing = discard
expect :: Boolindicates what the expected result of the property is
reason :: Stringa message indicating what went wrong
interrupted :: Boolindicates if the test case was cancelled by pressing ^C
stamp :: [(String, Int)]the collected values for this test case
callbacks :: [Callback]the callbacks for this test case
result :: ResultSource
exception :: String -> AnException -> ResultSource
protectResult :: IO Result -> IO ResultSource
succeeded :: ResultSource
failed :: ResultSource
rejected :: ResultSource
Lifting and mapping functions
liftBool :: Bool -> ResultSource
mapResult :: Testable prop => (Result -> Result) -> prop -> PropertySource
mapTotalResult :: Testable prop => (Result -> Result) -> prop -> PropertySource
mapRoseResult :: Testable prop => (Rose Result -> Rose Result) -> prop -> PropertySource
mapProp :: Testable prop => (Prop -> Prop) -> prop -> PropertySource
Property combinators
mapSize :: Testable prop => (Int -> Int) -> prop -> PropertySource
Changes the maximum test case size for a property.
shrinkingSource
:: Testable prop
=> a -> [a]The original argument
-> a
-> 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.
callback :: Testable prop => Callback -> prop -> PropertySource
Adds a callback
printTestCase :: Testable prop => String -> prop -> PropertySource
Prints a message to the terminal as part of 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, like verboseCheck from QuickCheck 1. Only variables quantified over inside the verbose are printed.
expectFailure :: Testable prop => prop -> PropertySource
Modifies a property so that it is expected to fail for some test cases.
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)
classifySource
:: Testable prop
=> BoolLabel.
-> String
-> prop
-> Property
Conditionally labels test case.
coverSource
:: Testable prop
=> BoolThe required percentage (0-100) of test cases.
-> IntLabel for the test case class.
-> String
-> 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, 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.
conjoin :: Testable prop => [prop] -> PropertySource
Take the conjunction of several properties.
(.||.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> PropertySource
Disjunction: p1 .||. p2 passes unless p1 and p2 simultaneously fail.
disjoin :: Testable prop => [prop] -> PropertySource
Take the disjunction of several properties.
Produced by Haddock version 2.6.0