| Copyright | (C) 2017 ATS Advanced Telematic Systems GmbH |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Stevan Andjelkovic <stevan.andjelkovic@strath.ac.uk> |
| Stability | provisional |
| Portability | non-portable (GHC extensions) |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Test.StateMachine
Description
The main module for state machine based testing, it contains combinators that help you build sequential and parallel properties.
Synopsis
- forAllCommands :: Testable prop => (Show (cmd Symbolic), Show (resp Symbolic), Show (model Symbolic)) => (Traversable cmd, Foldable resp) => StateMachine model cmd m resp -> Maybe Int -> (Commands cmd resp -> prop) -> Property
- existsCommands :: forall model cmd m resp prop. (Testable prop, Foldable resp) => (Show (model Symbolic), Show (cmd Symbolic), Show (resp Symbolic)) => StateMachine model cmd m resp -> [model Symbolic -> Gen (cmd Symbolic)] -> (Commands cmd resp -> prop) -> Property
- runCommands :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadIO m) => StateMachine model cmd m resp -> Commands cmd resp -> PropertyM m (History cmd resp, model Concrete, Reason)
- runCommandsWithSetup :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadIO m) => m (StateMachine model cmd m resp) -> Commands cmd resp -> PropertyM m (History cmd resp, model Concrete, Reason)
- prettyCommands :: (MonadIO m, CanDiff (model Concrete)) => (Show (cmd Concrete), Show (resp Concrete)) => StateMachine model cmd m resp -> History cmd resp -> Property -> PropertyM m ()
- prettyCommands' :: (MonadIO m, CanDiff (model Concrete), CanDiff [tag]) => (Show (cmd Concrete), Show (resp Concrete)) => StateMachine model cmd m resp -> ([Event model cmd resp Symbolic] -> [tag]) -> Commands cmd resp -> History cmd resp -> Property -> PropertyM m ()
- checkCommandNames :: forall cmd resp. CommandNames cmd => Commands cmd resp -> Property -> Property
- coverCommandNames :: forall cmd resp. CommandNames cmd => Commands cmd resp -> Property -> Property
- commandNames :: forall cmd resp. CommandNames cmd => Commands cmd resp -> [(String, Int)]
- commandNamesInOrder :: forall cmd resp. CommandNames cmd => Commands cmd resp -> [String]
- saveCommands :: (Show (cmd Symbolic), Show (resp Symbolic)) => FilePath -> Commands cmd resp -> Property -> Property
- runSavedCommands :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadIO m) => (Read (cmd Symbolic), Read (resp Symbolic)) => StateMachine model cmd m resp -> FilePath -> PropertyM m (Commands cmd resp, History cmd resp, model Concrete, Reason)
- showLabelledExamples :: (Show tag, Show (model Symbolic)) => (Show (cmd Symbolic), Show (resp Symbolic)) => (Traversable cmd, Foldable resp) => StateMachine model cmd m resp -> ([Event model cmd resp Symbolic] -> [tag]) -> IO ()
- showLabelledExamples' :: (Show tag, Show (model Symbolic)) => (Show (cmd Symbolic), Show (resp Symbolic)) => (Traversable cmd, Foldable resp) => StateMachine model cmd m resp -> Maybe Int -> Int -> ([Event model cmd resp Symbolic] -> [tag]) -> (tag -> Bool) -> IO ()
- noCleanup :: Monad m => model Concrete -> m ()
- forAllParallelCommands :: Testable prop => (Show (cmd Symbolic), Show (resp Symbolic), Show (model Symbolic)) => (Traversable cmd, Foldable resp) => StateMachine model cmd m resp -> Maybe Int -> (ParallelCommands cmd resp -> prop) -> Property
- forAllNParallelCommands :: Testable prop => (Show (cmd Symbolic), Show (resp Symbolic), Show (model Symbolic)) => (Traversable cmd, Foldable resp) => StateMachine model cmd m resp -> Int -> (NParallelCommands cmd resp -> prop) -> Property
- runNParallelCommands :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => StateMachine model cmd m resp -> NParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)]
- runNParallelCommandsWithSetup :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => m (StateMachine model cmd m resp) -> NParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)]
- runParallelCommands :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => StateMachine model cmd m resp -> ParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)]
- runParallelCommandsWithSetup :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => m (StateMachine model cmd m resp) -> ParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)]
- runParallelCommands' :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => m (StateMachine model cmd m resp) -> (cmd Concrete -> resp Concrete) -> ParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)]
- runParallelCommandsNTimes :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => Int -> StateMachine model cmd m resp -> ParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)]
- runParallelCommandsNTimesWithSetup :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => Int -> m (StateMachine model cmd m resp) -> ParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)]
- runNParallelCommandsNTimes' :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => Int -> m (StateMachine model cmd m resp) -> (cmd Concrete -> resp Concrete) -> NParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)]
- runParallelCommandsNTimes' :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => Int -> m (StateMachine model cmd m resp) -> (cmd Concrete -> resp Concrete) -> ParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)]
- runNParallelCommandsNTimes :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => Int -> StateMachine model cmd m resp -> NParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)]
- runNParallelCommandsNTimesWithSetup :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => Int -> m (StateMachine model cmd m resp) -> NParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)]
- prettyNParallelCommands :: (Show (cmd Concrete), Show (resp Concrete)) => MonadIO m => Foldable cmd => NParallelCommands cmd resp -> [(History cmd resp, a, Logic)] -> PropertyM m ()
- prettyParallelCommands :: (Show (cmd Concrete), Show (resp Concrete)) => MonadIO m => Foldable cmd => ParallelCommands cmd resp -> [(History cmd resp, a, Logic)] -> PropertyM m ()
- prettyParallelCommandsWithOpts :: (MonadIO m, Foldable cmd) => (Show (cmd Concrete), Show (resp Concrete)) => ParallelCommands cmd resp -> Maybe GraphOptions -> [(History cmd resp, a, Logic)] -> PropertyM m ()
- prettyNParallelCommandsWithOpts :: (Show (cmd Concrete), Show (resp Concrete)) => MonadIO m => Foldable cmd => NParallelCommands cmd resp -> Maybe GraphOptions -> [(History cmd resp, a, Logic)] -> PropertyM m ()
- checkCommandNamesParallel :: forall cmd resp t. Foldable t => CommandNames cmd => ParallelCommandsF t cmd resp -> Property -> Property
- coverCommandNamesParallel :: forall cmd resp t. Foldable t => CommandNames cmd => ParallelCommandsF t cmd resp -> Property -> Property
- commandNamesParallel :: forall cmd resp t. Foldable t => CommandNames cmd => ParallelCommandsF t cmd resp -> [(String, Int)]
- data StateMachine model cmd m resp = StateMachine (forall r. model r) (forall r. (Show1 r, Ord1 r) => model r -> cmd r -> resp r -> model r) (model Symbolic -> cmd Symbolic -> Logic) (model Concrete -> cmd Concrete -> resp Concrete -> Logic) (Maybe (model Concrete -> Logic)) (model Symbolic -> Maybe (Gen (cmd Symbolic))) (model Symbolic -> cmd Symbolic -> [cmd Symbolic]) (cmd Concrete -> m (resp Concrete)) (model Symbolic -> cmd Symbolic -> GenSym (resp Symbolic)) (model Concrete -> m ())
- data Concrete a
- data Symbolic a
- data Reference a r
- concrete :: Reference a Concrete -> a
- reference :: Typeable a => a -> Reference a Concrete
- newtype Opaque a = Opaque {
- unOpaque :: a
- opaque :: Reference (Opaque a) Concrete -> a
- data Reason
- data GenSym a
- genSym :: Typeable a => GenSym (Reference a Symbolic)
- class CommandNames (cmd :: k -> Type) where
- module Test.StateMachine.Logic
- class CanDiff x where
Sequential property combinators
Arguments
| :: forall model cmd m resp prop. (Testable prop, Foldable resp) | |
| => (Show (model Symbolic), Show (cmd Symbolic), Show (resp Symbolic)) | |
| => StateMachine model cmd m resp | |
| -> [model Symbolic -> Gen (cmd Symbolic)] | Generators. |
| -> (Commands cmd resp -> prop) | Predicate. |
| -> Property |
Generate commands from a list of generators.
runCommands :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadIO m) => StateMachine model cmd m resp -> Commands cmd resp -> PropertyM m (History cmd resp, model Concrete, Reason) Source #
runCommandsWithSetup :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadIO m) => m (StateMachine model cmd m resp) -> Commands cmd resp -> PropertyM m (History cmd resp, model Concrete, Reason) Source #
prettyCommands :: (MonadIO m, CanDiff (model Concrete)) => (Show (cmd Concrete), Show (resp Concrete)) => StateMachine model cmd m resp -> History cmd resp -> Property -> PropertyM m () Source #
prettyCommands' :: (MonadIO m, CanDiff (model Concrete), CanDiff [tag]) => (Show (cmd Concrete), Show (resp Concrete)) => StateMachine model cmd m resp -> ([Event model cmd resp Symbolic] -> [tag]) -> Commands cmd resp -> History cmd resp -> Property -> PropertyM m () Source #
Variant of prettyCommands that also prints the tags covered by each
command.
checkCommandNames :: forall cmd resp. CommandNames cmd => Commands cmd resp -> Property -> Property Source #
Print the percentage of each command used. The prefix check is an unfortunate remaining for backwards compatibility.
coverCommandNames :: forall cmd resp. CommandNames cmd => Commands cmd resp -> Property -> Property Source #
Fail if some commands have not been executed.
commandNames :: forall cmd resp. CommandNames cmd => Commands cmd resp -> [(String, Int)] Source #
commandNamesInOrder :: forall cmd resp. CommandNames cmd => Commands cmd resp -> [String] Source #
saveCommands :: (Show (cmd Symbolic), Show (resp Symbolic)) => FilePath -> Commands cmd resp -> Property -> Property Source #
runSavedCommands :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadIO m) => (Read (cmd Symbolic), Read (resp Symbolic)) => StateMachine model cmd m resp -> FilePath -> PropertyM m (Commands cmd resp, History cmd resp, model Concrete, Reason) Source #
showLabelledExamples :: (Show tag, Show (model Symbolic)) => (Show (cmd Symbolic), Show (resp Symbolic)) => (Traversable cmd, Foldable resp) => StateMachine model cmd m resp -> ([Event model cmd resp Symbolic] -> [tag]) -> IO () Source #
showLabelledExamples' Source #
Arguments
| :: (Show tag, Show (model Symbolic)) | |
| => (Show (cmd Symbolic), Show (resp Symbolic)) | |
| => (Traversable cmd, Foldable resp) | |
| => StateMachine model cmd m resp | |
| -> Maybe Int | Seed |
| -> Int | Number of tests to run to find examples |
| -> ([Event model cmd resp Symbolic] -> [tag]) | |
| -> (tag -> Bool) | Tag filter (can be |
| -> IO () |
Show minimal examples for each of the generated tags.
Parallel property combinators
forAllParallelCommands Source #
Arguments
| :: Testable prop | |
| => (Show (cmd Symbolic), Show (resp Symbolic), Show (model Symbolic)) | |
| => (Traversable cmd, Foldable resp) | |
| => StateMachine model cmd m resp | |
| -> Maybe Int | |
| -> (ParallelCommands cmd resp -> prop) | Predicate. |
| -> Property |
forAllNParallelCommands Source #
Arguments
| :: Testable prop | |
| => (Show (cmd Symbolic), Show (resp Symbolic), Show (model Symbolic)) | |
| => (Traversable cmd, Foldable resp) | |
| => StateMachine model cmd m resp | |
| -> Int | Number of threads |
| -> (NParallelCommands cmd resp -> prop) | Predicate. |
| -> Property |
runNParallelCommands :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => StateMachine model cmd m resp -> NParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)] Source #
runNParallelCommandsWithSetup :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => m (StateMachine model cmd m resp) -> NParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)] Source #
runParallelCommands :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => StateMachine model cmd m resp -> ParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)] Source #
runParallelCommandsWithSetup :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => m (StateMachine model cmd m resp) -> ParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)] Source #
runParallelCommands' :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadMask m, MonadUnliftIO m) => m (StateMachine model cmd m resp) -> (cmd Concrete -> resp Concrete) -> ParallelCommands cmd resp -> PropertyM m [(History cmd resp, model Concrete, Logic)] Source #
runParallelCommandsNTimes Source #
Arguments
| :: (Show (cmd Concrete), Show (resp Concrete)) | |
| => (Traversable cmd, Foldable resp) | |
| => (MonadMask m, MonadUnliftIO m) | |
| => Int | How many times to execute the parallel program. |
| -> StateMachine model cmd m resp | |
| -> ParallelCommands cmd resp | |
| -> PropertyM m [(History cmd resp, model Concrete, Logic)] |
runParallelCommandsNTimesWithSetup Source #
Arguments
| :: (Show (cmd Concrete), Show (resp Concrete)) | |
| => (Traversable cmd, Foldable resp) | |
| => (MonadMask m, MonadUnliftIO m) | |
| => Int | How many times to execute the parallel program. |
| -> m (StateMachine model cmd m resp) | |
| -> ParallelCommands cmd resp | |
| -> PropertyM m [(History cmd resp, model Concrete, Logic)] |
runNParallelCommandsNTimes' Source #
Arguments
| :: (Show (cmd Concrete), Show (resp Concrete)) | |
| => (Traversable cmd, Foldable resp) | |
| => (MonadMask m, MonadUnliftIO m) | |
| => Int | How many times to execute the parallel program. |
| -> m (StateMachine model cmd m resp) | |
| -> (cmd Concrete -> resp Concrete) | |
| -> NParallelCommands cmd resp | |
| -> PropertyM m [(History cmd resp, model Concrete, Logic)] |
runParallelCommandsNTimes' Source #
Arguments
| :: (Show (cmd Concrete), Show (resp Concrete)) | |
| => (Traversable cmd, Foldable resp) | |
| => (MonadMask m, MonadUnliftIO m) | |
| => Int | How many times to execute the parallel program. |
| -> m (StateMachine model cmd m resp) | |
| -> (cmd Concrete -> resp Concrete) | |
| -> ParallelCommands cmd resp | |
| -> PropertyM m [(History cmd resp, model Concrete, Logic)] |
runNParallelCommandsNTimes Source #
Arguments
| :: (Show (cmd Concrete), Show (resp Concrete)) | |
| => (Traversable cmd, Foldable resp) | |
| => (MonadMask m, MonadUnliftIO m) | |
| => Int | How many times to execute the parallel program. |
| -> StateMachine model cmd m resp | |
| -> NParallelCommands cmd resp | |
| -> PropertyM m [(History cmd resp, model Concrete, Logic)] |
runNParallelCommandsNTimesWithSetup Source #
Arguments
| :: (Show (cmd Concrete), Show (resp Concrete)) | |
| => (Traversable cmd, Foldable resp) | |
| => (MonadMask m, MonadUnliftIO m) | |
| => Int | How many times to execute the parallel program. |
| -> m (StateMachine model cmd m resp) | |
| -> NParallelCommands cmd resp | |
| -> PropertyM m [(History cmd resp, model Concrete, Logic)] |
prettyParallelCommandsWithOpts Source #
Arguments
| :: (MonadIO m, Foldable cmd) | |
| => (Show (cmd Concrete), Show (resp Concrete)) | |
| => ParallelCommands cmd resp | |
| -> Maybe GraphOptions | |
| -> [(History cmd resp, a, Logic)] | Output of |
| -> PropertyM m () |
Takes the output of parallel program runs and pretty prints a counterexample if any of the runs fail.
prettyNParallelCommandsWithOpts Source #
Arguments
| :: (Show (cmd Concrete), Show (resp Concrete)) | |
| => MonadIO m | |
| => Foldable cmd | |
| => NParallelCommands cmd resp | |
| -> Maybe GraphOptions | |
| -> [(History cmd resp, a, Logic)] | Output of |
| -> PropertyM m () |
Takes the output of parallel program runs and pretty prints a counterexample if any of the runs fail.
checkCommandNamesParallel :: forall cmd resp t. Foldable t => CommandNames cmd => ParallelCommandsF t cmd resp -> Property -> Property Source #
Print the percentage of each command used. The prefix check is an unfortunate remaining for backwards compatibility.
coverCommandNamesParallel :: forall cmd resp t. Foldable t => CommandNames cmd => ParallelCommandsF t cmd resp -> Property -> Property Source #
Fail if some commands have not been executed.
commandNamesParallel :: forall cmd resp t. Foldable t => CommandNames cmd => ParallelCommandsF t cmd resp -> [(String, Int)] Source #
Types
data StateMachine model cmd m resp Source #
Constructors
| StateMachine (forall r. model r) (forall r. (Show1 r, Ord1 r) => model r -> cmd r -> resp r -> model r) (model Symbolic -> cmd Symbolic -> Logic) (model Concrete -> cmd Concrete -> resp Concrete -> Logic) (Maybe (model Concrete -> Logic)) (model Symbolic -> Maybe (Gen (cmd Symbolic))) (model Symbolic -> cmd Symbolic -> [cmd Symbolic]) (cmd Concrete -> m (resp Concrete)) (model Symbolic -> cmd Symbolic -> GenSym (resp Symbolic)) (model Concrete -> m ()) |
Instances
| Eq1 Concrete Source # | |
| Ord1 Concrete Source # | |
Defined in Test.StateMachine.Types.References | |
| Show1 Concrete Source # | |
| Show a => Show (Concrete a) Source # | |
| Eq a => Eq (Concrete a) Source # | |
| Ord a => Ord (Concrete a) Source # | |
Defined in Test.StateMachine.Types.References | |
Instances
| Eq1 Symbolic Source # | |
| Ord1 Symbolic Source # | |
Defined in Test.StateMachine.Types.References | |
| Show1 Symbolic Source # | |
| Typeable a => Read (Symbolic a) Source # | |
| Show (Symbolic a) Source # | |
| Eq (Symbolic a) Source # | |
| Ord (Symbolic a) Source # | |
Defined in Test.StateMachine.Types.References | |
| Typeable a => Read (Reference a Symbolic) Source # | |
Instances
class CommandNames (cmd :: k -> Type) where Source #
The names of all possible commands
This is used for things like tagging, coverage checking, etc.
Minimal complete definition
Nothing
Methods
cmdName :: cmd r -> String Source #
Name of this particular command
cmdNames :: Proxy (cmd r) -> [String] Source #
Name of all possible commands
Instances
| CommandNames (U1 :: k -> Type) Source # | |
| CommandNames f => CommandNames (Rec1 f :: k -> Type) Source # | |
| (CommandNames f, CommandNames g) => CommandNames (f :*: g :: k -> Type) Source # | |
| (CommandNames f, CommandNames g) => CommandNames (f :+: g :: k -> Type) Source # | |
| CommandNames (K1 i c :: k -> Type) Source # | |
| Constructor c => CommandNames (M1 C c f :: k -> Type) Source # | |
| CommandNames f => CommandNames (M1 D c f :: k -> Type) Source # | |
| CommandNames f => CommandNames (M1 S c f :: k -> Type) Source # | |
module Test.StateMachine.Logic
Diffing class
class CanDiff x where Source #
Associated Types
Expressions that will be diffed
What will the diff of two AnExprs result in
Methods
toDiff :: x -> AnExpr x Source #
Extract the expression from the data
exprDiff :: Proxy x -> AnExpr x -> AnExpr x -> ADiff x Source #
Diff two expressions
diffToDocCompact :: Proxy x -> ADiff x -> Doc Source #
Output a diff in compact form
diffToDoc :: Proxy x -> ADiff x -> Doc Source #
Output a diff
exprToDoc :: Proxy x -> AnExpr x -> Doc Source #
Output an expression