This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 8/19/2026.
Testing
~import std/testingKoru Testing Framework
testing.kz · 10 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: *const Item,
program: *const Program,
allocator: std.mem.Allocator
} -> SiteResult~[comptime|retain] pub tor validate-mocks {
program: *const Program,
mocks: []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
}// Assertions
//
// Pass-through assertion checkpoint
// Usage: assert(u.name == "Alice") |> next_step()
// Panics with message if expression is false, otherwise continues
~[keyword|comptime|transform|pure] pub tor assert {
expr: Expression,
invocation: *const Invocation,
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
} -> SiteResult// Simple pass - marks a test branch as passing (noop)
~[keyword|comptime|transform|pure] pub tor assert.ok {}// Simple fail - fails the test with optional message
~[keyword] pub tor assert.fail { message: ?[]const u8 }// Equality assertion
~[keyword] pub tor assert.eq { expected: Expression, actual: Expression }
| ok
| failed { expected: string, actual: string }// TODO: Transform to generate Zig equality check
//
// Contains assertion (for strings/slices)
~[keyword] pub tor assert.contains { haystack: Expression, needle: Expression }
| ok
| failed~[comptime|transform] pub tor test.property.equivalent { source: Source }