jc/test/module.jai
2025-05-11 02:29:36 -06:00

48 lines
1,010 B
Text

T :: struct {
location: Source_Code_Location;
expects_run: int;
expects_ok: int;
failed: bool;
}
Proc :: #type (t: *T);
expect :: (t: *T, cond: bool, message := "", args: ..Any, loc := #caller_location) {
t.expects_run += 1;
if cond {
t.expects_ok += 1;
return;
}
msg := "expectation failed";
if message.count != 0 {
msg = basic.tprint(message, ..args);
}
t.failed = true;
if #compile_time {
compiler.compiler_report(msg, loc = loc, mode = .ERROR_CONTINUABLE);
}
else {
basic.assert(false, msg, loc = loc);
}
}
run :: (name: string, proc: Proc, loc := #caller_location) {
filename := strings.path_filename(loc.fully_pathed_filename);
basic.print("test %,%: %...", filename, loc.line_number, name);
t: T;
proc(*t);
if t.failed {
basic.print(" failed!\n");
}
else {
basic.print(" ok!\n");
}
}
basic :: #import "Basic";
strings :: #import "String";
compiler :: #import "Compiler";