Next: (veritas model), Up: API
This module is a Scheme testing library that provides a comprehensive set of assertion functions. At its core is the assert procedure, a flexible and powerful tool for comparing an expected value against a result.
Beyond simple value comparison, the module offers a set of tools for testing program behavior related to error handling.
These functions provide a complete assertion toolkit, enabling developers to write robust tests that cover both expected outcomes and predictable failures, thereby improving the reliability and quality of their Scheme code.
Returns a function taking a VC (veritas-context) that returns an assertion that two values are equal based on a given comparison procedure. This is the core assertion procedure that the other ‘assert-equal‘ variants are built upon. It’s used to compare an expected value with a computed value.
The got parameter can be a value or a special list to compute a
value dynamically. If got is a list starting with compute,
comp, or computare, the second element of the list is
evaluated to get the actual value for comparison.
For example, (assert #:got '(compute (+ 1 1)) ...) would evaluate
(+ 1 1) to 2 before the comparison.
The expected value.
The value to compare against, or a list to be computed.
The comparison procedure, the predicate, which should be a function of two arguments, e.g., ‘equal?‘, ‘eqv?‘, or ‘eq?‘.
A doc string to identify the assertion in the logs.
(assert #:expect 3
#:got (+ 1 1 1)
#:compare equal?
#:name "Ensuring addition works")
⇒ #<procedure 7f58ec5ce390 at veritas/assert.scm:69:2 (vc)>
;; Upon applying vc to the procedure we will compute the assertion:
`((assertion-successful . #t)
(assertion-name "Ensuring addition works"))
Returns a function taking a VC (veritas-context) that returns an assertion checking that expect and got are approximately equal.
Two values are considered approximately equal if their difference is smaller than epsilon.
This is useful for floating-point computations.
(assert-approximate #:expect 3.14
#:got 3.141
#:epsilon 0.01)
Returns a function taking a VC (veritas-context) that returns an
assertion checking that expect and got are identical using
eq?.
This is the strictest equality assertion and is typically used for symbols, booleans, and identity-sensitive comparisons.
It is a convenience wrapper around assert.
The expected value.
The value to compare against.
A string to identify the assertion in the logs.
(assert-eq #:expect 'foo
#:got 'foo)
Returns a function taking a VC (veritas-context) that returns an
assertion checking that expect and got are structurally
equal using equal? predicate.
This is the standard assertion for comparing lists, strings, vectors, and other compound data structures.
It is a convenience wrapper around assert.
The expected value.
The value to compare against.
A string to identify the assertion in the logs.
(assert-equal #:expect '(1 2 3)
#:got '(1 2 3)
#:name "Lists should match")
Returns a function taking a VC (veritas-context) that returns an
assertion checking that expect and got are equivalent using
eqv? predicate.
This is useful for comparing numbers, characters, and symbols where value equivalence matters.
It is a convenience wrapper around assert.
The expected value.
The value to compare against.
A string to identify the assertion in the logs.
(assert-eqv #:expect 42
#:got (+ 40 2))
Returns a function taking a VC (veritas-context) that returns an assertion that checks that a thunk (a procedure with no arguments) raises an error when called.
This is a crucial function for testing error-handling logic. It attempts to execute the provided thunk. If an error is caught during its execution, the assertion passes. If the thunk completes without raising an error, the assertion fails.
A procedure of no arguments to be executed.
A string to identify the assertion in the logs.
(assert-error (lambda ()
(sum-list-elements '(1 2 "a" 4)))
#:name
"Should fail when list contains non-numbers")
⇒ #<procedure 8f58ec5ce390 at veritas/assert.scm:69:2 (vc)>
;; Upon applying vc to the procedure we will compute the assertion:
`((assertion-successful . #t)
(assertion-name "Should fail when list contains non-numbers"))
Returns a function taking a VC (veritas-context) that returns an
assertion checking that x is #f.
This is a convenience wrapper for boolean falsehood assertions.
(assert-false (< 5 2)
#:name "5 is not less than 2")
Returns a function taking a VC (veritas-context) that returns an assertion that checks that a thunk (a procedure with no arguments) does not raise an error when called.
This is a crucial function for testing error-handling logic. It attempts to execute the provided thunk. If no error is caught during its execution, the assertion passes. If the thunk raises an error, the assertion fails.
A procedure of no arguments to be executed.
A string to identify the assertion in the logs.
(assert-no-error (lambda ()
(sum-list-elements '(1 2 "a" 4))))
⇒ #<procedure 8f58ec5ce390 at veritas/assert.scm:69:2 (vc)>
;; Upon applying vc to the procedure we will compute the assertion:
`((assertion-successful . #f))
Returns a function taking a VC (veritas-context) that returns an assertion checking that expect and got are not approximately equal.
This assertion passes when the difference between the values is greater than or equal to epsilon.
It is the inverse of assert-approximate.
(assert-not-approximate #:expect 3.14
#:got 3.5
#:epsilon 0.01)
Returns a function taking a VC (veritas-context) that returns an
assertion checking that expect and got are not identical
using eq?.
This assertion passes when the two values do not share identity.
It is the inverse of assert-eq.
(assert-not-eq #:expect '(1 2)
#:got '(1 2))
Returns a function taking a VC (veritas-context) that returns an
assertion checking that expect and got are not structurally
equal using equal?.
This assertion is useful when testing for inequality of compound values.
It is the inverse of assert-equal.
(assert-not-equal #:expect '(1 2 3)
#:got '(1 2 4))
Returns a function taking a VC (veritas-context) that returns an
assertion checking that expect and got are not equivalent
using eqv?.
This assertion is useful when values should differ in meaning or representation.
It is the inverse of assert-eqv.
(assert-not-eqv #:expect 1
#:got 2)
Returns a function taking a VC (veritas-context) that returns an
assertion checking that x is #t.
This is a convenience wrapper for boolean truth assertions.
(assert-true (> 5 2)
#:name "5 is greater than 2")
Returns #t if the absolute difference between a and b
is smaller than epsilon.
This is useful for comparing floating-point values where exact equality may not be reliable.
The first numeric value.
The second numeric value.
The maximum allowed difference.
(is-approximate? 3.14159 3.14160
#:epsilon 0.0001)
⇒ #t
Next: (veritas model), Up: API