authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-09-17 11:11:49+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-09-18 12:42:24+02:00
log4e9b8aec2cbaa9fba7b64b03e90d0426b09e1003
tree6ca0fcf042f8b164d95b358ebaada7360f77ad51
parentabd73083e423fa1422aa64575e357b85c17a5101
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

test: remove unnecessary @cImport usage in some standalone tests


2 files changed, 8 insertions(+), 10 deletions(-)

test/standalone/simple/hello_world/hello_libc.zig+3-7
......@@ -1,15 +1,11 @@
1const c = @cImport({
2 // See https://github.com/ziglang/zig/issues/515
3 @cDefine("_NO_CRT_STDIO_INLINE", "1");
4 @cInclude("stdio.h");
5 @cInclude("string.h");
6});
1extern fn printf(format: [*:0]const u8, ...) c_int;
2extern fn strlen(str: [*:0]const u8) usize;
73
84const msg = "Hello, world!\n";
95
106pub export fn main(argc: c_int, argv: **u8) c_int {
117 _ = argv;
128 _ = argc;
13 if (c.printf(msg) != @as(c_int, @intCast(c.strlen(msg)))) return -1;
9 if (printf(msg) != @as(c_int, @intCast(strlen(msg)))) return -1;
1410 return 0;
1511}
test/standalone/static_c_lib/foo.zig+5-3
......@@ -1,12 +1,14 @@
11const std = @import("std");
22const expect = std.testing.expect;
3const c = @cImport(@cInclude("foo.h"));
3
4extern fn add(a: u32, b: u32) u32;
5extern var foo: u32;
46
57test "C add" {
6 const result = c.add(1, 2);
8 const result = add(1, 2);
79 try expect(result == 3);
810}
911
1012test "C extern variable" {
11 try expect(c.foo == 12345);
13 try expect(foo == 12345);
1214}