zig/doc/langref/defer_unwind.zig
Alex Kladov 96bb1137c2 langref: don't encourage printing to stderr in tests
The rule: `pub fn main` owns file descriptors 0, 1, and 2. If you didn't
write `pub fn main()` it is, in general, not your business to print to
stderr.
2025-07-14 17:32:50 +01:00

23 lines
382 B
Zig

const std = @import("std");
const expect = std.testing.expect;
const print = std.debug.print;
pub fn main() void {
print("\n", .{});
defer {
print("1 ", .{});
}
defer {
print("2 ", .{});
}
if (false) {
// defers are not run if they are never executed.
defer {
print("3 ", .{});
}
}
}
// exe=succeed