authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-19 20:59:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-19 20:59:06-07:00
loga8eac0cf0738dc086cfc7688d2395e6805257d82
treefedab8e8bb07a714fbfbc4ab4d728e3c6c4636b1
parentbfd051a53c9d1db7a7f8743cd981646a6ac37114

stage2 test harness: show source file name

Also support specifying source file name in compile error test cases. closes #8829

1 files changed, 14 insertions(+), 7 deletions(-)

src/test.zig+14-7
......@@ -28,6 +28,7 @@ test "self-hosted" {
2828
2929const ErrorMsg = union(enum) {
3030 src: struct {
31 src_path: []const u8,
3132 msg: []const u8,
3233 line: u32,
3334 column: u32,
......@@ -47,6 +48,7 @@ const ErrorMsg = union(enum) {
4748 switch (other) {
4849 .src => |src| return .{
4950 .src = .{
51 .src_path = src.src_path,
5052 .msg = src.msg,
5153 .line = @intCast(u32, src.line),
5254 .column = @intCast(u32, src.column),
......@@ -70,7 +72,8 @@ const ErrorMsg = union(enum) {
7072 ) !void {
7173 switch (self) {
7274 .src => |src| {
73 return writer.print(":{d}:{d}: {s}: {s}", .{
75 return writer.print("{s}:{d}:{d}: {s}: {s}", .{
76 src.src_path,
7477 src.line + 1,
7578 src.column + 1,
7679 @tagName(src.kind),
......@@ -188,9 +191,9 @@ pub const TestContext = struct {
188191 };
189192 continue;
190193 }
191 // example: ":1:2: error: bad thing happened"
194 // example: "file.zig:1:2: error: bad thing happened"
192195 var it = std.mem.split(err_msg_line, ":");
193 _ = it.next() orelse @panic("missing colon");
196 const src_path = it.next() orelse @panic("missing colon");
194197 const line_text = it.next() orelse @panic("missing line");
195198 const col_text = it.next() orelse @panic("missing column");
196199 const kind_text = it.next() orelse @panic("missing 'error'/'note'");
......@@ -211,6 +214,7 @@ pub const TestContext = struct {
211214
212215 array[i] = .{
213216 .src = .{
217 .src_path = src_path,
214218 .msg = msg,
215219 .line = line - 1,
216220 .column = column - 1,
......@@ -692,8 +696,8 @@ pub const TestContext = struct {
692696 for (all_errors.list) |err_msg| {
693697 switch (err_msg) {
694698 .src => |src| {
695 std.debug.print(":{d}:{d}: error: {s}\n{s}\n", .{
696 src.line + 1, src.column + 1, src.msg, hr,
699 std.debug.print("{s}:{d}:{d}: error: {s}\n{s}\n", .{
700 src.src_path, src.line + 1, src.column + 1, src.msg, hr,
697701 });
698702 },
699703 .plain => |plain| {
......@@ -747,7 +751,11 @@ pub const TestContext = struct {
747751
748752 if (ex_tag != .src) continue;
749753
750 if (actual_msg.line == case_msg.src.line and
754 const src_path_ok = case_msg.src.src_path.len == 0 or
755 std.mem.eql(u8, case_msg.src.src_path, actual_msg.src_path);
756
757 if (src_path_ok and
758 actual_msg.line == case_msg.src.line and
751759 actual_msg.column == case_msg.src.column and
752760 std.mem.eql(u8, case_msg.src.msg, actual_msg.msg) and
753761 case_msg.src.kind == .@"error")
......@@ -959,7 +967,6 @@ pub const TestContext = struct {
959967 }
960968 }
961969 }
962
963970};
964971
965972fn dumpArgs(argv: []const []const u8) void {