gizlang:test
assertions, generated inputs and shrinking, for test functions (function testName(): void, run by giz test FILE) and for programs.
An assertion that does not hold faults (R004) inside itself, so the fault trace carries what failed with its values and where it was called: equal line 1 (actual = 4, expected = 5) <- testAdd (main.giz:12). The test fails with that trace and a replay test reproducing the call, and the other tests still run. Nothing is collected or formatted on success.
import * as Test from "gizlang:test";Functions
equal
function equal<T>(actual: T, expected: T): voidactual is expected (===: numbers, bools, strings, bytes, and records, unions and Vecs by content; a record shows its fields in the trace).
differ
function differ<T>(actual: T, unexpected: T): voidactual is not unexpected.
check
function check(condition: bool): voidcondition holds; the trace shows the calling line.
Effects: fail.
maxError
function maxError(actual: Vec<f32>, expected: Vec<f32>): f64The largest |actual[i] - expected[i]| of a numeric result and its reference, which have the same length.
Effects: fail.
relativeError
function relativeError(actual: Vec<f32>, expected: Vec<f32>): f64maxError over the largest |expected[i]|.
Effects: fail.
includes
function includes(text: string, part: string): voidtext contains part.
Effects: fail.
equalLines
function equalLines(actual: string, expected: string): voidTwo texts are equal; on a difference the trace shows the first differing line and column, and both lines from just before it (a trace keeps 32 bytes of a string), not two whole texts.
Effects: fail.
equalItems
function equalItems<T>(actual: Vec<T>, expected: Vec<T>): voidTwo Vecs are equal item by item; on a difference the trace shows the first differing index and both items, or both lengths.
forAll
function forAll<T>(seed: u64, runs: i64, generate: (seed: u64, size: i64) => T, smaller: (value: T) => Vec<T>, holds: (value: T) => bool, failing: (value: T) => void): voidA property over generated inputs: holds is tried on runs values from
generate, given each run's own seed (from seed, so the same seed gives
the same inputs; build a newRandom(seed) from it) and a size growing from
0 to 100. The first value it rejects is shrunk by smaller (values simpler
than one; none for the simplest) to a minimal counterexample, which
failing receives: its assertion faults with that value in the trace.
shrunk
function shrunk<T>(value: T, smaller: (value: T) => Vec<T>, holds: (value: T) => bool): TThe smallest form of VALUE that still fails HOLDS: it tries the candidates of SMALLER until none fails.
smallerI64
function smallerI64(n: i64): Vec<i64>Simpler i64s than n, toward 0: 0, n/2, n-1 (or n+1 below 0).
Effects: fail.
smallerVec
function smallerVec<T>(v: Vec<T>, item: (value: T) => Vec<T>): Vec<Vec<T>>Simpler Vecs than v: without its second half, without each item, and
with each item simpler (by item).