Skip to content

Commit e363805

Browse files
committed
better error messages in WPT report (in line with what main branch is doing)
1 parent d688d88 commit e363805

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

src/browser/dom/node.zig

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,17 @@ test "Browser.DOM.node" {
411411
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
412412
defer runner.deinit();
413413

414-
try runner.exec(
415-
\\ function trimAndReplace(str) {
416-
\\ str = str.replace(/(\r\n|\n|\r)/gm,'');
417-
\\ str = str.replace(/\s+/g, ' ');
418-
\\ str = str.trim();
419-
\\ return str;
420-
\\ }
421-
);
414+
{
415+
var err_out: ?[]const u8 = null;
416+
try runner.exec(
417+
\\ function trimAndReplace(str) {
418+
\\ str = str.replace(/(\r\n|\n|\r)/gm,'');
419+
\\ str = str.replace(/\s+/g, ' ');
420+
\\ str = str.trim();
421+
\\ return str;
422+
\\ }
423+
, &err_out);
424+
}
422425

423426
try runner.testCases(&.{
424427
.{ "document.body.compareDocumentPosition(document.firstChild); ", "10" },

src/testing.zig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,17 +468,18 @@ pub const JsRunner = struct {
468468
}
469469
}
470470

471-
pub fn exec(self: *JsRunner, src: []const u8) !void {
472-
_ = try self.eval(src);
471+
pub fn exec(self: *JsRunner, src: []const u8, err_msg: *?[]const u8) !void {
472+
_ = try self.eval(src, err_msg);
473473
}
474474

475-
pub fn eval(self: *JsRunner, src: []const u8) !Env.Value {
475+
pub fn eval(self: *JsRunner, src: []const u8, err_msg: *?[]const u8) !Env.Value {
476476
var try_catch: Env.TryCatch = undefined;
477477
try_catch.init(self.executor);
478478
defer try_catch.deinit();
479479

480480
return self.executor.exec(src, null) catch |err| {
481481
if (try try_catch.err(self.arena)) |msg| {
482+
err_msg.* = msg;
482483
std.debug.print("Error runnign script: {s}\n", .{msg});
483484
}
484485
return err;

src/wpt/run.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const polyfill = @import("../browser/polyfill/polyfill.zig");
3030
// runWPT parses the given HTML file, starts a js env and run the first script
3131
// tags containing javascript sources.
3232
// It loads first the js libs files.
33-
pub fn run(arena: Allocator, comptime dir: []const u8, f: []const u8, loader: *FileLoader, msg_out: *?[]const u8) ![]const u8 {
33+
pub fn run(arena: Allocator, comptime dir: []const u8, f: []const u8, loader: *FileLoader, err_msg: *?[]const u8) ![]const u8 {
3434
// document
3535
const html = blk: {
3636
const file = try std.fs.cwd().openFile(f, .{});
@@ -48,7 +48,7 @@ pub fn run(arena: Allocator, comptime dir: []const u8, f: []const u8, loader: *F
4848

4949
// display console logs
5050
defer {
51-
const res = runner.eval("console.join('\\n');") catch unreachable;
51+
const res = runner.eval("console.join('\\n');", err_msg) catch unreachable;
5252
const log = res.toString(arena) catch unreachable;
5353
if (log.len > 0) {
5454
std.debug.print("-- CONSOLE LOG\n{s}\n--\n", .{log});
@@ -63,7 +63,7 @@ pub fn run(arena: Allocator, comptime dir: []const u8, f: []const u8, loader: *F
6363
\\ console.debug = function () {
6464
\\ console.push("debug", ...arguments);
6565
\\ };
66-
);
66+
, err_msg);
6767

6868
// loop over the scripts.
6969
const doc = parser.documentHTMLToDocument(runner.state.document.?);
@@ -79,12 +79,12 @@ pub fn run(arena: Allocator, comptime dir: []const u8, f: []const u8, loader: *F
7979
// no need to free path, thanks to the arena.
8080
path = try fspath.join(arena, &.{ "/", dirname, path });
8181
}
82-
try runner.exec(try loader.get(path));
82+
try runner.exec(try loader.get(path), err_msg);
8383
}
8484

8585
// If the script as a source text, execute it.
8686
const src = try parser.nodeTextContent(s) orelse continue;
87-
try runner.exec(src);
87+
try runner.exec(src, err_msg);
8888
}
8989

9090
// Mark tests as ready to run.
@@ -104,17 +104,17 @@ pub fn run(arena: Allocator, comptime dir: []const u8, f: []const u8, loader: *F
104104
defer try_catch.deinit();
105105
runner.loop.run() catch |err| {
106106
if (try try_catch.err(arena)) |msg| {
107-
msg_out.* = msg;
107+
err_msg.* = msg;
108108
}
109109
return err;
110110
};
111111
}
112112

113113
// Check the final test status.
114-
try runner.exec("report.status;");
114+
try runner.exec("report.status;", err_msg);
115115

116116
// return the detailed result.
117-
const res = try runner.eval("report.log");
117+
const res = try runner.eval("report.log", err_msg);
118118
return res.toString(arena);
119119
}
120120

0 commit comments

Comments
 (0)