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 journal
- 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
- 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 -> prop
- type SuccessProp a prop = PrettyCookedOpts -> [MockChainLogEntry] -> a -> UtxoState -> prop
- type SizeProp prop = Integer -> prop
- type JournalProp prop = PrettyCookedOpts -> [MockChainLogEntry] -> prop
- data Test a prop = Test {
- testTrace :: StagedMockChain a
- testInitDist :: InitialDistribution
- testSizeProp :: SizeProp prop
- testFailureProp :: FailureProp prop
- testSuccessProp :: SuccessProp a prop
- testPrettyOpts :: PrettyCookedOpts
- testToProp :: IsProp prop => Test a prop -> prop
- testCooked :: String -> Test a Assertion -> TestTree
- testCookedQC :: String -> Test a Property -> TestTree
- mustSucceedTest :: IsProp prop => StagedMockChain a -> Test a prop
- mustFailTest :: (IsProp prop, Show a) => StagedMockChain a -> Test a prop
- withInitDist :: Test a prop -> InitialDistribution -> Test a prop
- withPrettyOpts :: Test a prop -> PrettyCookedOpts -> Test a prop
- withJournalProp :: IsProp prop => Test a prop -> JournalProp prop -> Test a prop
- withSuccessProp :: IsProp prop => Test a prop -> SuccessProp a prop -> Test a prop
- withResultProp :: IsProp prop => Test a prop -> (a -> prop) -> Test a prop
- withStateProp :: IsProp prop => Test a prop -> (UtxoState -> prop) -> Test a prop
- withSizeProp :: IsProp prop => Test a prop -> SizeProp prop -> Test a prop
- withFailureProp :: IsProp prop => Test a prop -> FailureProp prop -> Test a prop
- withErrorProp :: IsProp prop => Test a prop -> (MockChainError -> prop) -> Test a 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 -> JournalProp prop
- didNotHappen :: IsProp prop => String -> JournalProp prop
- isInWallets :: IsProp prop => [(Wallet, [(AssetClass, Integer -> Bool)])] -> SuccessProp a prop
- isInWallet :: IsProp prop => (Wallet, AssetClass, Integer) -> SuccessProp a prop
- mustFailInPhase2Test :: (IsProp prop, Show a) => StagedMockChain a -> Test a prop
- mustFailInPhase2WithMsgTest :: (IsProp prop, Show a) => String -> StagedMockChain a -> Test a prop
- mustFailInPhase1Test :: (IsProp prop, Show a) => StagedMockChain a -> Test a prop
- mustFailInPhase1WithMsgTest :: (IsProp prop, Show a) => String -> StagedMockChain a -> Test a prop
- mustSucceedWithSizeTest :: IsProp prop => Integer -> StagedMockChain a -> Test a prop
- mustFailWithSizeTest :: (IsProp prop, Show a) => Integer -> StagedMockChain a -> Test 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 # |
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 -> 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 JournalProp prop = PrettyCookedOpts -> [MockChainLogEntry] -> prop Source #
Type of properties over the mockchain journal
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 => Test a 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 :: String -> Test a 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
.
testCookedQC :: String -> Test a Property -> TestTree Source #
Same as testCooked
, but for Property
Simple test templates
mustSucceedTest :: IsProp prop => StagedMockChain a -> Test a prop Source #
A test template which expects a success from a trace
mustFailTest :: (IsProp prop, Show a) => StagedMockChain a -> Test a prop Source #
A test template which expects a failure from a trace
Appending elements (in particular requirements) to existing tests
withInitDist :: Test a prop -> InitialDistribution -> Test a prop Source #
Gives an initial distribution from which the trace will be run
withPrettyOpts :: Test a prop -> PrettyCookedOpts -> Test a prop Source #
Gives some pretty options to render test messages
withJournalProp :: IsProp prop => Test a prop -> JournalProp prop -> Test a 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.
withSuccessProp :: IsProp prop => Test a prop -> SuccessProp a prop -> Test a 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 a prop -> (a -> prop) -> Test a prop Source #
Same as withSuccessProp
but only considers the returning value of the run
withStateProp :: IsProp prop => Test a prop -> (UtxoState -> prop) -> Test a prop Source #
Some as withSuccessProp
but only considers the returning state of the run
withSizeProp :: IsProp prop => Test a prop -> SizeProp prop -> Test a prop Source #
Appends a requirement over the resulting number of outcomes of the run
withFailureProp :: IsProp prop => Test a prop -> FailureProp prop -> Test a 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 a prop -> (MockChainError -> prop) -> Test a 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 journal
happened :: IsProp prop => String -> JournalProp 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 -> JournalProp 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
isInWallets :: IsProp prop => [(Wallet, [(AssetClass, Integer -> Bool)])] -> SuccessProp a prop Source #
Ensures that the given wallets satisfy certain amount requirements over a list of given asset classes in the end of the run
isInWallet :: IsProp prop => (Wallet, AssetClass, Integer) -> SuccessProp a prop Source #
Ensures that a given wallet possesses exactly a certain amount of a given asset class in the end of the run
Advanced test templates
mustFailInPhase2Test :: (IsProp prop, Show a) => StagedMockChain a -> Test a prop Source #
A test template which expects a Phase 2 failure
mustFailInPhase2WithMsgTest :: (IsProp prop, Show a) => String -> StagedMockChain a -> Test a prop Source #
A test template which expects a specific phase 2 error message
mustFailInPhase1Test :: (IsProp prop, Show a) => StagedMockChain a -> Test a prop Source #
A test template which expects a Phase 1 failure
mustFailInPhase1WithMsgTest :: (IsProp prop, Show a) => String -> StagedMockChain a -> Test a prop Source #
A test template which expects a specific phase 1 error message
mustSucceedWithSizeTest :: IsProp prop => Integer -> StagedMockChain a -> Test a prop Source #
A test template which expects a certain number of successful outcomes
mustFailWithSizeTest :: (IsProp prop, Show a) => Integer -> StagedMockChain a -> Test a prop Source #
A test template which expects a certain number of unsuccessful outcomes