scmunit is a simple and lightweight test runner plus assertion library written in and for MIT Scheme (R7RS). scmunit comes with the following features:
- 🚀 Small footprint (100 lines of code, 4 kB)
- 🐣 Dead simple API (4 functions – that’s all there is)
- 📝 Concise yet helpful report
- ⏱ Runtime measurements
(load "scmunit.scm")
(define (increment x) (+ x 1))
(testcase* "increments numbers by 1" (list
(assert eq? (increment 0) 1)
(assert eq? (increment 12) 13)
))
(scmunit-run*)
Also, see another demonstration in test/example.scm.
Evaluates an expression against a predicate. The assertion is considered to be successful if the predicate returns true (#t
).
predicate
A predicate that takes the result ofexpression
as first argument andarguments
as subsequent argumentsexpression
The expression that you want to testarguments
Seepredicate
Container for grouping assertions and/or other testcases. Can be nested arbitrarily deep.
name
a string for recognising the testcase in the test output of the runneritems
a list of assertions and/or testcases
Same as (testcase ...)
, but it automatically registers the testcases with all its content, so that it gets picked up by the test runner. Supposed to be used at top-level.
Runs all testcases that had been registered via (testcase* ...)
, displays the result and exits the program with status 0
or 1
(depending on whether there were failed tests or not).
Provide the list of test items by means of a let
block:
(testcase "magic computation" (let ((MAGIC 42))
(define (square x) (* x x))
(list
(assert eq? (square MAGIC) 1764)
)))
Yes, arbitrarily deep:
(testcase "foo" (list
(testcase "bar" (list
(testcase "baz" (list
; ...
))
))
))