2
2
// const tests = b.addTest(.{
3
3
// .target = target,
4
4
// .optimize = optimize,
5
- // .test_runner = "test_runner.zig", // add this line
5
+ // .test_runner = .{ .path = b.path( "test_runner.zig"), .mode = .simple } , // add this line
6
6
// .root_source_file = b.path("src/main.zig"),
7
7
// });
8
8
@@ -33,14 +33,11 @@ pub fn main() !void {
33
33
var skip : usize = 0 ;
34
34
var leak : usize = 0 ;
35
35
36
- try std .posix .getrandom (std .mem .asBytes (& std .testing .random_seed ));
37
-
38
36
const printer = Printer .init ();
39
37
printer .fmt ("\r \x1b [0K" , .{}); // beginning of line and clear to end of line
40
38
41
39
for (builtin .test_functions ) | t | {
42
40
if (isSetup (t )) {
43
- current_test = friendlyName (t .name );
44
41
t .func () catch | err | {
45
42
printer .status (.fail , "\n setup \" {s}\" failed: {}\n " , .{ t .name , err });
46
43
return err ;
@@ -63,16 +60,23 @@ pub fn main() !void {
63
60
}
64
61
}
65
62
66
- const friendly_name = friendlyName (t .name );
63
+ const friendly_name = blk : {
64
+ const name = t .name ;
65
+ var it = std .mem .splitScalar (u8 , name , '.' );
66
+ while (it .next ()) | value | {
67
+ if (std .mem .eql (u8 , value , "test" )) {
68
+ const rest = it .rest ();
69
+ break :blk if (rest .len > 0 ) rest else name ;
70
+ }
71
+ }
72
+ break :blk name ;
73
+ };
74
+
67
75
current_test = friendly_name ;
68
76
std .testing .allocator_instance = .{};
69
77
const result = t .func ();
70
78
current_test = null ;
71
79
72
- if (is_unnamed_test ) {
73
- continue ;
74
- }
75
-
76
80
const ns_taken = slowest .endTiming (friendly_name );
77
81
78
82
if (std .testing .allocator_instance .deinit () == .leak ) {
@@ -110,7 +114,6 @@ pub fn main() !void {
110
114
111
115
for (builtin .test_functions ) | t | {
112
116
if (isTeardown (t )) {
113
- current_test = friendlyName (t .name );
114
117
t .func () catch | err | {
115
118
printer .status (.fail , "\n teardown \" {s}\" failed: {}\n " , .{ t .name , err });
116
119
return err ;
@@ -133,17 +136,6 @@ pub fn main() !void {
133
136
std .posix .exit (if (fail == 0 ) 0 else 1 );
134
137
}
135
138
136
- fn friendlyName (name : []const u8 ) []const u8 {
137
- var it = std .mem .splitScalar (u8 , name , '.' );
138
- while (it .next ()) | value | {
139
- if (std .mem .eql (u8 , value , "test" )) {
140
- const rest = it .rest ();
141
- return if (rest .len > 0 ) rest else name ;
142
- }
143
- }
144
- return name ;
145
- }
146
-
147
139
const Printer = struct {
148
140
out : std.fs.File.Writer ,
149
141
@@ -290,12 +282,14 @@ const Env = struct {
290
282
}
291
283
};
292
284
293
- pub fn panic (msg : []const u8 , error_return_trace : ? * std.builtin.StackTrace , ret_addr : ? usize ) noreturn {
294
- if (current_test ) | ct | {
295
- std .debug .print ("\x1b [31m{s}\n panic running \" {s}\" \n {s}\x1b [0m\n " , .{ BORDER , ct , BORDER });
285
+ pub const panic = std .debug .FullPanic (struct {
286
+ pub fn panicFn (msg : []const u8 , first_trace_addr : ? usize ) noreturn {
287
+ if (current_test ) | ct | {
288
+ std .debug .print ("\x1b [31m{s}\n panic running \" {s}\" \n {s}\x1b [0m\n " , .{ BORDER , ct , BORDER });
289
+ }
290
+ std .debug .defaultPanic (msg , first_trace_addr );
296
291
}
297
- std .debug .defaultPanic (msg , error_return_trace , ret_addr );
298
- }
292
+ }.panicFn );
299
293
300
294
fn isUnnamed (t : std.builtin.TestFn ) bool {
301
295
const marker = ".test_" ;
0 commit comments