This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 9/16/2026.
Testing
~import std/testingKoru Testing Framework
testing.kz · 5 tors · ~[comptime]
Koru Testing Framework · 16 more lines
Koru Testing Framework
Compiler-guided test development with automatic mock detection.
Usage:
test(User cannot withdraw more than balance) {
account.balance = amount 50
app:withdraw(amount: 100)
| insufficient_funds |> assert.ok()
}
The compiler:
1. Traces the flow to find impure events
2. Errors if impure event not mocked
3. Errors if mock is unused
4. Generates Zig test block
// Test Declaration
//
// Main test event - takes name as Expression, body as Source
// Transform generates Zig test blocks using real emitter infrastructure
~[keyword|comptime|transform] pub tor test {
expr: Expression,
source: Source,
invocation: *const Invocation,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
allocator: std.mem.Allocator
} -> SiteResult~[comptime|retain] pub tor validate-mocks {
program: std/compiler:*const Program,
mocks: std/compiler:[]const Item,
source: *const Source,
allocator: std.mem.Allocator
}
| ok
| failed string// Test with shared harness (mocks can be unused per-test)
~[keyword|comptime|transform] pub tor test.with-harness {
expr: Expression,
harness: string,
source: Source
}// Define a test harness with shared mocks
~[keyword|comptime|transform] pub tor test.harness {
expr: Expression,
source: Source
}~[comptime|transform] pub tor test.property.equivalent { source: Source }