Simple but extensible testing framework with advanced reporting.
The primary interface to testing. Evaluateexpr
and check
that it is equal to expect
, and report the result, using
name
or a printed summary of expr
.
If used inside a group this will contribute to the overall group
reporting, but can be used standalone:
(test 4 (+ 2 2))
(+ 2 2) .............................................................. [ PASS]
=> PASS
(test "add two and two" 4 (+ 2 2))
add two and two ...................................................... [ PASS]
=> PASS
(test 3 (+ 2 2))
(+ 2 2) .............................................................. [ FAIL]
expected 3 but got 4
=> FAIL
(test 4 (+ 2 "2"))
(+ 2 "2") ............................................................ [ERROR]
ERROR: invalid type, expected Number: "2"
=> ERROR
current-test-comparator
, defaulting to
test-equal?
, which is the same as equal?
but
more permissive on floating point comparisons). Returns the
status of the test (one of the symbols 'PASS
,
'FAIL
, 'SKIP
, 'ERROR
).
Equivalent to test, using equal
for comparison instead of
equal?
.
Like test
but evaluates expr
and checks that it's true.
Like test
but evaluates expr
and checks that it's false.
Like test
but expect
and expr
can both
return multiple values.
Like test
but evaluates expr
and checks that it
raises an error.Low-level macro to pass alist info to the underlying test-run
.The procedural interface to testing. expect
and expr
should be thunks, and info
is an alist of properties used in
test reporting.Returns true if either (equal? expect res)
, or
expect
is inexact and res
is within
current-test-epsilon
of expect
.
Tests can be collected in groups for
Wraps body
as a single test group, which can be filtered
and summarized separately.
(test-group "pi"
(test 3.14159 (acos -1))
(test 3 (acos -1))
(test 3.14159 (acos "-1")))
pi: .x!
1 out of 3 (33.3%) test passed in 0.00030422210693359375 seconds.
1 failure (33.3%).
1 error (33.3%).
FAIL: (acos -1)
expected 3 but got 3.141592653589793
ERROR: (acos "-1")
ERROR in "acos": invalid type, expected Number: "-1"
(test-end)
.Ends testing group introduced with (test-begin)
, and
summarizes the results. The name
is optional, but if
present should match the corresponding test-begin
name,
or a warning is printed.Exits with a failure status if any tests have failed,
and a successful status otherwise.Returns the name of a test group info object.Returns the value of a field
in a test var{group} info
object. field
should be a symbol, and predefined fields
include parent
, verbose
, level
,
start-time
, skip-group?
, count
,
total-pass
, total-fail
, total-error
.Sets the value of a field
in a test group
info object.Increments the value of a field
in a test group
info
object by amount
, defaulting to 1.Updates a field
in a test group info object by consing
value
onto it.
The current test group as started by test-group
or
test-begin
.If true, show more verbose output per test. Inferred from the
environment variable TEST_VERBOSE.The epsilon used for floating point comparisons.The underlying comparator used in testing, defaults to
test-equal?
.The test applier - what we do with non-skipped tests. Takes the
same signature as test-run
, should be responsible for
evaluating the thunks, determining the status of the test, and
passing this information to current-test-reporter
.The test skipper - what we do with non-skipped tests. This should
not evaluate the thunks and simply pass off to
current-test-reporter
.Takes two arguments, the symbol status of the test and the info
alist. Reports the result of the test and updates bookkeeping in
the current test group for reporting.Takes one argument, a test group, and prints a summary of the test
results for that group.A running count of all test failures and errors across all groups
(and threads). Used by test-exit
.Parameters controlling which test groups are skipped. Each
parameter is a list of procedures of one argument, a test group
info, which can be queried with test-group-name
and
test-group-ref
. Analogous to SRFI 1, a filter selects a
group for inclusion and a removers for exclusion. The defaults
are set automatically from the environment variables
TEST_GROUP_FILTER and TEST_GROUP_REMOVE, which should be
comma-delimited lists of strings which are checked for a substring
match in the test group name. A test group is skipped if it does
not match any filter and:
- its parent group is skipped, or
- it matches a remover, or
- no removers are specified but some filters are
test-get-name!
or assq
.
Analogous to SRFI 1, a filter selects a test for inclusion and a
removers for exclusion. The defaults are set automatically from
the environment variables TEST_FILTER and TEST_REMOVE, which
should be comma-delimited lists of strings which are checked for a
substring match in the test name. A test is skipped if its group
is skipped, or if it does not match a filter and:
- it matches a remover, or
- no removers are specified but some filters are