| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.Tasty.HUnit
Description
Unit testing support for tasty, inspired by the HUnit package
- testCase :: TestName -> Assertion -> TestTree
- type Assertion = IO ()
- assertFailure :: String -> Assertion
- assertBool :: String -> Bool -> Assertion
- assertString :: String -> Assertion
- assertEqual :: (Eq a, Show a) => String -> a -> a -> Assertion
- class Assertable t where
- type AssertionPredicate = IO Bool
- class AssertionPredicable t where
- assertionPredicate :: t -> AssertionPredicate
- (@?) :: AssertionPredicable t => t -> String -> Assertion
- (@=?) :: (Eq a, Show a) => a -> a -> Assertion
- (@?=) :: (Eq a, Show a) => a -> a -> Assertion
- data HUnitFailure = HUnitFailure String
Documentation
When an assertion is evaluated, it will output a message if and only if the assertion fails.
Test cases are composed of a sequence of one or more assertions.
Unconditionally signals that a failure has occured. All other assertions can be expressed with the form:
if conditionIsMet
then IO ()
else assertFailure msg
Arguments
| :: String | The message that is displayed if the assertion fails |
| -> Bool | The condition |
| -> Assertion |
Asserts that the specified condition holds.
Signals an assertion failure if a non-empty message (i.e., a message
other than "") is passed.
Arguments
| :: (Eq a, Show a) | |
| => String | The message prefix |
| -> a | The expected value |
| -> a | The actual value |
| -> Assertion |
Asserts that the specified actual value is equal to the expected value. The output message will contain the prefix, the expected value, and the actual value.
If the prefix is the empty string (i.e., ""), then the prefix is omitted
and only the expected and actual values are output.
class Assertable t where Source
Allows the extension of the assertion mechanism.
Since an Assertion can be a sequence of Assertions and IO actions,
there is a fair amount of flexibility of what can be achieved. As a rule,
the resulting Assertion should be the body of a TestCase or part of
a TestCase; it should not be used to assert multiple, independent
conditions.
If more complex arrangements of assertions are needed, Tests and
Testable should be used.
Instances
| Assertable Bool | |
| Assertable String | |
| Assertable () | |
| Assertable t => Assertable (IO t) |
type AssertionPredicate = IO Bool Source
The result of an assertion that hasn't been evaluated yet.
Most test cases follow the following steps:
- Do some processing or an action.
- Assert certain conditions.
However, this flow is not always suitable. AssertionPredicate allows for
additional steps to be inserted without the initial action to be affected
by side effects. Additionally, clean-up can be done before the test case
has a chance to end. A potential work flow is:
- Write data to a file.
- Read data from a file, evaluate conditions.
- Clean up the file.
- Assert that the side effects of the read operation meet certain conditions.
- Assert that the conditions evaluated in step 2 are met.
class AssertionPredicable t where Source
Used to signify that a data type can be converted to an assertion predicate.
Methods
Instances
Arguments
| :: AssertionPredicable t | |
| => t | A value of which the asserted condition is predicated |
| -> String | A message that is displayed if the assertion fails |
| -> Assertion |
Asserts that the condition obtained from the specified
AssertionPredicable holds.
Asserts that the specified actual value is equal to the expected value (with the expected value on the left-hand side).
Asserts that the specified actual value is equal to the expected value (with the actual value on the left-hand side).
data HUnitFailure Source
Exception thrown by assertFailure etc.
Constructors
| HUnitFailure String |
Instances