A simple default main function, which runs a list of tests and logs statistics to stdout.
Modulechell-0.5.0.2GHC2021
Test.Chell
Chell is a simple and intuitive library for automated testing. It natively
supports assertion-based testing, and can use companion libraries
such as chell-quickcheck to support more complex testing strategies.
An example test suite, which verifies the behavior of arithmetic operators.
{-# LANGUAGE TemplateHaskell #-}
import Test.Chell
suite_Math :: Suite
suite_Math = suite "math"
[ test_Addition
, test_Subtraction
]
test_Addition :: Test
test_Addition = assertions "addition" $ do
$expect (equal (2 + 1) 3)
$expect (equal (1 + 2) 3)
test_Subtraction :: Test
test_Subtraction = assertions "subtraction" $ do
$expect (equal (2 - 1) 1)
$expect (equal (1 - 2) (-1))
main :: IO ()
main = defaultMain [suite_Math]
$ ghc --make chell-example.hs
$ ./chell-example
PASS: 2 tests run, 2 tests passed- 8 types
- 3 classes
- 47 values
- Packagechell-0.5.0.2
- Exports58
- LanguageGHC2021
- LicenceMIT
- SourceChell.hs
Main
1 declarationTest suites
4 declarationsA suite is a named collection of tests.
Note: earlier versions of Chell permitted arbitrary nesting of test suites. This feature proved too unwieldy, and was removed. A similar result can be achieved with suiteTests; see the documentation for suite.
Instances2Show, SuiteOrTest
Show SuiteDefined in chell-0.5.0.2 · Test.Chell.TypesSuiteOrTest SuiteDefined in chell-0.5.0.2 · Test.Chell.Types
Define a new Suite, with the given name and children.
Note: earlier versions of Chell permitted arbitrary nesting of test suites. This feature proved too unwieldy, and was removed. A similar result can be achieved with suiteTests:
test_Addition :: Test
test_Subtraction :: Test
test_Show :: Test
suite_Math :: Suite
suite_Math = suite "math"
[ test_Addition
, test_Subtraction
]
suite_Prelude :: Suite
suite_Prelude = suite "prelude"
(
[ test_Show
]
++ suiteTests suite_Math
)
Get a suite's name. Suite names may be any string, but are typically plain ASCII so users can easily type them on the command line.
$ ghci chell-example.hs
Ok, modules loaded: Main.
*Main> suiteName tests_Math
"math"Get the full list of tests contained within this Suite. Each test is given its full name within the test hierarchy, where names are separated by periods.
$ ghci chell-example.hs
Ok, modules loaded: Main.
*Main> suiteTests tests_Math
[Test "math.addition",Test "math.subtraction"]Skipping some tests
Instances2SuiteOrTest
SuiteOrTest SuiteDefined in chell-0.5.0.2 · Test.Chell.TypesSuiteOrTest TestDefined in chell-0.5.0.2 · Test.Chell.Types
Basic testing library
14 declarationsSee assertions.
Instances4Monad, Functor, Applicative, MonadIO
Monad AssertionsDefined in chell-0.5.0.2 · Test.ChellFunctor AssertionsDefined in chell-0.5.0.2 · Test.ChellApplicative AssertionsDefined in chell-0.5.0.2 · Test.ChellMonadIO AssertionsDefined in chell-0.5.0.2 · Test.Chell
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)
Instances3IsAssertion
IsAssertion AssertionDefined in chell-0.5.0.2 · Test.ChellIsAssertion BoolDefined in chell-0.5.0.2 · Test.ChellIsAssertion a => IsAssertion (IO a)Defined in chell-0.5.0.2 · Test.Chell
A single pass/fail assertion. Failed assertions include an explanatory message.
See Assertion.
See Assertion.
Attach a note to a test run. Notes will be printed to stdout and included in reports, even if the test fails or aborts. Notes are useful for debugging failing tests.
Register an IO action to be run after the test completes. This action will run even if the test failed or aborted.
Built-in assertions
Assert that two values are equal.
Assert that two values are not equal.
Assert that two values are within some delta of each other.
Assert that some value is Just.
Assert that some value is Nothing.
Assert that some value is Left.
Assert that some value is Right.
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.
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.
Assert a value is greater than another.
Assert a value is greater than or equal to another.
Assert a value is less than another.
Assert a value is less than or equal to another.
Assert that two containers have the same items, in any order.
Assert that two containers have the same items, in the same order.
Class for types which can be treated as text; see equalLines.
Instances5IsText
IsText ByteStringDefined in chell-0.5.0.2 · Test.ChellUses
Data.ByteString.Char8IsText ByteStringDefined in chell-0.5.0.2 · Test.ChellUses
Data.ByteString.Lazy.Char8IsText StringDefined in chell-0.5.0.2 · Test.ChellIsText TextDefined in chell-0.5.0.2 · Test.ChellIsText TextDefined in chell-0.5.0.2 · Test.Chell
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.
Variant of equalLines which allows a user-specified line-splitting predicate.
Custom test types
4 declarationsA Test is, essentially, an IO action that returns a TestResult. Tests are aggregated into suites (see Suite).
Instances2Show, SuiteOrTest
Show TestDefined in chell-0.5.0.2 · Test.Chell.TypesSuiteOrTest TestDefined in chell-0.5.0.2 · Test.Chell.Types
Define a test, with the given name and implementation.
Get the name a test was given when it was defined; see test.
Run a test, wrapped in error handlers. This will return TestAborted if the test throws an exception or times out.
Test results
The result of running a test.
To support future extensions to the testing API, any users of this module who pattern-match against the TestResult constructors should include a default case. If no default case is provided, a warning will be issued.
Constructors
TestPassed [(String, String)]The test passed, and generated the given notes.
TestSkippedTestFailed [(String, String)] [Failure]The test failed, generating the given notes and failures.
TestAborted [(String, String)] StringThe test aborted with an error message, and generated the given notes.
Instances2Eq, Show
Eq TestResultDefined in chell-0.5.0.2 · Test.Chell.TypesShow TestResultDefined in chell-0.5.0.2 · Test.Chell.Types
Failures
Contains details about a test failure.
An empty Failure; use the field accessors to populate this value.
If given, the location of the failing assertion, expectation, etc.
failureLocation is a field accessor, and can be used to update a Failure value.
If given, a message which explains why the test failed.
failureMessage is a field accessor, and can be used to update a Failure value.
Failure locations
Contains details about a location in the test source file.
An empty Location; use the field accessors to populate this value.
A path to a source file, or empty if not provided.
locationFile is a field accessor, and can be used to update a Location value.
A Haskell module name, or empty if not provided.
locationModule is a field accessor, and can be used to update a Location value.
A line number, or Nothing if not provided.
locationLine is a field accessor, and can be used to update a Location value.
Test options
Test options are passed to each test, and control details about how the test should be run.
Instances2Eq, Show
Eq TestOptionsDefined in chell-0.5.0.2 · Test.Chell.TypesShow TestOptionsDefined in chell-0.5.0.2 · Test.Chell.Types
Default test options.
$ ghci
Prelude> import Test.Chell
Test.Chell> testOptionSeed defaultTestOptions
0
Test.Chell> testOptionTimeout defaultTestOptions
NothingGet 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.
testOptionSeed is a field accessor, and can be used to update a TestOptions value.
An optional timeout, in milliseconds. Tests which run longer than this timeout will be aborted.
When using defaultMain, users may specify a timeout using the
--timeout command-line option.
testOptionTimeout is a field accessor, and can be used to update a TestOptions value.