mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
test: remove unnecessary @cImport usage in some standalone tests
This commit is contained in:
parent
abd73083e4
commit
4e9b8aec2c
@ -1,15 +1,11 @@
|
||||
const c = @cImport({
|
||||
// See https://github.com/ziglang/zig/issues/515
|
||||
@cDefine("_NO_CRT_STDIO_INLINE", "1");
|
||||
@cInclude("stdio.h");
|
||||
@cInclude("string.h");
|
||||
});
|
||||
extern fn printf(format: [*:0]const u8, ...) c_int;
|
||||
extern fn strlen(str: [*:0]const u8) usize;
|
||||
|
||||
const msg = "Hello, world!\n";
|
||||
|
||||
pub export fn main(argc: c_int, argv: **u8) c_int {
|
||||
_ = argv;
|
||||
_ = argc;
|
||||
if (c.printf(msg) != @as(c_int, @intCast(c.strlen(msg)))) return -1;
|
||||
if (printf(msg) != @as(c_int, @intCast(strlen(msg)))) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const c = @cImport(@cInclude("foo.h"));
|
||||
|
||||
extern fn add(a: u32, b: u32) u32;
|
||||
extern var foo: u32;
|
||||
|
||||
test "C add" {
|
||||
const result = c.add(1, 2);
|
||||
const result = add(1, 2);
|
||||
try expect(result == 3);
|
||||
}
|
||||
|
||||
test "C extern variable" {
|
||||
try expect(c.foo == 12345);
|
||||
try expect(foo == 12345);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user