Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Cooked.MockChain.Testing
Description
This modules provides primitives to run tests over mockchain executions and to give expectation on the result 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
- (.==.) :: (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
- data Test a prop = Test {
- testTrace :: StagedMockChain a
- testInitDist :: InitialDistribution
- testErrorProp :: PrettyCookedOpts -> MockChainError -> [MockChainLogEntry] -> prop
- testResultProp :: PrettyCookedOpts -> a -> UtxoState -> [MockChainLogEntry] -> prop
- testPrettyOpts :: PrettyCookedOpts
- mustSucceedTest :: IsProp prop => StagedMockChain a -> Test a prop
- mustFailTest :: (IsProp prop, Show a) => StagedMockChain a -> Test a prop
- emptyTest :: IsProp prop => StagedMockChain a -> Test a prop
- withInitDist :: Test a prop -> InitialDistribution -> Test a prop
- withPrettyOpts :: Test a prop -> PrettyCookedOpts -> Test a prop
- withJournalPred :: IsProp prop => Test a prop -> ([MockChainLogEntry] -> prop) -> Test a prop
- withValueAndStatePred :: IsProp prop => Test a prop -> (a -> UtxoState -> prop) -> Test a prop
- withValuePred :: IsProp prop => Test a prop -> (a -> prop) -> Test a prop
- withStatePred :: IsProp prop => Test a prop -> (UtxoState -> prop) -> Test a prop
- withPrettyAndErrorPred :: IsProp prop => Test a prop -> (PrettyCookedOpts -> MockChainError -> prop) -> Test a prop
- withErrorPred :: IsProp prop => Test a prop -> (MockChainError -> prop) -> Test a prop
- testToProp :: IsProp prop => Test a prop -> prop
- testSucceeds :: IsProp prop => StagedMockChain a -> prop
- testFails :: (IsProp prop, Show a) => StagedMockChain a -> prop
- isPhase1Failure :: IsProp prop => PrettyCookedOpts -> MockChainError -> prop
- testFailsInPhase1 :: (IsProp prop, Show a) => StagedMockChain a -> prop
- isPhase2Failure :: IsProp prop => PrettyCookedOpts -> MockChainError -> prop
- testFailsInPhase2 :: (IsProp prop, Show a) => StagedMockChain a -> prop
- isPhase1FailureWithMsg :: IsProp prop => (String -> Bool) -> PrettyCookedOpts -> MockChainError -> prop
- testFailsInPhase1WithMsg :: (IsProp prop, Show a) => (String -> Bool) -> StagedMockChain a -> prop
- isPhase2FailureWithMsg :: IsProp prop => (String -> Bool) -> PrettyCookedOpts -> MockChainError -> prop
- testFailsInPhase2WithMsg :: (IsProp prop, Show a) => (String -> Bool) -> StagedMockChain 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 # |
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.
Testing mockchain traces
Data structure to test a mockchain trace
Constructors
Test | |
Fields
|
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
emptyTest :: IsProp prop => StagedMockChain a -> Test a prop Source #
A test template with no particular requirement on the trace
withInitDist :: Test a prop -> InitialDistribution -> Test a prop Source #
Appending an initial distribution to a test
withPrettyOpts :: Test a prop -> PrettyCookedOpts -> Test a prop Source #
Appending printing options to a test
withJournalPred :: IsProp prop => Test a prop -> ([MockChainLogEntry] -> prop) -> Test a prop Source #
Appending a predicate over the log to a test. This will be used both in case of success or failure of the trace.
withValueAndStatePred :: IsProp prop => Test a prop -> (a -> UtxoState -> prop) -> Test a prop Source #
Appending a predicate over the return value and state, which will be used in case of success of the trace.
withValuePred :: IsProp prop => Test a prop -> (a -> prop) -> Test a prop Source #
Appending a predicate over the return value, which will be used in case of success of the trace.
withStatePred :: IsProp prop => Test a prop -> (UtxoState -> prop) -> Test a prop Source #
Appending a predicate over the return state, which will be used in case of success of the trace.
withPrettyAndErrorPred :: IsProp prop => Test a prop -> (PrettyCookedOpts -> MockChainError -> prop) -> Test a prop Source #
Appending a predicate over an error which uses the printing options, which will be used in case of failure of the trace.
withErrorPred :: IsProp prop => Test a prop -> (MockChainError -> prop) -> Test a prop Source #
testToProp :: IsProp prop => Test a prop -> prop Source #
This takes a test and transforms it into an actual test case in prop.
testSucceeds :: IsProp prop => StagedMockChain a -> prop Source #
Ensure that all results produced by the staged mockchain succeed, starting from the default initial distribution
testFails :: (IsProp prop, Show a) => StagedMockChain a -> prop Source #
Ensure that all results produced by the staged mockchain fail
isPhase1Failure :: IsProp prop => PrettyCookedOpts -> MockChainError -> prop Source #
A property to ensure a phase 1 failure
testFailsInPhase1 :: (IsProp prop, Show a) => StagedMockChain a -> prop Source #
A test that succeeds when the trace results in a phase 1 failure
isPhase2Failure :: IsProp prop => PrettyCookedOpts -> MockChainError -> prop Source #
A property to ensure a phase 2 failure
testFailsInPhase2 :: (IsProp prop, Show a) => StagedMockChain a -> prop Source #
A test that succeeds when the trace results in a phase 2 failure
isPhase1FailureWithMsg :: IsProp prop => (String -> Bool) -> PrettyCookedOpts -> MockChainError -> prop Source #
Same as isPhase1Failure
with an added predicate on the text error
testFailsInPhase1WithMsg :: (IsProp prop, Show a) => (String -> Bool) -> StagedMockChain a -> prop Source #
Same as testFailsInPhase1
with an added predicate on the text error
isPhase2FailureWithMsg :: IsProp prop => (String -> Bool) -> PrettyCookedOpts -> MockChainError -> prop Source #
Same as isPhase2Failure
with an added predicate over the text error
testFailsInPhase2WithMsg :: (IsProp prop, Show a) => (String -> Bool) -> StagedMockChain a -> prop Source #
Same as testFailsInPhase2
with an added predicate over the text error