Next: , Previous: , Up: API  


1.12 (veritas prelude)

1.12.1 Macros

Macro: evaluate-thunks x

Evaluate thunks one after another, keeping their order.

The result list lines up with the input list.

Macro: evaluate-thunks-concurrently x

Run thunks concurrently in fibers and collect what they return.

Blocks until every thunk has reported back through a shared channel. A thunk that raises sends a formatted error string instead of a value, so one failure cannot hang the run. Results come back in the order of thunks, not in completion order: two runs of one suite have to report the same lines, and which fiber finished first is not part of a result.

(evaluate-thunks-concurrently
 (list (lambda () (sleep 1) 'delayed)
       (lambda () 'instant)))
⇒ (delayed instant)

1.12.2 Parameters

Parameter: current-collector

Default value:

#f

1.12.3 Procedures

Procedure: add-result-counts a b

Return the sum of the count alists a and b.

Procedure: call-with-fiber-safe-wind before thunk after

Call thunk between before and after, safely under fibers.

Fibers suspends a task by unwinding to the scheduler and resumes it by winding back in, so a plain dynamic-wind runs its guards again every time the task yields - and a port operation is enough to yield. A guard that has a side effect - a module binding swapped, a directory removed, a VM engine changed - would then fire in the middle of the thunk. dynamic-wind* from (fibers scheduler) skips the guards during those round trips and runs them when the extent is really entered and really left, which is what every bracketing helper here wants.

(call-with-fiber-safe-wind
 (lambda () (module-set! module 'now 0))
 (lambda () (read-the-clock))
 (lambda () (module-set! module 'now original)))
Procedure: call-with-timeout seconds thunk KEY: #:on-timeout

Run thunk with an optional deadline of seconds seconds.

When seconds is a positive real number the work runs in its own fiber and, if it has not finished by then, the fiber is aborted and the result of calling on-timeout is returned instead. When seconds is #f (the default, meaning no deadline) thunk is simply called and its result is returned.

thunk must return a single value. The caller never waits for more than seconds, and the runaway fiber is terminated rather than left running.

(call-with-timeout 5
                   (lambda () (expensive-computation))
                   #:on-timeout (lambda () 'gave-up))
Procedure: capture-result-and-output thunk

Call thunk and return a result-and-output record.

The record holds what thunk returned together with everything it printed, so a test’s output can be reported next to its result.

Procedure: collect-assertion-successful xs

Return the outcome of every assertion in xs as a flat list.

Booleans only: #t for a pass, #f for a failure.

Procedure: collect-assertion-successful* xs

Return the assertion outcomes found inside xs.

Knows assertion, pre-test, test and suite results, and recurses into lists. Unspecified values, benchmarks and #t contribute nothing; an unrecognized type raises.

Procedure: collect-in! item

Record item in the active collector, and return item.

Does nothing else when no collector is bound, which is what building a case outside a body - at load time, or inside an assertion that runs later - looks like. #f is never recorded: a case a filter dropped is not a case.

Procedure: collector-items collector

Return what collector recorded, in the order the items were built.

Procedure: collector? value

Return #t when value is a collector made by make-collector.

Procedure: deduplicate-values values

Return values without the entries that are the same object as an earlier one.

Identity, not equality, decides: the same case built twice is two cases, while the same case both recorded and returned by one form is one.

Procedure: display-all-results vc all-results

Print and log every test outcome inside all-results using reporter client vc.

Iterates over the compilation of all-results. Evaluates types dynamically:

  • suite-result: Displays suite output, followed by inner test results.
  • pre-test-result: Logs the test identity via vc and displays inner assertions.
  • benchmark-result: Dispatches to log-benchmark.

Throws an explicit error if an unrecognized result type is processed.

Procedure: display-assertion-results assertion-results

Print the captured output of each record in assertion-results.

A record that is not an assertion gets printed as an error instead of bringing down the reporter.

Procedure: flatten-cases value case? expand OPT: depth

Return the cases value stands for, in order, leaving out what is not one.

case? recognises a case, expand evaluates a thunk-shaped body form, lists (of any depth) are walked, and anything else - an unspecified value, a number, a nested task in a place that wants assertions - contributes nothing. depth bounds the recursion, so a thunk that keeps returning thunks is a value that is ignored rather than a run that never ends.

Procedure: flatten-list xs

Flatten xs into a single list, however deeply it nests.

An atom that is not a list comes back wrapped in a one-element list.

Procedure: getenv-or var KEY: #:default

Return environment variable var, or default when it is unset.

var is a symbol. Anything that goes wrong while reading it yields default as well.

Procedure: make-collector

Return a fresh collector: a mutable list head of recorded items.

Procedure: make-timeout-assertion-result KEY: #:vc #:name #:timeout

Build the failed assertion-result reported for a timeout.

name is the timed task, timeout the seconds it was given and vc the client used to report it. A timeout fails the run exactly like any other failed assertion.

Procedure: nullary-procedure? proc

Return #t when proc can be called with no arguments at all.

A body form is wrapped in such a thunk by the DSL, and a thunk of this shape is therefore a body still to be evaluated rather than a case to run.

Procedure: procedure-required-arity proc

Return how many arguments proc needs, or #f when that is unknown.

Guile reports a procedure’s arity as the list (required optional rest?), or as several values on older versions; both are read here.

Procedure: result-counts result KEY: #:files

Return the files, suites, tests and assertions result records.

result is a result record or a list of them, at any depth: an assertion counts as one assertion, a test as one test, a suite as one suite, and a suite or a test that holds further results counts what it holds as well. files is how many test files the results stand for - one for the run of a single file - and is added to the files count.

A benchmark measures instead of asserting, and a task that raised arrives as the error string, so neither contributes a test or an assertion of its own.

(result-counts (list a-suite a-test) #:files 1)
⇒ ((files . 1) (suites . 1) (tests . 3) (assertions . 7))
Procedure: result-counts-summary counts

Return counts as one readable line.

(result-counts-summary '((files . 2) (suites . 3) (tests . 12) (assertions . 48)))
⇒ "2 files, 3 suites, 12 tests and 48 assertions"

1.12.4 Variables

Variable: empty-result-counts
((files . 0) (suites . 0) (tests . 0) (assertions . 0) (flaky . 0))

Next: (veritas property), Previous: (veritas model), Up: API