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 @@...@@ -1,15 +1,11 @@
1const c = @cImport({1extern fn printf(format: [*:0]const u8, ...) c_int;
2 // See https://github.com/ziglang/zig/issues/5152extern fn strlen(str: [*:0]const u8) usize;
3 @cDefine("_NO_CRT_STDIO_INLINE", "1");
4 @cInclude("stdio.h");
5 @cInclude("string.h");
6});
73
8const msg = "Hello, world!\n";4const msg = "Hello, world!\n";
95
10pub export fn main(argc: c_int, argv: **u8) c_int {6pub export fn main(argc: c_int, argv: **u8) c_int {
11 _ = argv;7 _ = argv;
12 _ = argc;8 _ = 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;
14 return 0;10 return 0;
15}11}
test/standalone/static_c_lib/foo.zig+5-3
...@@ -1,12 +1,14 @@...@@ -1,12 +1,14 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expect = std.testing.expect;
3const c = @cImport(@cInclude("foo.h"));3
4extern fn add(a: u32, b: u32) u32;
5extern var foo: u32;
46
5test "C add" {7test "C add" {
6 const result = c.add(1, 2);8 const result = add(1, 2);
7 try expect(result == 3);9 try expect(result == 3);
8}10}
911
10test "C extern variable" {12test "C extern variable" {
11 try expect(c.foo == 12345);13 try expect(foo == 12345);
12}14}