mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-10-28 10:45:48 +08:00
Converts usages of `@intFromEnum` and `@enumFromInt` to instead use the new `@backingInt` and `@fromBackingInt` builtins.
39 lines
1.3 KiB
Zig
39 lines
1.3 KiB
Zig
const builtin = @import("builtin");
|
|
const std = @import("std");
|
|
const c = std.c;
|
|
|
|
test {
|
|
_ = @import("c/inttypes.zig");
|
|
_ = @import("c/math.zig");
|
|
_ = @import("c/pthread.zig");
|
|
_ = @import("c/search.zig");
|
|
_ = @import("c/stdlib.zig");
|
|
_ = @import("c/string.zig");
|
|
_ = @import("c/strings.zig");
|
|
_ = @import("c/unistd.zig");
|
|
_ = @import("c/wchar.zig");
|
|
}
|
|
|
|
pub fn expectErrno(expected_errno: c.E) !void {
|
|
try std.testing.expectEqual(expected_errno, @as(c.E, @fromBackingInt(@intCast(c._errno().*))));
|
|
c._errno().* = @backingInt(c.E.SUCCESS);
|
|
}
|
|
|
|
pub fn expectErrnoAny(expected_errnos: []const c.E) !void {
|
|
const errno = c._errno().*;
|
|
for (expected_errnos) |expected_errno| {
|
|
if (errno == @backingInt(expected_errno)) break;
|
|
} else {
|
|
var buffer: [64]u8 = undefined;
|
|
const stderr = std.debug.lockStderr(&buffer);
|
|
defer std.debug.unlockStderr();
|
|
try stderr.file_writer.interface.print("expected one of {t}", .{expected_errnos[0]});
|
|
for (expected_errnos[1..]) |expected_errno| {
|
|
try stderr.file_writer.interface.print(", {t}", .{expected_errno});
|
|
}
|
|
try stderr.file_writer.interface.print(", found {t}\n", .{@as(c.E, @fromBackingInt(@intCast(errno)))});
|
|
return error.TestExpectedEqual;
|
|
}
|
|
c._errno().* = @backingInt(c.E.SUCCESS);
|
|
}
|