1const builtin = @import("builtin");
2const std = @import("std");
3const c = std.c;
4
5test {
6 _ = @import("c/inttypes.zig");
7 _ = @import("c/math.zig");
8 _ = @import("c/pthread.zig");
9 _ = @import("c/search.zig");
10 _ = @import("c/stdlib.zig");
11 _ = @import("c/string.zig");
12 _ = @import("c/strings.zig");
13 _ = @import("c/unistd.zig");
14 _ = @import("c/wchar.zig");
15}
16
17pub fn expectErrno(expected_errno: c.E) !void {
18 try std.testing.expectEqual(expected_errno, @as(c.E, @fromBackingInt(@intCast(c._errno().*))));
19 c._errno().* = @backingInt(c.E.SUCCESS);
20}
21
22pub fn expectErrnoAny(expected_errnos: []const c.E) !void {
23 const errno = c._errno().*;
24 for (expected_errnos) |expected_errno| {
25 if (errno == @backingInt(expected_errno)) break;
26 } else {
27 var buffer: [64]u8 = undefined;
28 const stderr = std.debug.lockStderr(&buffer);
29 defer std.debug.unlockStderr();
30 try stderr.file_writer.interface.print("expected one of {t}", .{expected_errnos[0]});
31 for (expected_errnos[1..]) |expected_errno| {
32 try stderr.file_writer.interface.print(", {t}", .{expected_errno});
33 }
34 try stderr.file_writer.interface.print(", found {t}\n", .{@as(c.E, @fromBackingInt(@intCast(errno)))});
35 return error.TestExpectedEqual;
36 }
37 c._errno().* = @backingInt(c.E.SUCCESS);
38}