Outdated egg!
This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.
If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.
SRFI-78
The aim of lightweight testing is to provide a simple set of procedures for defining and running tests.
The original SRFI documentation is available at: http://srfi.schemers.org/srfi-78/
Examples
check
(check ''expression'' => ''expected'')
(check ''expected'' (=> ''predicate'') ''expected'')
Evaluates expression and expected, comparing the results using the given predicate or equal?, in the first case. Then, depending on the current mode, a report will be printed and the counts of passed/failed tests updated.
> (check (+ 1 1) => 2) (+ 1 1) => 2 ;; correct > (check (list (+ 1 1) "a b c") (=> (lambda (a b) (string=? (cadr a) (cadr b)))) (list (+ 2 1) "a b c")) (list (+ 1 1) "a b c") (=> (lambda (a b) (string=? (cadr a) (cadr b)))) (2 "a b c") ;; correct > (check (list (+ 1 1) "a b c") (=> (lambda (a b) (string=? (cadr a) (cadr b)))) (list 2 "a b c d")) (list (+ 1 1) "a b c") (=> (lambda (a b) (string=? (cadr a) (cadr b)))) (2 "a b c") ;; *** failed *** ;; expected result: (2 "a b c d")
check-ec
check-ec uses eager comprehensions, as in SRFI 42, to provide a form of automated bulk tested. Therefore, you must import SRFI 42 before you can use this macro.
(check-ec ''qualifier'' ... ''expression'' => ''expected'')
(check-ec ''qualifier'' ... ''expected'' (=> ''predicate'') ''expected'')
(check-ec ''qualifier'' ... ''expression'' => ''expected'' (''argument'' ...))
(check-ec ''qualifier'' ... ''expected'' (=> ''predicate'') ''expected'' (''argument'' ...))
The qualifer ... are one or more qualifiers, as defined in SRFI 42. Values for expression and expected are computed for each value of the qualifiers, and results compared. The test stops as soon as one set of values fails to match. The optional list of arguments are variable names which can be printed in the event of a failed test.
A simple example of bulk testing:
> (check-ec (: i 10) (: j 10) (: k 10) (+ (* i j) (* i k)) (=> =) (* i (+ j k))) (check-ec (nested (: i 10) (: j 10) (: k 10)) (+ (* i j) (* i k)) (=> =) (* i (+ j k)) ()) (=> =) <void> ;; correct (1000 cases checked)
An illustration of how variable names can be displayed in the event of an error (the variable value is given in the let form):
> (check-ec (: e 100) (:let x (expt 2.0 e)) (= (+ x 1) x) => #f (x)) (let ((x 9.007199254740992e15)) (= (+ x 1) x)) => #t ;; *** failed *** ;; expected result: #f
The following example sets up a list of input and expected output values:
> (check-ec (: i '((1 1) (2 4) (3 9) (4 16))) (* (car i) (car i)) => (cadr i)) (check-ec (: i '((1 1) (2 4) (3 9) (4 16))) (* (car i) (car i)) (=> equal?) (cadr i) ()) => <void> ;; correct (4 cases checked)
check-passed?
(check-passed? ''expected-total'') -> ''boolean''
Compares the actual number of passed tests so far with the given expected number, returning #t if they are equal and #f if not.
check-report
(check-report)
Depending on the current mode, this prints a report and the first failed test (if any).
> (check-report) ;; *** checks *** : 1 correct, 1 failed. First failed example: (+ 1 1) => 2 ;; *** failed *** ;; expected result: 2.0
check-reset!
(check-reset!)
Resets the counter of numbers of tests passed/failed. (This may be used to display multiple reports for different parts of the code.)
check-set-mode!
(check-set-mode! ''mode'') -> unspecified
Changes the current mode to one of the following:
- off: do not execute any of the checks
- summary: print only summary in check-report and nothing else
- report-failed: report failed checks when they happen, and in summary
- report: report every example executed
The default is report
Authors
SRFI 78 was written by Sebastian Egner, and this port to Chicken was made by Peter Lane.
License
Released under a SRFI license.
Requirements
To use check-ec you will also need srfi-42 installed.
Version History
version 1.0: first package.