native test framework

This commit is contained in:
2026-07-17 22:36:17 +02:00
parent cedc63b28b
commit b09787029d
23 changed files with 141197 additions and 139688 deletions
+39
View File
@@ -0,0 +1,39 @@
debug :: import "@std/debug"
Error :: enum {
expectation_failed
}
SourceLocation :: struct {
file []u8
line usize
column usize
}
expect func(condition bool, location SourceLocation) void ! Error {
if (!condition) {
debug.print("{s}:{d}:{d}: expectation failed\n", {location.file, location.line, location.column})
return .expectation_failed
}
}
expect_equal func($T type, expected, actual T, location SourceLocation) void ! Error {
if (expected != actual) {
debug.print("{s}:{d}:{d}: expected {}, found {}\n", {location.file, location.line, location.column, expected, actual})
return .expectation_failed
}
}
run func(name []u8, callback *func() void ! Error) bool {
debug.print("RUN {s}\n", {name,})
callback() catch |_| {
debug.print("FAIL {s}\n", {name,})
return false
}
debug.print("PASS {s}\n", {name,})
return true
}
summary func(passed, failed i32) void {
debug.print("{d} passed, {d} failed\n", {passed, failed})
}