Next: , Up: API  


1.1 (veritas assert)

This module is a Scheme testing library that provides a comprehensive set of assertion functions. At its core is the assert-equal* 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.

1.1.1 Procedures

Procedure: assert-eq KEY: #:expect #:got #:name

Undocumented procedure.

Procedure: assert-equal KEY: #:expect #:got #:name

Undocumented procedure.

Procedure: assert-equal* KEY: #:expect #:got #:compare #:name

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-equal* #:got '(compute (+ 1 1)) ...) would evaluate (+ 1 1) to 2 before the comparison.

expect

The expected value.

got

The value to compare against, or a list to be computed.

compare

The comparison procedure, which should be a function of two arguments, e.g., ‘equal?‘, ‘eqv?‘, or ‘eq?‘.

name

A doc string to identify the assertion in the logs.

(assert-equal* #: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"))
Procedure: assert-eqv KEY: #:expect #:got #:name

Undocumented procedure.

Procedure: assert-error thunk KEY: #:name

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.

thunk

A procedure of no arguments to be executed.

name

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"))
Procedure: assert-false x KEY: #:name

Undocumented procedure.

Procedure: assert-no-error thunk KEY: #:name

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.

thunk

A procedure of no arguments to be executed.

name

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))
Procedure: assert-true x KEY: #:name

Undocumented procedure.


Next: (veritas model), Up: API