A poolable string builder (aka string buffer) for Zig
0

Configure Feed

Select the types of activity you want to include in your feed.

accomodate zig changes introducing std.posix

Karl Seguin (Mar 23, 2024, 9:36 AM +0800) 491fa4e1 bb68f669

+18 -6
+1 -1
src/t.zig
··· 12 12 13 13 pub fn getRandom() std.rand.DefaultPrng { 14 14 var seed: u64 = undefined; 15 - std.os.getrandom(std.mem.asBytes(&seed)) catch unreachable; 15 + std.posix.getrandom(std.mem.asBytes(&seed)) catch unreachable; 16 16 return std.rand.DefaultPrng.init(seed); 17 17 }
+17 -5
test_runner.zig
··· 1 + // in your build.zig, you can specify a custom test runner: 2 + // const tests = b.addTest(.{ 3 + // .target = target, 4 + // .optimize = optimize, 5 + // .test_runner = "test_runner.zig", // add this line 6 + // .root_source_file = .{ .path = "src/main.zig" }, 7 + // }); 8 + 1 9 const std = @import("std"); 2 10 const builtin = @import("builtin"); 3 11 ··· 30 38 var status = Status.pass; 31 39 slowest.startTiming(); 32 40 33 - const is_unnamed_test = std.mem.eql(u8, "test_0", t.name); 41 + const is_unnamed_test = std.mem.endsWith(u8, t.name, ".test_0"); 34 42 if (env.filter) |f| { 35 43 if (!is_unnamed_test and std.mem.indexOf(u8, t.name, f) == null) { 36 44 continue; 37 45 } 38 46 } 39 - 40 47 41 48 const result = t.func(); 42 49 if (is_unnamed_test) { 43 50 continue; 44 51 } 45 52 46 - // strip out the test. prefix 47 - const friendly_name = t.name[5..]; 53 + const friendly_name = blk: { 54 + const name = t.name; 55 + var it = std.mem.splitScalar(u8, name, '.'); 56 + _ = it.next() orelse break :blk name; // skip module name 57 + _ = it.next() orelse break :blk name; // slip "test" 58 + break :blk it.rest(); 59 + }; 48 60 const ns_taken = slowest.endTiming(friendly_name); 49 61 50 62 if (std.testing.allocator_instance.deinit() == .leak) { ··· 92 104 printer.fmt("\n", .{}); 93 105 try slowest.display(printer); 94 106 printer.fmt("\n", .{}); 95 - std.os.exit(if (fail == 0) 0 else 1); 107 + std.posix.exit(if (fail == 0) 0 else 1); 96 108 } 97 109 98 110 const Printer = struct {