This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/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 tors
2. Errors if impure tor not mocked
3. Errors if mock is unused
4. Generates Zig test block
// Test Declaration
//
// Main test tor - 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 }~part assert koru_std/testing.assert.kz
Koru Standard Library: the `assert` part of testing.kz. Joined via `~part assert` in testing.kz; merged into the testing module at load. Assertions Pass-through assertion checkpoint Usage: assert(u.name == "Alice") |> next_step() Panics with message if expression is false, otherwise continues
// Koru Standard Library: the `assert` part of testing.kz.
// Joined via `~part assert` in testing.kz; merged into the testing module at load.
//
// 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: std/compiler:*const Item,
program: std/compiler:*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: ?string }~part compare koru_std/testing.compare.kz
Koru Standard Library: the `compare` part of testing.kz. Joined via `~part compare`; merged into the testing module at load. Equality assertion
// Koru Standard Library: the `compare` part of testing.kz.
// Joined via `~part compare`; merged into the testing module at load.
//
// Equality assertion
~[keyword|comptime|transform|pure] pub tor assert.eq {
expected: Expression,
actual: Expression,
invocation: *const Invocation,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
allocator: std.mem.Allocator
} -> SiteResult// Contains assertion (for strings/slices)
~[keyword|comptime|transform|pure] pub tor assert.contains {
haystack: Expression,
needle: Expression,
invocation: *const Invocation,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
allocator: std.mem.Allocator
} -> SiteResult