| Copyright | (C) 2017 ATS Advanced Telematic Systems GmbH |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Stevan Andjelkovic <stevan.andjelkovic@here.com> |
| Stability | provisional |
| Portability | non-portable (GHC extensions) |
| Safe Haskell | None |
| 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)) => CommandNames cmd => (Traversable cmd, Foldable resp) => StateMachine model cmd m resp -> Maybe Int -> (Commands cmd resp -> prop) -> Property
- transitionMatrix :: forall cmd. CommandNames cmd => Proxy (cmd Symbolic) -> (String -> String -> Int) -> Matrix Int
- runCommands :: (Traversable cmd, Foldable resp) => (MonadCatch m, MonadIO m) => StateMachine model cmd m resp -> Commands cmd resp -> PropertyM m (History cmd resp, model Concrete, Reason)
- prettyCommands :: (MonadIO m, ToExpr (model Concrete)) => (Show (cmd Concrete), Show (resp Concrete)) => StateMachine model cmd m resp -> History cmd resp -> Property -> PropertyM m ()
- checkCommandNames :: 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]
- forAllParallelCommands :: Testable prop => (Show (cmd Symbolic), Show (resp Symbolic), Show (model Symbolic)) => CommandNames cmd => (Traversable cmd, Foldable resp) => StateMachine model cmd m resp -> (ParallelCommands cmd resp -> prop) -> Property
- runParallelCommands :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadCatch m, MonadUnliftIO m) => StateMachine model cmd m resp -> ParallelCommands cmd resp -> PropertyM m [(History cmd resp, Logic)]
- runParallelCommandsNTimes :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadCatch m, MonadUnliftIO m) => Int -> StateMachine model cmd m resp -> ParallelCommands cmd resp -> PropertyM m [(History cmd resp, Logic)]
- prettyParallelCommands :: (MonadIO m, Foldable cmd) => (Show (cmd Concrete), Show (resp Concrete)) => ParallelCommands cmd resp -> [(History cmd resp, Logic)] -> PropertyM m ()
- 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))) (Maybe (Matrix Int)) (model Symbolic -> cmd Symbolic -> [cmd Symbolic]) (cmd Concrete -> m (resp Concrete)) (model Symbolic -> cmd Symbolic -> GenSym (resp Symbolic))
- 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
Sequential property combinators
Arguments
| :: Testable prop | |
| => (Show (cmd Symbolic), Show (resp Symbolic), Show (model Symbolic)) | |
| => CommandNames cmd | |
| => (Traversable cmd, Foldable resp) | |
| => StateMachine model cmd m resp | |
| -> Maybe Int | Minimum number of commands. |
| -> (Commands cmd resp -> prop) | Predicate. |
| -> Property |
transitionMatrix :: forall cmd. CommandNames cmd => Proxy (cmd Symbolic) -> (String -> String -> Int) -> Matrix Int Source #
runCommands :: (Traversable cmd, Foldable resp) => (MonadCatch m, MonadIO m) => StateMachine model cmd m resp -> Commands cmd resp -> PropertyM m (History cmd resp, model Concrete, Reason) Source #
prettyCommands :: (MonadIO m, ToExpr (model Concrete)) => (Show (cmd Concrete), Show (resp Concrete)) => StateMachine model cmd m resp -> History cmd resp -> Property -> PropertyM m () Source #
checkCommandNames :: forall cmd resp. CommandNames cmd => Commands cmd resp -> Property -> Property Source #
Print distribution of commands and 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 #
Parallel property combinators
forAllParallelCommands Source #
Arguments
| :: Testable prop | |
| => (Show (cmd Symbolic), Show (resp Symbolic), Show (model Symbolic)) | |
| => CommandNames cmd | |
| => (Traversable cmd, Foldable resp) | |
| => StateMachine model cmd m resp | |
| -> (ParallelCommands cmd resp -> prop) | Predicate. |
| -> Property |
runParallelCommands :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadCatch m, MonadUnliftIO m) => StateMachine model cmd m resp -> ParallelCommands cmd resp -> PropertyM m [(History cmd resp, Logic)] Source #
runParallelCommandsNTimes Source #
Arguments
| :: (Show (cmd Concrete), Show (resp Concrete)) | |
| => (Traversable cmd, Foldable resp) | |
| => (MonadCatch 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, Logic)] |
prettyParallelCommands Source #
Arguments
| :: (MonadIO m, Foldable cmd) | |
| => (Show (cmd Concrete), Show (resp Concrete)) | |
| => ParallelCommands cmd resp | |
| -> [(History cmd resp, Logic)] | Output of |
| -> PropertyM m () |
Takes the output of parallel program runs and pretty prints a counterexample if any of the runs fail.
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))) (Maybe (Matrix Int)) (model Symbolic -> cmd Symbolic -> [cmd Symbolic]) (cmd Concrete -> m (resp Concrete)) (model Symbolic -> cmd Symbolic -> GenSym (resp Symbolic)) |
Instances
| Eq1 Symbolic Source # | |
| Ord1 Symbolic Source # | |
Defined in Test.StateMachine.Types.References | |
| Show1 Symbolic Source # | |
| Eq (Symbolic a) Source # | |
| Ord (Symbolic a) Source # | |
Defined in Test.StateMachine.Types.References | |
| Show (Symbolic a) Source # | |
| ToExpr a => ToExpr (Symbolic a) Source # | |
Defined in Test.StateMachine.Types.References | |
Instances
| Traversable (Reference a :: (Type -> Type) -> Type) Source # | |
Defined in Test.StateMachine.Types.References | |
| Foldable (Reference a :: (Type -> Type) -> Type) Source # | |
| Functor (Reference a :: (Type -> Type) -> Type) Source # | |
| (Eq a, Eq1 r) => Eq (Reference a r) Source # | |
| (Ord a, Ord1 r) => Ord (Reference a r) Source # | |
Defined in Test.StateMachine.Types.References Methods compare :: Reference a r -> Reference a r -> Ordering # (<) :: Reference a r -> Reference a r -> Bool # (<=) :: Reference a r -> Reference a r -> Bool # (>) :: Reference a r -> Reference a r -> Bool # (>=) :: Reference a r -> Reference a r -> Bool # | |
| (Show1 r, Show a) => Show (Reference a r) Source # | |
| Generic (Reference a r) Source # | |
| ToExpr (r a) => ToExpr (Reference a r) Source # | |
Defined in Test.StateMachine.Types.References | |
| type Rep (Reference a r) Source # | |
Defined in Test.StateMachine.Types.References | |
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
cmdName :: (Generic1 cmd, CommandNames (Rep1 cmd)) => cmd r -> String Source #
Name of this particular command
cmdNames :: forall r. CommandNames (Rep1 cmd) => 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 # | |
| CommandNames f => CommandNames (M1 S c f :: k -> Type) Source # | |
| CommandNames f => CommandNames (M1 D c f :: k -> Type) Source # | |
| Constructor c => CommandNames (M1 C c f :: k -> Type) Source # | |
module Test.StateMachine.Logic