Next: (veritas bdd), Up: API
Assertions for Veritas. The core procedure is ‘assert’, which compares a value against an expected one using whatever predicate you give it. The assert-* procedures below are thin wrappers around it, together with a few helpers for checking error handling.
Every assertion also has a Latin alias, following the Latin naming already used by the BDD helpers (dato, quando, tunc, ...): (proba ...) is (assert ...), aequalis is assert-equal, verus is assert-true, continet is assert-contains, and so on. An alias is the exact same procedure object as its English name, so keyword arguments, semantics and reporting are identical. The complete mapping is documented in the README and repeated in the alias block at the end of this file.
Assert that got is equal? to expect.
The usual choice for lists, strings, vectors and other compound values.
Assert that got is eqv? to expect.
Good for numbers, characters and symbols, where value equivalence is what matters.
Return an assertion comparing got with expect using
compare, a two-argument predicate such as equal?.
The assert-* wrappers below are built on this one. got is
usually a plain value, but a list starting with compute,
comp or computare is evaluated when the assertion runs
instead: (assert #:got '(comp (+ 1 1)) ...) compares against
2. Deferring work that way is what makes it something a
timeout can actually catch.
name labels the assertion in the report. timeout caps it in
seconds; #f, the default, means no deadline.
(assert #:expect 3
#:got (+ 1 1 1)
#:compare equal?
#:name "Ensuring addition works")
Assert that got is within epsilon of expect.
The default epsilon is 1.0e-8.
Assert that the container expect contains got.
Works for strings (substring), lists and vectors (membership) and hash tables (key membership).
(assert-contains #:expect '(1 2 3) #:got 2) (assert-contains #:expect "hello world" #:got "world")
Assert that got is an empty list, vector or string.
Assert that got is eq? to expect.
The strictest of the equality assertions; use it for symbols, booleans and anything compared by identity.
Assert that got is equal? to expect.
The usual choice for lists, strings, vectors and other compound values.
Assert that got is eqv? to expect.
Good for numbers, characters and symbols, where value equivalence is what matters.
Return an assertion that thunk raises.
It fails if thunk returns normally. name labels it in the
report and timeout caps it in seconds, as in assert.
(assert-error (lambda () (sum-list-elements '(1 2 "a" 4)))
#:name "Should fail when list contains non-numbers")
Assert that x is #f.
Assert that got is within the inclusive range min–max.
Assert that got has expect elements (list, vector or string length).
Assert that the string got matches pattern.
pattern is a string or a compiled regexp.
(assert-matches #:pattern "^veri.*s$" #:got "veritas")
Return an assertion that thunk does not raise.
It fails if thunk raises. name labels it in the report and
timeout caps it in seconds, as in assert.
Assert that got differs from expect by at least epsilon.
Inverse of assert-approximate.
Assert that the container expect does not contain got.
Inverse of assert-contains.
Assert that got is a non-empty list, vector or string.
Assert that got is not eq? to expect.
Inverse of assert-eq.
Assert that got is not equal? to expect.
Inverse of assert-equal.
Assert that got is not eqv? to expect.
Inverse of assert-eqv.
Assert that string got does not match regular expression pattern.
Inverse of assert-matches.
Assert that got is equal? to one of the elements of list
expect.
Assert that calling thunk raises an error.
By default any error satisfies the assertion. Pass on to require
a specific error key (for example 'wrong-type-arg), or
predicate, a procedure of (key args) returning #t
for the expected error.
(assert-raises (lambda () (/ 1 0))) (assert-raises (lambda () (+ 1 'a)) #:on 'wrong-type-arg)
Assert that x is #t.
Assert that the string got matches pattern.
pattern is a string or a compiled regexp.
(assert-matches #:pattern "^veri.*s$" #:got "veritas")
Assert that the container expect contains got.
Works for strings (substring), lists and vectors (membership) and hash tables (key membership).
(assert-contains #:expect '(1 2 3) #:got 2) (assert-contains #:expect "hello world" #:got "world")
Return an assertion that thunk raises.
It fails if thunk returns normally. name labels it in the
report and timeout caps it in seconds, as in assert.
(assert-error (lambda () (sum-list-elements '(1 2 "a" 4)))
#:name "Should fail when list contains non-numbers")
Assert that x is #f.
Assert that got is eq? to expect.
The strictest of the equality assertions; use it for symbols, booleans and anything compared by identity.
Assert that got is an empty list, vector or string.
Assert that got is within the inclusive range min–max.
Return #t when a and b differ by less than
epsilon.
Useful for floating point, where exact equality rarely holds.
Assert that got has expect elements (list, vector or string length).
Return assertion, a procedure of one validation client, as a case to run.
The returned procedure is tagged so the runner can tell an assertion
from a task, and it records having run, which is how an assertion the
body itself consumes - with value or ok?, say - stays an
input to another case instead of becoming a case of its own.
It is also registered with the collector of the body being evaluated, if
there is one. That registration is what keeps a body form that builds
several assertions, such as the body of a let, from contributing
only the value of its last expression. Building an assertion outside
any body - at load time, or inside an assertion that runs later - simply
registers nothing.
Assert that got is not equal? to expect.
Inverse of assert-equal.
Assert that got is not eqv? to expect.
Inverse of assert-eqv.
Assert that string got does not match regular expression pattern.
Inverse of assert-matches.
Assert that the container expect does not contain got.
Inverse of assert-contains.
Return an assertion that thunk does not raise.
It fails if thunk raises. name labels it in the report and
timeout caps it in seconds, as in assert.
Assert that got is not eq? to expect.
Inverse of assert-eq.
Assert that got is a non-empty list, vector or string.
Assert that got differs from expect by at least epsilon.
Inverse of assert-approximate.
Return an assertion comparing got with expect using
compare, a two-argument predicate such as equal?.
The assert-* wrappers below are built on this one. got is
usually a plain value, but a list starting with compute,
comp or computare is evaluated when the assertion runs
instead: (assert #:got '(comp (+ 1 1)) ...) compares against
2. Deferring work that way is what makes it something a
timeout can actually catch.
name labels the assertion in the report. timeout caps it in
seconds; #f, the default, means no deadline.
(assert #:expect 3
#:got (+ 1 1 1)
#:compare equal?
#:name "Ensuring addition works")
Assert that got is within epsilon of expect.
The default epsilon is 1.0e-8.
Return #t when a and b differ by less than
epsilon.
Useful for floating point, where exact equality rarely holds.
Assert that calling thunk raises an error.
By default any error satisfies the assertion. Pass on to require
a specific error key (for example 'wrong-type-arg), or
predicate, a procedure of (key args) returning #t
for the expected error.
(assert-raises (lambda () (/ 1 0))) (assert-raises (lambda () (+ 1 'a)) #:on 'wrong-type-arg)
Assert that got is equal? to one of the elements of list
expect.
Assert that x is #t.
Next: (veritas bdd), Up: API