zig/test/incremental/assert_function.7.zig
Jakub Konka c1a98cd65d test: set case name from initial filename for a sequence
Port more incremental tests.
2022-04-28 18:35:01 +02:00

41 lines
800 B
Zig

const builtin = @import("builtin");
extern "c" fn write(usize, usize, usize) usize;
pub fn main() void {
var i: u32 = 0;
while (i < 4) : (i += 1) print();
assert(i == 4);
}
fn print() void {
switch (builtin.os.tag) {
.linux => {
asm volatile ("syscall"
:
: [number] "{rax}" (1),
[arg1] "{rdi}" (1),
[arg2] "{rsi}" (@ptrToInt("hello\n")),
[arg3] "{rdx}" (6),
: "rcx", "r11", "memory"
);
},
.macos => {
_ = write(1, @ptrToInt("hello\n"), 6);
},
else => unreachable,
}
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//
// hello
// hello
// hello
// hello
//