updating to Zig 0.16
Some checks failed
Build / build (push) Failing after 32s
Test / build (push) Successful in 7m50s

This commit is contained in:
2026-04-16 01:50:42 +02:00
parent 9f586ae9c0
commit 4bd688cf07
9 changed files with 330 additions and 378 deletions

View File

@@ -101,7 +101,7 @@ test "Bitwise vectors" {
inline for (types) |T| {
const op1: case.Vec(L, T) = .{ .val = case.random(@Vector(L, T)) };
var op2: case.Vec(L, T) = .{ .val = case.random(@Vector(L, T)) };
for (0..L) |i| op2.val[i] = @mod(op2.val[i], @bitSizeOf(T));
inline for (0..L) |i| op2.val[i] = @mod(op2.val[i], @bitSizeOf(T));
const expected = switch (op.key) {
.BitwiseAnd => op1.val & op2.val,
.BitwiseOr => op1.val | op2.val,

View File

@@ -78,7 +78,7 @@ pub const case = struct {
}
pub fn random(comptime T: type) T {
var prng: std.Random.DefaultPrng = .init(@intCast(std.time.microTimestamp()));
var prng: std.Random.DefaultPrng = .init(@intCast(std.Io.Timestamp.now(std.testing.io, .real).toMicroseconds()));
const rand = prng.random();
return switch (@typeInfo(T)) {
@@ -86,7 +86,7 @@ pub const case = struct {
.float => rand.float(T),
.vector => |v| blk: {
var vec: @Vector(v.len, v.child) = undefined;
for (0..v.len) |i| {
inline for (0..v.len) |i| {
vec[i] = random(v.child);
}
break :blk vec;

View File

@@ -16,11 +16,8 @@ pub fn main() !void {
const allocator = fba.allocator();
const env = Env.init(allocator);
defer env.deinit(allocator);
var slowest = SlowTracker.init(allocator, 5);
defer slowest.deinit();
defer slowest.deinit(allocator);
var pass: usize = 0;
var fail: usize = 0;
@@ -46,13 +43,6 @@ pub fn main() !void {
var status = Status.pass;
slowest.startTiming();
const is_unnamed_test = isUnnamed(t);
if (env.filter) |f| {
if (!is_unnamed_test and std.mem.indexOf(u8, t.name, f) == null) {
continue;
}
}
const friendly_name = blk: {
const name = t.name;
var it = std.mem.splitScalar(u8, name, '.');
@@ -70,7 +60,7 @@ pub fn main() !void {
const result = t.func();
current_test = null;
const ns_taken = slowest.endTiming(friendly_name);
const ns_taken = slowest.endTiming(allocator, friendly_name);
if (std.testing.allocator_instance.deinit() == .leak) {
leak += 1;
@@ -89,20 +79,13 @@ pub fn main() !void {
fail += 1;
Printer.status(.fail, "\n{s}\n\"{s}\" - {s}\n{s}\n", .{ BORDER, friendly_name, @errorName(err), BORDER });
if (@errorReturnTrace()) |trace| {
std.debug.dumpStackTrace(trace.*);
}
if (env.fail_first) {
break;
std.debug.dumpErrorReturnTrace(trace);
}
},
}
if (env.verbose) {
const ms = @as(f64, @floatFromInt(ns_taken)) / 1_000_000.0;
Printer.status(status, "\x1b[35m[{d: >10.2} ms]\x1b[0m {s: <30}", .{ ms, friendly_name });
} else {
Printer.status(status, ".", .{});
}
const ms = @as(f64, @floatFromInt(ns_taken)) / 1_000_000.0;
Printer.status(status, "\x1b[35m[{d: >10.2} ms]\x1b[0m {s: <30}", .{ ms, friendly_name });
}
for (builtin.test_functions) |t| {
@@ -126,7 +109,7 @@ pub fn main() !void {
Printer.fmt("\n", .{});
try slowest.display();
Printer.fmt("\n", .{});
std.posix.exit(if (fail == 0) 0 else 1);
std.process.exit(if (fail == 0) 0 else 1);
}
const Printer = struct {
@@ -155,42 +138,41 @@ const SlowTracker = struct {
const SlowestQueue = std.PriorityDequeue(TestInfo, void, compareTiming);
max: usize,
slowest: SlowestQueue,
timer: std.time.Timer,
timer: std.Io.Timestamp,
fn init(allocator: Allocator, count: u32) SlowTracker {
const timer = std.time.Timer.start() catch @panic("failed to start timer");
var slowest = SlowestQueue.init(allocator, {});
slowest.ensureTotalCapacity(count) catch @panic("OOM");
var slowest = SlowestQueue.empty;
slowest.ensureTotalCapacity(allocator, count) catch @panic("OOM");
return .{
.max = count,
.timer = timer,
.timer = std.Io.Timestamp.now(std.testing.io, .real),
.slowest = slowest,
};
}
const TestInfo = struct {
ns: u64,
ns: i96,
name: []const u8,
};
fn deinit(self: SlowTracker) void {
self.slowest.deinit();
fn deinit(self: *SlowTracker, allocator: std.mem.Allocator) void {
self.slowest.deinit(allocator);
}
fn startTiming(self: *SlowTracker) void {
self.timer.reset();
self.timer = std.Io.Timestamp.now(std.testing.io, .real);
}
fn endTiming(self: *SlowTracker, test_name: []const u8) u64 {
var timer = self.timer;
const ns = timer.lap();
fn endTiming(self: *SlowTracker, allocator: std.mem.Allocator, test_name: []const u8) i96 {
const duration = self.timer.untilNow(std.testing.io, .real);
const ns = duration.toNanoseconds();
var slowest = &self.slowest;
if (slowest.count() < self.max) {
// Capacity is fixed to the # of slow tests we want to track
// If we've tracked fewer tests than this capacity, than always add
slowest.add(TestInfo{ .ns = ns, .name = test_name }) catch @panic("failed to track test timing");
slowest.push(allocator, TestInfo{ .ns = ns, .name = test_name }) catch @panic("failed to track test timing");
return ns;
}
@@ -205,8 +187,8 @@ const SlowTracker = struct {
}
// the previous fastest of our slow tests, has been pushed off.
_ = slowest.removeMin();
slowest.add(TestInfo{ .ns = ns, .name = test_name }) catch @panic("failed to track test timing");
_ = slowest.popMin();
slowest.push(allocator, TestInfo{ .ns = ns, .name = test_name }) catch @panic("failed to track test timing");
return ns;
}
@@ -214,7 +196,7 @@ const SlowTracker = struct {
var slowest = self.slowest;
const count = slowest.count();
Printer.fmt("Slowest {d} test{s}: \n", .{ count, if (count != 1) "s" else "" });
while (slowest.removeMinOrNull()) |info| {
while (slowest.popMin()) |info| {
const ms = @as(f64, @floatFromInt(info.ns)) / 1_000_000.0;
Printer.fmt(" {d:.2}ms\t{s}\n", .{ ms, info.name });
}
@@ -226,43 +208,6 @@ const SlowTracker = struct {
}
};
const Env = struct {
verbose: bool,
fail_first: bool,
filter: ?[]const u8,
fn init(allocator: Allocator) Env {
return .{
.verbose = readEnvBool(allocator, "TEST_VERBOSE", true),
.fail_first = readEnvBool(allocator, "TEST_FAIL_FIRST", false),
.filter = readEnv(allocator, "TEST_FILTER"),
};
}
fn deinit(self: Env, allocator: Allocator) void {
if (self.filter) |f| {
allocator.free(f);
}
}
fn readEnv(allocator: Allocator, key: []const u8) ?[]const u8 {
const v = std.process.getEnvVarOwned(allocator, key) catch |err| {
if (err == error.EnvironmentVariableNotFound) {
return null;
}
std.log.warn("failed to get env var {s} due to err {}", .{ key, err });
return null;
};
return v;
}
fn readEnvBool(allocator: Allocator, key: []const u8, deflt: bool) bool {
const value = readEnv(allocator, key) orelse return deflt;
defer allocator.free(value);
return std.ascii.eqlIgnoreCase(value, "true");
}
};
pub const panic = std.debug.FullPanic(struct {
pub fn panicFn(msg: []const u8, first_trace_addr: ?usize) noreturn {
if (current_test) |ct| {