API Reference
Functions
fn blackBox(val: Any): AnyOpaque pass-through that defeats dead-code elimination in benchmarks.
The value goes through the backend's black-box barrier instead of being
folded at compile time, then comes back untouched, so a call to it reads
like any other call. It takes exactly one argument: two or more is a
compile error, reported as "std.testing.blackBox takes 1 args". A tuple
argument is refused as well: "tuple value cannot be used in blackBox".
The result is typed Any. The runtime type survives, so typeOf still
reports Int, Float, String, and the rest, and arithmetic on the
result works. Assigning it to a narrower binding is not: let n: Int = blackBox(7) is a type error, so pass the result straight on or declare
the binding as Any.
val : any single value.
returns: val unchanged.
import { blackBox } from "@std/testing";
bench "sum" {
let total = 0;
let i = 0;
while i < 1000 {
total = total + i;
i = i + 1;
}
blackBox(total);
}
fn Main(): Int {
println!(blackBox(2) + blackBox(3));
return 0;
}fn liveCount(): IntLive allocation count for leak assertions in tests.
Reads the runtime's live object-plus-array count: the same number the toolchain itself uses to balance allocations in its own test suite. Snapshot it before and after the code under test and compare the two; user code must never branch on it for control flow, only assert balance in tests.
returns: live allocations at the call instant.
import { liveCount, blackBox } from "@std/testing";
fn Main(): Int {
let before = liveCount();
let v = [1, 2, 3];
blackBox(v);
return liveCount() - before;
}