mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
Build: fail tests that log errors, like zig test
does
This commit is contained in:
parent
4403008cab
commit
750998eef6
@ -45,10 +45,11 @@ pub const TestResults = struct {
|
||||
fail_count: u32 = 0,
|
||||
skip_count: u32 = 0,
|
||||
leak_count: u32 = 0,
|
||||
log_err_count: u32 = 0,
|
||||
test_count: u32 = 0,
|
||||
|
||||
pub fn isSuccess(tr: TestResults) bool {
|
||||
return tr.fail_count == 0 and tr.leak_count == 0;
|
||||
return tr.fail_count == 0 and tr.leak_count == 0 and tr.log_err_count == 0;
|
||||
}
|
||||
|
||||
pub fn passCount(tr: TestResults) u32 {
|
||||
|
@ -1048,6 +1048,7 @@ fn evalZigTest(
|
||||
var skip_count: u32 = 0;
|
||||
var leak_count: u32 = 0;
|
||||
var test_count: u32 = 0;
|
||||
var log_err_count: u32 = 0;
|
||||
|
||||
var metadata: ?TestMetadata = null;
|
||||
|
||||
@ -1112,14 +1113,22 @@ fn evalZigTest(
|
||||
|
||||
const TrHdr = std.zig.Server.Message.TestResults;
|
||||
const tr_hdr = @as(*align(1) const TrHdr, @ptrCast(body));
|
||||
fail_count += @intFromBool(tr_hdr.flags.fail);
|
||||
skip_count += @intFromBool(tr_hdr.flags.skip);
|
||||
leak_count += @intFromBool(tr_hdr.flags.leak);
|
||||
fail_count +|= @intFromBool(tr_hdr.flags.fail);
|
||||
skip_count +|= @intFromBool(tr_hdr.flags.skip);
|
||||
leak_count +|= @intFromBool(tr_hdr.flags.leak);
|
||||
log_err_count +|= tr_hdr.flags.log_err_count;
|
||||
|
||||
if (tr_hdr.flags.fail or tr_hdr.flags.leak) {
|
||||
if (tr_hdr.flags.fail or tr_hdr.flags.leak or tr_hdr.flags.log_err_count > 0) {
|
||||
const name = std.mem.sliceTo(md.string_bytes[md.names[tr_hdr.index]..], 0);
|
||||
const msg = std.mem.trim(u8, stderr.readableSlice(0), "\n");
|
||||
const label = if (tr_hdr.flags.fail) "failed" else "leaked";
|
||||
const label = if (tr_hdr.flags.fail)
|
||||
"failed"
|
||||
else if (tr_hdr.flags.leak)
|
||||
"leaked"
|
||||
else if (tr_hdr.flags.log_err_count > 0)
|
||||
"logged errors"
|
||||
else
|
||||
unreachable;
|
||||
if (msg.len > 0) {
|
||||
try self.step.addError("'{s}' {s}: {s}", .{ name, label, msg });
|
||||
} else {
|
||||
@ -1153,6 +1162,7 @@ fn evalZigTest(
|
||||
.fail_count = fail_count,
|
||||
.skip_count = skip_count,
|
||||
.leak_count = leak_count,
|
||||
.log_err_count = log_err_count,
|
||||
},
|
||||
.test_metadata = metadata,
|
||||
};
|
||||
|
@ -53,12 +53,11 @@ pub const Message = struct {
|
||||
index: u32,
|
||||
flags: Flags,
|
||||
|
||||
pub const Flags = packed struct(u8) {
|
||||
pub const Flags = packed struct(u32) {
|
||||
fail: bool,
|
||||
skip: bool,
|
||||
leak: bool,
|
||||
|
||||
reserved: u5 = 0,
|
||||
log_err_count: u29 = 0,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -90,6 +90,7 @@ fn mainServer() !void {
|
||||
|
||||
.run_test => {
|
||||
std.testing.allocator_instance = .{};
|
||||
log_err_count = 0;
|
||||
const index = try server.receiveBody_u32();
|
||||
const test_fn = builtin.test_functions[index];
|
||||
if (test_fn.async_frame_size != null)
|
||||
@ -113,6 +114,10 @@ fn mainServer() !void {
|
||||
.fail = fail,
|
||||
.skip = skip,
|
||||
.leak = leak,
|
||||
.log_err_count = std.math.lossyCast(std.meta.FieldType(
|
||||
std.zig.Server.Message.TestResults.Flags,
|
||||
.log_err_count,
|
||||
), log_err_count),
|
||||
},
|
||||
});
|
||||
},
|
||||
@ -218,7 +223,7 @@ pub fn log(
|
||||
args: anytype,
|
||||
) void {
|
||||
if (@intFromEnum(message_level) <= @intFromEnum(std.log.Level.err)) {
|
||||
log_err_count += 1;
|
||||
log_err_count +|= 1;
|
||||
}
|
||||
if (@intFromEnum(message_level) <= @intFromEnum(std.testing.log_level)) {
|
||||
std.debug.print(
|
||||
|
Loading…
Reference in New Issue
Block a user