| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cooked.MockChain.Testing
Contents
- Common interface between HUnit and QuickCheck
- Extra HUnit assertions
- Data structure to test mockchain traces
- Simple test templates
- Appending elements (in particular requirements) to existing tests
- Specific properties around failures
- Specific properties around number of outcomes
- Specific properties over the log
- Specific properties over successes
- Advanced test templates
Description
This modules provides primitives to run tests over mockchain executions and to provide requirements on the the number and results of these runs.
Synopsis
- class IsProp prop where
- testCounterexample :: String -> prop -> prop
- testConjoin :: [prop] -> prop
- testDisjoin :: [prop] -> prop
- testFailure :: prop
- testSuccess :: prop
- testFailureMsg :: String -> prop
- testBool :: IsProp prop => Bool -> prop
- testBoolMsg :: IsProp prop => String -> Bool -> prop
- testAll :: IsProp prop => (a -> prop) -> [a] -> prop
- testAny :: IsProp prop => (a -> prop) -> [a] -> prop
- (.==.) :: (IsProp prop, Eq a) => a -> a -> prop
- (.&&.) :: IsProp prop => prop -> prop -> prop
- (.||.) :: IsProp prop => prop -> prop -> prop
- assertionToMaybe :: Assertion -> IO (Maybe HUnitFailure)
- forAll :: Show a => Gen a -> (a -> Property) -> Property
- assertSubset :: (Show a, Eq a) => [a] -> [a] -> Assertion
- assertSameSets :: (Show a, Eq a) => [a] -> [a] -> Assertion
- type FailureProp prop = PrettyCookedOpts -> [MockChainLogEntry] -> MockChainError -> UtxoState -> prop
- type SuccessProp a prop = PrettyCookedOpts -> [MockChainLogEntry] -> a -> UtxoState -> prop
- type SizeProp prop = Integer -> prop
- type LogProp prop = PrettyCookedOpts -> [MockChainLogEntry] -> prop
- type StateProp prop = PrettyCookedOpts -> UtxoState -> prop
- type Runner effs a b = MockChainState -> InitialDistribution -> Sem effs a -> [MockChainReturn b]
- data Test effs a b prop = Test {
- testTrace :: Sem effs a
- testRunner :: Runner effs a b
- testInitState :: MockChainState
- testInitDist :: InitialDistribution
- testSizeProp :: SizeProp prop
- testFailureProp :: FailureProp prop
- testSuccessProp :: SuccessProp b prop
- testPrettyOpts :: PrettyCookedOpts
- testToProp :: (IsProp prop, Show b) => Test effs a b prop -> prop
- testCooked :: forall effs a b. Show b => String -> Test effs a b Assertion -> TestTree
- testCookedFromInitDistTemplate :: forall effs a b. Show b => String -> Test effs a b Assertion -> TestTree
- testCookedQC :: forall effs a b. Show b => String -> Test effs a b Property -> TestTree
- testCookedQCFromInitDistTemplate :: forall effs a b. Show b => String -> Test effs a b Property -> TestTree
- mustSucceedTest' :: IsProp prop => Runner effs a b -> Sem effs a -> Test effs a b prop
- mustSucceedTest :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => Sem effs a -> Test effs a a prop
- mustFailTest' :: IsProp prop => Runner effs a b -> Sem effs a -> Test effs a b prop
- mustFailTest :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => Sem effs a -> Test effs a a prop
- withInitDist :: Test effs a b prop -> InitialDistribution -> Test effs a b prop
- withPrettyOpts :: Test effs a b prop -> PrettyCookedOpts -> Test effs a b prop
- withLogProp :: IsProp prop => Test effs a b prop -> LogProp prop -> Test effs a b prop
- withStateProp :: IsProp prop => Test effs a b prop -> StateProp prop -> Test effs a b prop
- withSuccessProp :: IsProp prop => Test effs a b prop -> SuccessProp b prop -> Test effs a b prop
- withResultProp :: IsProp prop => Test effs a b prop -> (b -> prop) -> Test effs a b prop
- withSizeProp :: IsProp prop => Test effs a b prop -> SizeProp prop -> Test effs a b prop
- withFailureProp :: IsProp prop => Test effs a b prop -> FailureProp prop -> Test effs a b prop
- withErrorProp :: IsProp prop => Test effs a b prop -> (MockChainError -> prop) -> Test effs a b prop
- isPhase1Failure :: IsProp prop => FailureProp prop
- isPhase2Failure :: IsProp prop => FailureProp prop
- isPhase1FailureWithMsg :: IsProp prop => String -> FailureProp prop
- isPhase2FailureWithMsg :: IsProp prop => String -> FailureProp prop
- isOfSize :: IsProp prop => Integer -> SizeProp prop
- isAtLeastOfSize :: IsProp prop => Integer -> SizeProp prop
- isAtMostOfSize :: IsProp prop => Integer -> SizeProp prop
- happened :: IsProp prop => String -> LogProp prop
- didNotHappen :: IsProp prop => String -> LogProp prop
- isAtAddress :: (IsProp prop, ToAddress addr, Show addr) => [(addr, [(AssetClass, Integer -> Bool)])] -> SuccessProp a prop
- possesses :: (IsProp prop, ToAddress addr, Show addr) => addr -> AssetClass -> Integer -> SuccessProp a prop
- mustFailInPhase2Test' :: IsProp prop => Runner effs a b -> Sem effs a -> Test effs a b prop
- mustFailInPhase2Test :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => Sem effs a -> Test effs a a prop
- mustFailInPhase2WithMsgTest' :: IsProp prop => String -> Runner effs a b -> Sem effs a -> Test effs a b prop
- mustFailInPhase2WithMsgTest :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => String -> Sem effs a -> Test effs a a prop
- mustFailInPhase1Test' :: IsProp prop => Runner effs a b -> Sem effs a -> Test effs a b prop
- mustFailInPhase1Test :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => Sem effs a -> Test effs a a prop
- mustFailInPhase1WithMsgTest' :: IsProp prop => String -> Runner effs a b -> Sem effs a -> Test effs a b prop
- mustFailInPhase1WithMsgTest :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => String -> Sem effs a -> Test effs a a prop
- mustSucceedWithSizeTest' :: IsProp prop => Integer -> Runner effs a b -> Sem effs a -> Test effs a b prop
- mustSucceedWithSizeTest :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => Integer -> Sem effs a -> Test effs a a prop
- mustFailWithSizeTest' :: IsProp prop => Integer -> Runner effs a b -> Sem effs a -> Test effs a b prop
- mustFailWithSizeTest :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => Integer -> Sem effs a -> Test effs a a prop
Common interface between HUnit and QuickCheck
class IsProp prop where Source #
IsProp is a common interface for HUnit and QuickCheck tests. It abstracts
uses of Assertion and Property for (IsProp prop) => prop, then
provide instances for both HU.Asserton and QC.Property.
Minimal complete definition
Methods
testCounterexample :: String -> prop -> prop Source #
Displays the string to the user in case of failure
testConjoin :: [prop] -> prop Source #
Conjunction of a number of results
testDisjoin :: [prop] -> prop Source #
Disjunction of a number of results
testFailure :: prop Source #
Flags a failure
testSuccess :: prop Source #
Flags a success
testFailureMsg :: String -> prop Source #
Flags a failure with a message
Instances
| IsProp Property Source # | QuickCheck instance of |
Defined in Cooked.MockChain.Testing Methods testCounterexample :: String -> Property -> Property Source # testConjoin :: [Property] -> Property Source # testDisjoin :: [Property] -> Property Source # testFailure :: Property Source # testSuccess :: Property Source # testFailureMsg :: String -> Property Source # | |
| IsProp Assertion Source # | HUnit instance of |
Defined in Cooked.MockChain.Testing Methods testCounterexample :: String -> Assertion -> Assertion Source # testConjoin :: [Assertion] -> Assertion Source # testDisjoin :: [Assertion] -> Assertion Source # testFailure :: Assertion Source # testSuccess :: Assertion Source # testFailureMsg :: String -> Assertion Source # | |
testBoolMsg :: IsProp prop => String -> Bool -> prop Source #
Turns a boolean into a prop, displaying an error message when applicable
testAll :: IsProp prop => (a -> prop) -> [a] -> prop Source #
Ensures all elements of a list satisfy a given prop
testAny :: IsProp prop => (a -> prop) -> [a] -> prop Source #
Ensures at least one element of a list satisfy a given prop
assertionToMaybe :: Assertion -> IO (Maybe HUnitFailure) Source #
Catches a HUnit test failure, if the test fails.
Extra HUnit assertions
assertSubset :: (Show a, Eq a) => [a] -> [a] -> Assertion Source #
Asserts whether a set is a subset of another one, both given as lists.
assertSameSets :: (Show a, Eq a) => [a] -> [a] -> Assertion Source #
Asserts whether 2 sets are equal, both given as lists.
Data structure to test mockchain traces
type FailureProp prop = PrettyCookedOpts -> [MockChainLogEntry] -> MockChainError -> UtxoState -> prop Source #
Type of properties over failures
type SuccessProp a prop = PrettyCookedOpts -> [MockChainLogEntry] -> a -> UtxoState -> prop Source #
Type of properties over successes
type SizeProp prop = Integer -> prop Source #
Type of properties over the number of run outcomes. This does not
necessitate a PrettyCookedOpts as parameter as an Integer does not
contain anything significant that can be pretty printed.
type LogProp prop = PrettyCookedOpts -> [MockChainLogEntry] -> prop Source #
Type of properties over the mockchain log
type StateProp prop = PrettyCookedOpts -> UtxoState -> prop Source #
Type of properties over the UtxoState
type Runner effs a b = MockChainState -> InitialDistribution -> Sem effs a -> [MockChainReturn b] Source #
Type of trace runners
data Test effs a b prop Source #
Data structure to test a mockchain trace. a is the return typed of the
tested trace, prop is the domain in which the properties live. This is not
enforced here, but it will often be assumed that prop satisfies IsProp.
Constructors
| Test | |
Fields
| |
testToProp :: (IsProp prop, Show b) => Test effs a b prop -> prop Source #
This takes a Test and transforms it into an actual test case in
prop. This is the main function justifying the existence of Test. This runs
the traces, ensures there is the right number of outcomes and, depending on
the nature of these outcomes, either calls testFailureProp or
testSuccessProp. It also uses the aliases emitted during the mockchain run
to pretty print messages when applicable.
testCooked :: forall effs a b. Show b => String -> Test effs a b Assertion -> TestTree Source #
A convenience helper when using Assertion which allows to replace
testCase with testCooked and thus avoid the use of testToProp.
Sadly we cannot generalise it with type classes on prop to work for
QuichCheck at GHC will never be able to instantiate prop.
testCookedFromInitDistTemplate :: forall effs a b. Show b => String -> Test effs a b Assertion -> TestTree Source #
Same as testCooked but first assigns the initial distribution template as
a starting point to the test
testCookedQC :: forall effs a b. Show b => String -> Test effs a b Property -> TestTree Source #
Same as testCooked, but for Property
testCookedQCFromInitDistTemplate :: forall effs a b. Show b => String -> Test effs a b Property -> TestTree Source #
Same as testCookedQC but first assigns the initial distribution template
as a starting point to the test
Simple test templates
mustSucceedTest' :: IsProp prop => Runner effs a b -> Sem effs a -> Test effs a b prop Source #
A test template which expects a success from a trace. This test template is
built from a trace and a dedicated runner, to be used for runs that do not
implement RunnableMockChain. One of the intended uses is for running
StagedInjectMockChain when the additional effect
results in a extended return value (such as a resulting state).
mustSucceedTest :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => Sem effs a -> Test effs a a prop Source #
A test template which expects a success from a RunnableMockChain trace.
mustFailTest' :: IsProp prop => Runner effs a b -> Sem effs a -> Test effs a b prop Source #
A test template which expects a failure from a trace. See
mustSucceedTest' for more information on its intended usage.
mustFailTest :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => Sem effs a -> Test effs a a prop Source #
A test template which expects a failure from a RunnableMockChain trace.
Appending elements (in particular requirements) to existing tests
withInitDist :: Test effs a b prop -> InitialDistribution -> Test effs a b prop Source #
Gives an initial distribution from which the trace will be run
withPrettyOpts :: Test effs a b prop -> PrettyCookedOpts -> Test effs a b prop Source #
Gives some pretty options to render test messages
withLogProp :: IsProp prop => Test effs a b prop -> LogProp prop -> Test effs a b prop Source #
Appends a requirements over the emitted log, which will need to be satisfied both in case of success or failure of the run.
withStateProp :: IsProp prop => Test effs a b prop -> StateProp prop -> Test effs a b prop Source #
Appends a requirements over the resulting UtxoState, which will need to
be satisfied both in case of success or failure of the run.
withSuccessProp :: IsProp prop => Test effs a b prop -> SuccessProp b prop -> Test effs a b prop Source #
Appends a requirement over the resulting value and state of the mockchain run which will need to be satisfied if the run is successful
withResultProp :: IsProp prop => Test effs a b prop -> (b -> prop) -> Test effs a b prop Source #
Same as withSuccessProp but only considers the returning value of the run
withSizeProp :: IsProp prop => Test effs a b prop -> SizeProp prop -> Test effs a b prop Source #
Appends a requirement over the resulting number of outcomes of the run
withFailureProp :: IsProp prop => Test effs a b prop -> FailureProp prop -> Test effs a b prop Source #
Appends a requirement over the resulting value and state of the mockchain run which will need to be satisfied if the run is successful
withErrorProp :: IsProp prop => Test effs a b prop -> (MockChainError -> prop) -> Test effs a b prop Source #
Same as withFailureProp but only considers the returning error of the run
Specific properties around failures
isPhase1Failure :: IsProp prop => FailureProp prop Source #
A property to ensure a phase 1 failure
isPhase2Failure :: IsProp prop => FailureProp prop Source #
A property to ensure a phase 2 failure
isPhase1FailureWithMsg :: IsProp prop => String -> FailureProp prop Source #
Same as isPhase1Failure with an added predicate on the text error
isPhase2FailureWithMsg :: IsProp prop => String -> FailureProp prop Source #
Same as isPhase2Failure with an added predicate over the text error
Specific properties around number of outcomes
isOfSize :: IsProp prop => Integer -> SizeProp prop Source #
Ensures the run has an exact given number of outcomes
isAtLeastOfSize :: IsProp prop => Integer -> SizeProp prop Source #
Ensures the run has a minimal number of outcomes
isAtMostOfSize :: IsProp prop => Integer -> SizeProp prop Source #
Ensures the run has a minimal number of outcomes
Specific properties over the log
happened :: IsProp prop => String -> LogProp prop Source #
Ensures a certain event has been emitted. This uses the constructor's name
of the MockChainLogEntry by relying on show being lazy.
didNotHappen :: IsProp prop => String -> LogProp prop Source #
Ensures a certain event has not been emitted. This uses the constructor's
name of the MockChainLogEntry by relying on show being lazy.
Specific properties over successes
isAtAddress :: (IsProp prop, ToAddress addr, Show addr) => [(addr, [(AssetClass, Integer -> Bool)])] -> SuccessProp a prop Source #
Ensures that the given addresses satisfy certain amount requirements over a list of given asset classes in the end of the run
possesses :: (IsProp prop, ToAddress addr, Show addr) => addr -> AssetClass -> Integer -> SuccessProp a prop Source #
Ensures that a given address possesses exactly a certain amount of a given asset class in the end of the run
Advanced test templates
mustFailInPhase2Test' :: IsProp prop => Runner effs a b -> Sem effs a -> Test effs a b prop Source #
A test template expecting a Phase 2 failure for arbitrary runs
mustFailInPhase2Test :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => Sem effs a -> Test effs a a prop Source #
A test template expecting a Phase 2 failure for RunnableMockChain runs
mustFailInPhase2WithMsgTest' :: IsProp prop => String -> Runner effs a b -> Sem effs a -> Test effs a b prop Source #
A test template expecting a specific phase 2 error message for arbitrary runs
mustFailInPhase2WithMsgTest :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => String -> Sem effs a -> Test effs a a prop Source #
A test template expecting a specific phase 2 error message for
RunnableMockChain runs
mustFailInPhase1Test' :: IsProp prop => Runner effs a b -> Sem effs a -> Test effs a b prop Source #
A test template expecting a Phase 1 failure
mustFailInPhase1Test :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => Sem effs a -> Test effs a a prop Source #
A test template expecting a Phase 1 failure for RunnableMockChain runs
mustFailInPhase1WithMsgTest' :: IsProp prop => String -> Runner effs a b -> Sem effs a -> Test effs a b prop Source #
A test template expecting a specific phase 1 error message
mustFailInPhase1WithMsgTest :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => String -> Sem effs a -> Test effs a a prop Source #
A test template expecting a specific phase 1 error message for
RunnableMockChain runs
mustSucceedWithSizeTest' :: IsProp prop => Integer -> Runner effs a b -> Sem effs a -> Test effs a b prop Source #
A test template expecting a certain number of successful outcomes for arbitrary runs
mustSucceedWithSizeTest :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => Integer -> Sem effs a -> Test effs a a prop Source #
A test template expecting a certain number of successful outcomes for
RunnableMockChain runs
mustFailWithSizeTest' :: IsProp prop => Integer -> Runner effs a b -> Sem effs a -> Test effs a b prop Source #
A test template expecting a certain number of unsuccessful outcomes for arbitrary runs
mustFailWithSizeTest :: (IsProp prop, RunnableMockChain effs, Member MockChainWrite effs) => Integer -> Sem effs a -> Test effs a a prop Source #
A test template expecting a certain number of unsuccessful outcomes for
RunnableMockChain runs