Defines a set of functions to write test scripts.
(mosh test) uses (srfi :64 testing) as backend.
(import (rnrs) (mosh test) (test-begin "number predicate") (test-false (number? 'a)) (test-end))
Unit Testing | Defines a set of functions to write test scripts. |
(mosh test) | Unit Testing library |
Functions | |
test-begin | A test-begin enters a new test group. |
test-end | A test-end leaves the current test group. |
test-group | This is usually equivalent to executing the decl-or-exprs within the named test group. |
test-assert | This evaluates the expression. |
test-true | Run the test and check the result is not #f. |
test-false | Run the test and check the result is #f. |
test-eqv | This is equivalent to |
test-eq | This is equivalent to |
test-equal | This is equivalent to |
test-approximate | This is equivalent to (except that each argument is only evaluated once) |
test-read-eval-string | This function parses string (using read) and evaluates the result. |
test-error | Evaluating test-expr is expected to signal an error.The kind of error is indicated by error-type. |
Unit Testing library
Functions | |
test-begin | A test-begin enters a new test group. |
test-end | A test-end leaves the current test group. |
test-group | This is usually equivalent to executing the decl-or-exprs within the named test group. |
test-assert | This evaluates the expression. |
test-true | Run the test and check the result is not #f. |
test-false | Run the test and check the result is #f. |
test-eqv | This is equivalent to |
test-eq | This is equivalent to |
test-equal | This is equivalent to |
test-approximate | This is equivalent to (except that each argument is only evaluated once) |
test-read-eval-string | This function parses string (using read) and evaluates the result. |
test-error | Evaluating test-expr is expected to signal an error.The kind of error is indicated by error-type. |
A test-begin enters a new test group. The suite-name becomes the current test group name, and is added to the end of the test group path.
Portable test suites should use a sting literal for suite-name; the effect of expressions or other kinds of literals is unspecified.
(test-begin suite-name [count])
suite-name | test suite name. |
count | The optional count must match the number of test-cases executed by this group. (Nested test groups count as a single test case for this count.) This extra test may be useful to catch cases where a test doesn’t get executed because of some unexpected error. |
unspecified.
A test-end leaves the current test group. An error is reported if the suite-name does not match the current test group name.
Additionally, if the matching test-begin installed a new test-runner, then the test-end will de-install it, after reporting the accumulated test results in an implementation-defined manner.
(test-end [suite-name])
suite-name | test suite name. |
unspecified.
This is usually equivalent to executing the decl-or-exprs within the named test group.
However, the entire group is skipped if it matched an active test-skip (see later).
Also, the test-end is executed in case of an exception.
Equivalent to
(if (not (test-to-skip% suite-name)) (dynamic-wind (lambda () (test-begin suite-name)) (lambda () decl-or-expr ...) (lambda () (test-end suite-name))))
(test-group suite-name decl-or-expr ...)
suite-name | test suite name. |
decl-or-expr | decl-or-expr |
unspecified.
This evaluates the expression.
The test passes if the result is true; if the result is false, a test failure is reported. The test also fails if an exception is raised.
The test-name is a string that names the test case.
(Though the test-name is a string literal in the examples, it is an expression. It is evaluated only once.)
It is used when reporting errors, and also when skipping tests, as described below. It is an error to invoke test-assert if there is no current test runner.
(test-assert [test-name] expression)
test-name | test name. |
expression | expression to evaluate. |
unspecified.
This is equivalent to (except that each argument is only evaluated once)
(test-assert [test-name] (and (>= test-expr (- expected error)) (<= test-expr (+ expected error))))
Run the test and check the result is #f.
(test-approximate [test-name] expected test-expr error)
test-name | test name. |
expected | expected values |
test-expr | test-expr to evaluate. |
error | allowed error. |
unspecified.
This function parses string (using read) and evaluates the result.
The result of evaluation is returned from test-read-eval-string. An error is signalled if there are unread characters after the read is done.
(test-read-eval-string string)
string | string to evaluate. |
evalated result.
Evaluating test-expr is expected to signal an error.The kind of error is indicated by error-type.
If the error-type is left out, or it is #t, it means “some kind of unspecified error should be signaled”.
(test-error [[test-name] error-type] test-expr)
test-name | test name. |
error-type | error-type |
test-expr | test-expr to evaluate. |
unspecified.