wpt: extract filter on its own func

This commit is contained in:
Pierre Tachoire
2023-11-30 15:41:43 +01:00
parent 8b8d7b3617
commit 07270fbb19

View File

@@ -91,6 +91,10 @@ pub fn main() !void {
if (safe) { if (safe) {
for (list.items) |tc| { for (list.items) |tc| {
if (!shouldRun(filter.items, tc)) {
continue;
}
// TODO use std.ChildProcess.run after next zig upgrade. // TODO use std.ChildProcess.run after next zig upgrade.
var child = std.ChildProcess.init(&.{ execname, tc }, alloc); var child = std.ChildProcess.init(&.{ execname, tc }, alloc);
child.stdin_behavior = .Ignore; child.stdin_behavior = .Ignore;
@@ -138,7 +142,7 @@ pub fn main() !void {
continue; continue;
} }
// std.debug.print("{s}\n", .{stderr.items}); std.debug.print("{s}\n", .{stderr.items});
} }
return; return;
@@ -163,21 +167,8 @@ pub fn main() !void {
var run: usize = 0; var run: usize = 0;
var failures: usize = 0; var failures: usize = 0;
for (list.items) |tc| { for (list.items) |tc| {
if (filter.items.len > 0) { if (!shouldRun(filter.items, tc)) {
var match = false; continue;
for (filter.items) |f| {
if (std.mem.startsWith(u8, tc, f)) {
match = true;
break;
}
if (std.mem.endsWith(u8, tc, f)) {
match = true;
break;
}
}
if (!match) {
continue;
}
} }
run += 1; run += 1;
@@ -279,3 +270,19 @@ pub fn main() !void {
std.os.exit(1); std.os.exit(1);
} }
} }
fn shouldRun(filter: [][]const u8, tc: []const u8) bool {
if (filter.len == 0) {
return true;
}
for (filter) |f| {
if (std.mem.startsWith(u8, tc, f)) {
return true;
}
if (std.mem.endsWith(u8, tc, f)) {
return true;
}
}
return false;
}