veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

testing

lib/testing.vk

lib/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
signature
Suite = struct { name str, passed i64 = ..., failed i64 = ..., failures block[str] = ... }

Mutable test suite accumulator tracking pass/fail counts and failure diagnostics.

signature
BenchResult = struct { name str, iters i64, total_ns i64, ns_per_op i64 }

Timing result returned by testing/bench.

new fn
signature
new = fn [name str] Suite

Creates a new empty test Suite with the given name.

Executable Example
veko
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 ]
ok fn
signature
ok = fn [mut s Suite, cond bool, label str] bool

Asserts that cond is true.

eq fn
signature
eq = fn [mut s Suite, actual any, expected any, label str] bool

Asserts that actual == expected.

neq fn
signature
neq = fn [mut s Suite, actual any, unexpected any, label str] bool

Asserts that actual != unexpected.

signature
is-err = fn [mut s Suite, val any, label str] bool

Asserts that val is a Veko err.

signature
is-ok = fn [mut s Suite, val any, label str] bool

Asserts that val is not a Veko err.

signature
approx = fn [mut s Suite, actual f64, expected f64, eps f64, label str] bool

Asserts that two floats are within eps (|actual - expected| <= eps).

signature
finish = fn [s Suite] i64

Finalizes a Suite, returning 0 when all assertions passed or an err summarizing failures.

signature
report = fn [s Suite] i64

Prints a compact single-line summary for s and returns finish s.

bench fn caps: .clocks
signature
bench = fn [name str, iters i64, work fn[->any]] BenchResult

Executes work iters times and returns monotonic timing measurements (BenchResult).

Executable Example
veko
use [t = testing]
b = t/bench 'noop' 10 fn [] [ 1 + 1 ]
if b.iters != 10 [ err 'bench iters mismatch' ] else [ .ok ]