Next: , Previous: , Up: checks   [Index]


17.2 Evaluating code

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

Evaluate expr and compare its return value to the return 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).

When name is given: it is the name of this test, Selecting tests to be run.

Function: check-report

Print a summary and the first failed check, if there is any, depending on the current mode settings. Call exit to exit the current process with code:

0

If all the tests were run successfully.

1

If at least one test failed.

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 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))
Syntax: false-if-exception form0 form ...

Evaluate all the forms as in begin. If an exception is raised: return #f.

Syntax: check-for-true expr
Syntax: check-for-true name expr
Syntax: check-for-false expr
Syntax: check-for-false name expr

Evaluate expr in a check form, expecting a non–false or #f value as result.

When name is given: it is the name of this test, Selecting tests to be run.

Syntax: check-for-assertion-violation ?body => ?expected-who/irritants
Auxiliary Syntax: =>

Expand to:

(check
    (guard (E ((assertion-violation? E)
               (list (condition-who E)
                     (condition-irritants E))
              (else E))
      ?body)
  => ?expected-who/irritants))
Syntax: check-for-procedure-argument-violation ?body => ?expected-who/irritants
Auxiliary Syntax: =>

Expand to:

(check
    (guard (E ((procedure-argument-violation? E)
               (list (condition-who E)
                     (condition-irritants E))
              (else E))
      ?body)
  => ?expected-who/irritants))
Syntax: check-for-procedure-signature-argument-violation ?body => ?expected-who/irritants
Auxiliary Syntax: =>

Expand to:

(check
    (guard (E ((procedure-argument-violation? E)
               (list (condition-who E)
                     (procedure-argument-violation.one-based-argument-index E)
                     (procedure-argument-violation.failed-expression E)
                     (procedure-argument-violation.offending-value E)))
              (else E))
      ?body)
  => ?expected-who/irritants)
Syntax: check-for-procedure-signature-return-value-violation ?body => ?expected-who/irritants
Auxiliary Syntax: =>

Expand to:

(check
    (guard (E ((procedure-signature-return-value-violation? E)
               (list (condition-who E)
                     (procedure-signature-return-value-violation.one-based-return-value-index E)
                     (procedure-signature-return-value-violation.failed-expression E)
                     (procedure-signature-return-value-violation.offending-value E)))
              (else E))
      ?body)
  => ?expected-who/irritants)
Syntax: check-for-procedure-arguments-consistency-violation ?body => ?expected-who/irritants
Auxiliary Syntax: =>

Expand to:

(check
    (guard (E ((procedure-arguments-consistency-violation? E)
               (list (condition-who E)
                     (condition-irritants E)))
              (else E))
      ?body)
  => ?expected-who/irritants)
Syntax: check-for-expression-return-value-violation ?body => ?expected-who/irritants
Auxiliary Syntax: =>

Expand to:

(check
    (guard (E ((expression-return-value-violation? E)
               (list (condition-who E)
                     (condition-irritants E)))
              (else E))
      ?body)
  => ?expected-who/irritants)

Next: , Previous: , Up: checks   [Index]