https://github.com/jotaen/scmunit
Lightweight unit testing and assertion library for MIT Scheme.
https://github.com/jotaen/scmunit
lisp mit-scheme scheme scheme-language testing
Last synced: 3 months ago
JSON representation
Lightweight unit testing and assertion library for MIT Scheme.
- Host: GitHub
- URL: https://github.com/jotaen/scmunit
- Owner: jotaen
- Created: 2020-04-20T14:11:31.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-14T18:29:02.000Z (about 5 years ago)
- Last Synced: 2025-01-10T03:26:57.429Z (5 months ago)
- Topics: lisp, mit-scheme, scheme, scheme-language, testing
- Language: Scheme
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# scmunit – Unit testing for Scheme with ease
*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## Example
```scheme
(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](example.scm).
## Reference
### `(assert predicate expression [arguments])`
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 of `expression` as first argument and `arguments` as subsequent arguments
- `expression` The expression that you want to test
- `arguments` See `predicate`### `(testcase name [items])`
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 runner
- `items` a list of assertions and/or testcases### `(testcase* ...)`
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.
### `(scmunit-run*)`
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).
## FAQ
### How can I declare local variables or functions in a testcase?
Provide the list of test items by means of a `let` block:
```scheme
(testcase "magic computation" (let ((MAGIC 42))
(define (square x) (* x x))
(list
(assert eq? (square MAGIC) 1764)
)))
```### Can test testcases be nested?
Yes, arbitrarily deep:
```scheme
(testcase "foo" (list
(testcase "bar" (list
(testcase "baz" (list
; ...
))
))
))
```