Safe Haskell | None |
---|
- defaultMain :: [Suite] -> IO ()
- data Suite
- suite :: Text -> [Suite] -> Suite
- suiteName :: Suite -> Text
- suiteTests :: Suite -> [Test]
- test :: Test -> Suite
- skipIf :: Bool -> Suite -> Suite
- skipWhen :: IO Bool -> Suite -> Suite
- newtype Assertion = Assertion (IO AssertionResult)
- data AssertionResult
- = AssertionPassed
- | AssertionFailed Text
- class IsAssertion a
- data Assertions a
- assertions :: Text -> Assertions a -> Suite
- assertionsTest :: Text -> Assertions a -> Test
- assert :: Q Exp
- expect :: Q Exp
- die :: Q Exp
- trace :: Text -> Assertions ()
- note :: Text -> Text -> Assertions ()
- afterTest :: IO () -> Assertions ()
- requireLeft :: Q Exp
- requireRight :: Q Exp
- 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
- defaultTestOptions :: 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 {
- locationFile :: Text
- locationModule :: Text
- locationLine :: Integer
- fail :: Q Exp
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 -> SuiteSource
Convert a sequence of pass/fail assertions into a runnable test.
test_Equality :: Suite test_Equality = assertions "equality" $ do $assert (1 == 1) $assert (equal 1 1)
assertionsTest :: Text -> Assertions a -> TestSource
Convert a sequence of pass/fail assertions into a runnable test.
This is easier to use than assertions
when the result is going to be
modified (eg, by a wrapper) before being used in a test suite.
Most users should use assertions
instead, to avoid the extra wrapping
step.
Since: 0.2.3
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.
die
is a Template Haskell macro, to retain the source-file location from
which it was used. Its effective type is:
$die ::String
->Assertions
a
Since: 0.2.4
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.
afterTest :: IO () -> Assertions ()Source
Register an IO action to be run after the test completes. This action will run even if the test failed or threw an exception.
Since: 0.2.3
Require an Either
value to be Left
, and return its contents. If
the value is Right
, fail the test.
requireLeft
is a Template Haskell macro, to retain the source-file
location from which it was used. Its effective type is:
$requireLeft ::Show
b =>Either
a b ->Assertions
a
Since: 0.2.4
Require an Either
value to be Right
, and return its contents. If
the value is Left
, fail the test.
requireRight
is a Template Haskell macro, to retain the source-file
location from which it was used. Its effective type is:
$requireRight ::Show
a =>Either
a b ->Assertions
b
Since: 0.2.4
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.
defaultTestOptions :: TestOptionsSource
Default test options.
testOptionSeed
defaultTestOptions = 0testOptionTimeout
defaultTestOptions = Nothing
Since: 0.2.3
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.
When using defaultMain
, 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.
When using defaultMain
, 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 |
Location | |
|