mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 06:15:21 +00:00
std.testing: allow print() at comptime
This allows functions like expectEqual to be performed at comptime. If an error is detected, the result is logged via a compile error.
This commit is contained in:
parent
839a93a101
commit
dc44baf763
@ -22,10 +22,14 @@ pub var base_allocator_instance = std.heap.FixedBufferAllocator.init("");
|
||||
pub var log_level = std.log.Level.warn;
|
||||
|
||||
fn print(comptime fmt: []const u8, args: anytype) void {
|
||||
// Disable printing in tests for simple backends.
|
||||
if (builtin.zig_backend == .stage2_spirv64) return;
|
||||
if (@inComptime()) {
|
||||
@compileError(std.fmt.comptimePrint(fmt, args));
|
||||
} else {
|
||||
// Disable printing in tests for simple backends.
|
||||
if (builtin.zig_backend == .stage2_spirv64) return;
|
||||
|
||||
std.debug.print(fmt, args);
|
||||
std.debug.print(fmt, args);
|
||||
}
|
||||
}
|
||||
|
||||
/// This function is intended to be used only in tests. It prints diagnostics to stderr
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user