Merge pull request #135 from lightpanda-io/wpt-imp

wpt: better summary output
This commit is contained in:
Pierre Tachoire
2023-12-15 12:07:07 +01:00
committed by GitHub
3 changed files with 43 additions and 37 deletions

View File

@@ -249,17 +249,15 @@ fn runSafe(
const alloc = arena.allocator();
const Result = enum {
pass,
fail,
success,
crash,
};
var argv = try std.ArrayList([]const u8).initCapacity(alloc, 3);
defer argv.deinit();
argv.appendAssumeCapacity(execname);
if (out == .json) {
argv.appendAssumeCapacity("--json");
}
// always require json output to count test cases results
argv.appendAssumeCapacity("--json");
var output = std.ArrayList(Test).init(alloc);
@@ -268,43 +266,47 @@ fn runSafe(
continue;
}
// append the test case to argv and pop it before next loop.
argv.appendAssumeCapacity(tc);
defer _ = argv.pop();
// TODO use std.ChildProcess.run after next zig upgrade.
var child = std.ChildProcess.init(argv.items, alloc);
child.stdin_behavior = .Ignore;
child.stdout_behavior = .Pipe;
child.stderr_behavior = .Pipe;
const run = try std.ChildProcess.run(.{
.allocator = alloc,
.argv = argv.items,
.max_output_bytes = 1024 * 1024,
});
var stdout = std.ArrayList(u8).init(alloc);
var stderr = std.ArrayList(u8).init(alloc);
const result: Result = switch (run.term) {
.Exited => .success,
else => .crash,
};
try child.spawn();
try child.collectOutput(&stdout, &stderr, 1024 * 1024);
const term = try child.wait();
var result: Result = undefined;
switch (term) {
.Exited => |v| {
if (v == 0) {
result = .pass;
} else {
result = .fail;
}
},
.Signal => result = .crash,
.Stopped => result = .crash,
.Unknown => result = .crash,
// read the JSON result from stdout
var tests: []Test = undefined;
if (result != .crash) {
const parsed = try std.json.parseFromSlice([]Test, alloc, run.stdout, .{});
tests = parsed.value;
}
if (out == .summary) {
switch (result) {
.pass => std.debug.print("Pass", .{}),
.fail => std.debug.print("Fail", .{}),
.crash => std.debug.print("Crash", .{}),
defer std.debug.print("\t{s}\n", .{tc});
if (result == .crash) {
std.debug.print("Crash\t", .{});
continue;
}
std.debug.print("\t{s}\n", .{tc});
// count results
var pass: u32 = 0;
var all: u32 = 0;
for (tests) |ttc| {
for (ttc.cases) |c| {
all += 1;
if (c.pass) pass += 1;
}
}
const status = if (pass == all) "Pass" else "Fail";
std.debug.print("{s} {d}/{d}", .{ status, pass, all });
continue;
}
@@ -313,7 +315,7 @@ fn runSafe(
var cases = [_]Case{.{
.pass = false,
.name = "crash",
.message = stderr.items,
.message = run.stderr,
}};
try output.append(Test{
.pass = false,
@@ -324,12 +326,11 @@ fn runSafe(
continue;
}
const jp = try std.json.parseFromSlice([]Test, alloc, stdout.items, .{});
try output.appendSlice(jp.value);
try output.appendSlice(tests);
continue;
}
std.debug.print("{s}\n", .{stderr.items});
std.debug.print("{s}\n", .{run.stderr});
}
if (out == .json) {

View File

@@ -0,0 +1,5 @@
var creators = {
"element": "createElement",
"text": "createTextNode",
"comment": "createComment"
};