Don't [try] to run non-tests

Currently, we treat every .html file in tests/wpt as-if it's a test. That
isn't always the case. wpt has a manifest tool to generate a manifest (in
JSON) of the tests, we should probably use that (but it's quite large).

This PR filters out two groups. First, everything in resources/ appears to
be things to _run_ the tests, not actual tests.

Second, any file without a "testharness.js" doesn't appear to be a test
either. Note that WPT's own manifest generator looks at this:
43a0615361/tools/manifest/sourcefile.py (L676)
(which is used later in the file to determine the type of file).
This commit is contained in:
Karl Seguin
2025-04-22 21:05:12 +08:00
parent f3d8ec040c
commit 8aa3608a3c
2 changed files with 19 additions and 3 deletions

View File

@@ -148,6 +148,10 @@ pub fn main() !void {
}
failures += 1;
continue;
} orelse {
// This test should _not_ have been run.
run -= 1;
continue;
};
const suite = try Suite.init(alloc, tc, true, res);

View File

@@ -30,7 +30,7 @@ const polyfill = @import("../browser/polyfill/polyfill.zig");
// runWPT parses the given HTML file, starts a js env and run the first script
// tags containing javascript sources.
// It loads first the js libs files.
pub fn run(arena: Allocator, comptime dir: []const u8, f: []const u8, loader: *FileLoader, err_msg: *?[]const u8) ![]const u8 {
pub fn run(arena: Allocator, comptime dir: []const u8, f: []const u8, loader: *FileLoader, err_msg: *?[]const u8) !?[]const u8 {
// document
const html = blk: {
const file = try std.fs.cwd().openFile(f, .{});
@@ -38,6 +38,12 @@ pub fn run(arena: Allocator, comptime dir: []const u8, f: []const u8, loader: *F
break :blk try file.readToEndAlloc(arena, 128 * 1024);
};
if (std.mem.indexOf(u8, html, "testharness.js") == null) {
// This isn't a test. A lot of files are helpers/content for tests to
// make use of.
return null;
}
const dirname = fspath.dirname(f[dir.len..]) orelse unreachable;
var runner = try @import("../testing.zig").jsRunner(arena, .{
@@ -115,11 +121,11 @@ pub fn run(arena: Allocator, comptime dir: []const u8, f: []const u8, loader: *F
// return the detailed result.
const res = try runner.eval("report.log", "report", err_msg);
return res.toString(arena);
return try res.toString(arena);
}
// browse the path to find the tests list.
pub fn find(allocator: std.mem.Allocator, comptime path: []const u8, list: *std.ArrayList([]const u8)) !void {
pub fn find(allocator: Allocator, comptime path: []const u8, list: *std.ArrayList([]const u8)) !void {
var dir = try std.fs.cwd().openDir(path, .{ .iterate = true, .no_follow = true });
defer dir.close();
@@ -130,6 +136,12 @@ pub fn find(allocator: std.mem.Allocator, comptime path: []const u8, list: *std.
if (entry.kind != .file) {
continue;
}
if (std.mem.startsWith(u8, entry.path, "resources/")) {
// resources for running the tests themselves, not actual tests
continue;
}
if (!std.mem.endsWith(u8, entry.basename, ".html") and !std.mem.endsWith(u8, entry.basename, ".htm")) {
continue;
}