Next: , Previous: , Up: srfi lightweight-testing   [Index]


2.30.4 Specification

Syntax: check expr (=> equal) expected
Syntax: check expr => expected

Evaluate expr and compare the value to the value of expected using the predicate equal, which is equal? when omitted. Then a report is printed according to the current mode setting (see below) and the outcome is recorded in a global state to be used in check-report.

The precise order of evaluation is that first equal and expected are evaluated (in unspecified order) and then expr is evaluated. Example: (check (+ 1 1) => 2).

Syntax: check-ec qualifier* expr (=> equal) expected (argument*))
Syntax: check-ec qualifier* expr => expected (argument*)
Syntax: check-ec qualifier* expr (=> equal) expected
Syntax: check-ec qualifier* expr => expected

An eager comprehension for executing a parametric sequence of checks.

Enumerate the sequence of bindings specified by qualifier*. For each binding evaluate equal and expected in unspecified order. Then evaluate expr and compare the value obtained to the value of expected using the value of equal as predicate, which is equal? when omitted.

The comprehension stops after the first failed check, if there is any. Then a report is printed according to the current mode setting (see below) and the outcome is recorded in a global state to be used in check-report. The entire check-ec counts as a single check.

In case the check fails argument* is used for constructing an informative message with the argument values. Use argument* to list the relevant free variables of expr (see examples) that you want to have printed.

A qualifier is any qualifier of an eager comprehension as specified in SRFI-42.

Examples:

(check-ec (: e 100)
          (positive? (expt 2 e))
          => #t (e)) ; fails on fixnums

(check-ec (: e 100)
          (:let x (expt 2.0 e))
          (= (+ x 1) x)
          => #f (x)) ; fails

(check-ec (: x 10)
          (: y 10)
          (: z 10)
          (* x (+ y z))
          => (+ (* x y) (* x z))
             (x y z)) ; passes with 10^3 cases checked
Function: check-report

Print a summary and the first failed check, if there is any, depending on the current mode settings.

Function: check-set-mode! mode

Set the current mode to mode, which must be a symbol among: off, summary, report-failed, report; the default is report. Note that you can change the mode at any time, and that check, check-ec and check-report use the current value.

The mode symbols have the following meaning:

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.

Function: check-reset!

Reset the global state (counters of correct/failed examples) to the state immediately after loading the module for the first time, i.e. no checks have been executed.

Function: check-passed? expected-total-count

Return #t if there were no failed checks and expected-total-count correct checks, #f otherwise.

Rationale: This procedure can be used in automatized tests by terminating a test program with the statement:

(exit (if (check-passed? n) 0 1))

Next: , Previous: , Up: srfi lightweight-testing   [Index]