- defaultMain :: [Suite] -> IO ()
- data Suite
- suite :: Text -> [Suite] -> Suite
- suiteName :: Suite -> Text
- suiteTests :: Suite -> [Test]
- test :: Test -> Suite
- skipIf :: Bool -> Test -> Test
- skipWhen :: IO Bool -> Test -> Test
- newtype Assertion = Assertion (IO AssertionResult)
- data AssertionResult
- class IsAssertion a
- data Assertions a
- assertions :: Text -> Assertions a -> Test
- assert :: Q Exp
- expect :: Q Exp
- fail :: Q Exp
- trace :: Text -> Assertions ()
- note :: Text -> Text -> Assertions ()
- equal :: (Show a, Eq a) => a -> a -> Assertion
- notEqual :: (Eq a, Show a) => a -> a -> Assertion
- equalWithin :: (Real a, Show a) => a -> a -> a -> Assertion
- just :: Maybe a -> Assertion
- nothing :: Maybe a -> Assertion
- left :: Either a b -> Assertion
- right :: Either a b -> Assertion
- throws :: Exception err => (err -> Bool) -> IO a -> Assertion
- throwsEq :: (Eq err, Exception err, Show err) => err -> IO a -> Assertion
- greater :: (Ord a, Show a) => a -> a -> Assertion
- greaterEqual :: (Ord a, Show a) => a -> a -> Assertion
- lesser :: (Ord a, Show a) => a -> a -> Assertion
- lesserEqual :: (Ord a, Show a) => a -> a -> Assertion
- sameItems :: (Foldable container, Show item, Ord item) => container item -> container item -> Assertion
- equalItems :: (Foldable container, Show item, Ord item) => container item -> container item -> Assertion
- class IsText a
- equalLines :: (Ord a, IsText a) => a -> a -> Assertion
- data Test = Test Text (TestOptions -> IO TestResult)
- testName :: Test -> Text
- runTest :: Test -> TestOptions -> IO TestResult
- data TestOptions
- testOptionSeed :: TestOptions -> Int
- testOptionTimeout :: TestOptions -> Maybe Int
- data TestResult
- = TestPassed [(Text, Text)]
- | TestSkipped
- | TestFailed [(Text, Text)] [Failure]
- | TestAborted [(Text, Text)] Text
- data Failure = Failure (Maybe Location) Text
- data Location = Location {}
Main
defaultMain :: [Suite] -> IO ()Source
A simple default main function, which runs a list of tests and logs statistics to stderr.
Test suites
suiteTests :: Suite -> [Test]Source
Basic testing library
This library includes a few basic JUnit-style assertions, for use in simple test suites where depending on a separate test framework is too much trouble.
data Assertions a Source
assertions :: Text -> Assertions a -> TestSource
Convert a sequence of pass/fail assertions into a runnable test.
test_Equality :: Test test_Equality = assertions "equality" $ do $assert (1 == 1) $assert (equal 1 1)
Run an Assertion
. If the assertion fails, the test will immediately
fail.
assert
is a Template Haskell macro, to retain the source-file location
from which it was used. Its effective type is:
$assert ::IsAssertion
assertion => assertion ->Assertions
()
Run an Assertion
. If the assertion fails, the test will continue to
run until it finishes (or until an assert
fails).
expect
is a Template Haskell macro, to retain the source-file location
from which it was used. Its effective type is:
$expect ::IsAssertion
assertion => assertion ->Assertions
()
Cause a test to immediately fail, with a message.
fail
is a Template Haskell macro, to retain the source-file
location from which it was used. Its effective type is:
$fail ::Text
->Assertions
a
trace :: Text -> Assertions ()Source
Print a message from within a test. This is just a helper for debugging,
so you don't have to import Debug.Trace
.
note :: Text -> Text -> Assertions ()Source
Attach metadata to a test run. This will be included in reports.
Assertions
Assert that two values are within some delta of each other.
throws :: Exception err => (err -> Bool) -> IO a -> AssertionSource
Assert that some computation throws an exception matching the provided
predicate. This is mostly useful for exception types which do not have an
instance for Eq
, such as
.
ErrorCall
throwsEq :: (Eq err, Exception err, Show err) => err -> IO a -> AssertionSource
Assert that some computation throws an exception equal to the given exception. This is better than just checking that the correct type was thrown, because the test can also verify the exception contains the correct information.
greaterEqual :: (Ord a, Show a) => a -> a -> AssertionSource
Assert a value is greater than or equal to another.
lesserEqual :: (Ord a, Show a) => a -> a -> AssertionSource
Assert a value is less than or equal to another.
sameItems :: (Foldable container, Show item, Ord item) => container item -> container item -> AssertionSource
Assert that two containers have the same items, in any order.
equalItems :: (Foldable container, Show item, Ord item) => container item -> container item -> AssertionSource
Assert that two containers have the same items, in the same order.
Class for types which can be treated as text.
IsText String | |
IsText ByteString | Uses |
IsText ByteString | Uses |
IsText Text | |
IsText Text |
equalLines :: (Ord a, IsText a) => a -> a -> AssertionSource
Assert that two pieces of text are equal. This uses a diff algorithm to check line-by-line, so the error message will be easier to read on large inputs.
Constructing tests
runTest :: Test -> TestOptions -> IO TestResultSource
Run a test, wrapped in error handlers. This will return TestAborted
if
the test throws an exception or times out.
testOptionSeed :: TestOptions -> IntSource
Get the RNG seed for this test run. The seed is generated once, in
defaultMain
, and used for all tests. It is also logged to reports using
a note.
Users may specify a seed using the --seed
command-line option.
testOptionTimeout :: TestOptions -> Maybe IntSource
An optional timeout, in millseconds. Tests which run longer than this timeout will be aborted.
Users may specify a timeout using the --timeout
command-line option.
data TestResult Source
TestPassed [(Text, Text)] | |
TestSkipped | |
TestFailed [(Text, Text)] [Failure] | |
TestAborted [(Text, Text)] Text |