testing
lib/testing.vklib/testing.vk
Pure-Veko unit test suite assertions and monotonic micro-benchmarking harness.
Zero capabilities required for assertions; bench uses time/now (.clocks).
Suite = struct { name str, passed i64 = ..., failed i64 = ..., failures block[str] = ... }
Mutable test suite accumulator tracking pass/fail counts and failure diagnostics.
BenchResult = struct { name str, iters i64, total_ns i64, ns_per_op i64 }
Timing result returned by testing/bench.
new = fn [name str] Suite
Creates a new empty test Suite with the given name.
Executable Example
use [t = testing]
mut s = t/new 'math-smoke'
_ = t/eq mut s (2 + 2) 4 'addition'
r = t/finish s
if err? r [ r ] else [ .ok ]
neq = fn [mut s Suite, actual any, unexpected any, label str] bool
Asserts that actual != unexpected.
approx = fn [mut s Suite, actual f64, expected f64, eps f64, label str] bool
Asserts that two floats are within eps (|actual - expected| <= eps).
finish = fn [s Suite] i64
Finalizes a Suite, returning 0 when all assertions passed or an err summarizing failures.
bench = fn [name str, iters i64, work fn[->any]] BenchResult
Executes work iters times and returns monotonic timing measurements (BenchResult).
Executable Example
use [t = testing]
b = t/bench 'noop' 10 fn [] [ 1 + 1 ]
if b.iters != 10 [ err 'bench iters mismatch' ] else [ .ok ]