quickcheck-state-machine-0.2.0: Test monadic programs using state machine based models

Copyright(C) 2017 ATS Advanced Telematic Systems GmbH
LicenseBSD-style (see the file LICENSE)
MaintainerStevan Andjelkovic <stevan@advancedtelematic.com>
Stabilityprovisional
Portabilitynon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell2010

Test.StateMachine

Contents

Description

The main module for state machine based testing, it contains combinators that help you build sequential and parallel properties.

Synopsis

Sequential property combinators

data Program act Source #

A (sequential) program is an abstract datatype representing a list of actions.

The idea is that the user shows how to generate, shrink, execute and modelcheck individual actions, and then the below combinators lift those things to whole programs.

Instances

Eq (Internal act) => Eq (Program act) Source # 

Methods

(==) :: Program act -> Program act -> Bool #

(/=) :: Program act -> Program act -> Bool #

Read (Untyped act) => Read (Program act) Source # 
Show (Untyped act) => Show (Program act) Source # 

Methods

showsPrec :: Int -> Program act -> ShowS #

show :: Program act -> String #

showList :: [Program act] -> ShowS #

Monoid (Program act) Source # 

Methods

mempty :: Program act #

mappend :: Program act -> Program act -> Program act #

mconcat :: [Program act] -> Program act #

programLength :: Program act -> Int Source #

Returns the number of actions in a program.

forAllProgram Source #

Arguments

:: Show (Untyped act) 
=> HFoldable act 
=> Generator model act 
-> Shrinker act 
-> Precondition model act 
-> Transition model act 
-> InitialModel model 
-> (Program act -> Property)

Predicate that should hold for all programs.

-> Property 

This function is like a forAllShrink for sequential programs.

monadicSequential Source #

Arguments

:: Monad m 
=> Show (Untyped act) 
=> HFoldable act 
=> StateMachine' model act err m 
-> (Program act -> PropertyM m a)

Predicate that should hold for all programs.

-> Property 

Wrapper around forAllProgram using the StateMachine specification to generate and shrink sequential programs.

runProgram Source #

Arguments

:: Monad m 
=> Show (Untyped act) 
=> HTraversable act 
=> StateMachine' model act err m 
-> Program act 
-> PropertyM m (History act err, model Concrete, Property) 

Testable property of sequential programs derived from a StateMachine specification.

prettyProgram :: MonadIO m => Program act -> History act err -> model Concrete -> Property -> PropertyM m () Source #

Takes the output of running a program and pretty prints a counterexample if the run failed.

actionNames :: forall act. Constructors act => Program act -> [(Constructor, Int)] Source #

Returns the frequency of actions in a program.

checkActionNames :: Constructors act => Program act -> Property -> Property Source #

Print distribution of actions and fail if some actions have not been executed.

Parallel property combinators

data ParallelProgram act Source #

A parallel program is an abstract datatype that represents three sequences of actions; a sequential prefix and two parallel suffixes. Analogous to the sequential case, the user shows how to generate, shrink, execute and modelcheck individual actions, and then the below combinators lift those things to whole parallel programs.

forAllParallelProgram Source #

Arguments

:: Show (Untyped act) 
=> HFoldable act 
=> Generator model act 
-> Shrinker act 
-> Precondition model act 
-> Transition model act 
-> InitialModel model 
-> (ParallelProgram act -> Property)

Predicate that should hold for all parallel programs.

-> Property 

This function is like a forAllShrink for parallel programs.

data History act err Source #

A history is a trace of a program execution.

Instances

Monoid (History act err) Source # 

Methods

mempty :: History act err #

mappend :: History act err -> History act err -> History act err #

mconcat :: [History act err] -> History act err #

monadicParallel Source #

Arguments

:: MonadBaseControl IO m 
=> Show (Untyped act) 
=> HFoldable act 
=> StateMachine' model act err m 
-> (ParallelProgram act -> PropertyM m ())

Predicate that should hold for all parallel programs.

-> Property 

Wrapper around forAllParallelProgram using the StateMachine specification to generate and shrink parallel programs.

runParallelProgram Source #

Arguments

:: MonadBaseControl IO m 
=> Show (Untyped act) 
=> HTraversable act 
=> StateMachine' model act err m 
-> ParallelProgram act 
-> PropertyM m [(History act err, Property)] 

Testable property of parallel programs derived from a StateMachine specification.

runParallelProgram' Source #

Arguments

:: MonadBaseControl IO m 
=> Show (Untyped act) 
=> HTraversable act 
=> Int

How many times to execute the parallel program.

-> StateMachine' model act err m 
-> ParallelProgram act 
-> PropertyM m [(History act err, Property)] 

Same as above, but with the ability to choose how many times each parallel program is executed. It can be important to tune this value in order to reveal race conditions. The more runs, the more likely we will find a bug, but it also takes longer.

prettyParallelProgram Source #

Arguments

:: MonadIO m 
=> HFoldable act 
=> ParallelProgram act 
-> [(History act err, Property)]

Output of runParallelProgram.

-> PropertyM m () 

Takes the output of a parallel program runs and pretty prints a counter example if any of the runs fail.

With counterexamples

forAllProgramC Source #

Arguments

:: Show (Untyped act) 
=> HFoldable act 
=> Generator model act 
-> Shrinker act 
-> Precondition model act 
-> Transition model act 
-> InitialModel model 
-> (Program act -> PropertyOf a)

Predicate that should hold for all programs.

-> PropertyOf (Program act :&: a) 

Variant of forAllProgram which returns the generated and shrunk program if the property fails.

monadicSequentialC Source #

Arguments

:: Monad m 
=> Show (Untyped act) 
=> HFoldable act 
=> StateMachine' model act err m 
-> (Program act -> PropertyM m a)

Predicate that should hold for all programs.

-> PropertyOf (Program act) 

Variant of monadicSequential with counterexamples.

forAllParallelProgramC Source #

Arguments

:: Show (Untyped act) 
=> HFoldable act 
=> Generator model act 
-> Shrinker act 
-> Precondition model act 
-> Transition model act 
-> InitialModel model 
-> (ParallelProgram act -> PropertyOf a)

Predicate that should hold for all parallel programs.

-> PropertyOf (ParallelProgram act :&: a) 

Variant of forAllParallelProgram which returns the generated and shrunk program if the property fails.

monadicParallelC Source #

Arguments

:: MonadBaseControl IO m 
=> Show (Untyped act) 
=> HFoldable act 
=> StateMachine' model act err m 
-> (ParallelProgram act -> PropertyM m ())

Predicate that should hold for all parallel programs.

-> PropertyOf (ParallelProgram act) 

Variant of monadicParallel with counterexamples.

Types

Reexport

quickCheck :: Testable prop => prop -> IO () #

Tests a property and prints the results to stdout.