authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-08 15:32:55-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-09 15:37:16-07:00
logbc36da0cb80eebffbbd86a430b435492e00f8378
tree3060a85bfe1a989a119aaac1e3b53df7b24af9f3
parentfd32f6890db8d338ec5cad92871035767f2e84ac

test harness: fix handling of counts

I'm not really happy with parsing compile errors; I think we should just be checking that the expected compile error matches the actual rendered version. I will save that change for a later date however.

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

src/test.zig+36-7
......@@ -61,10 +61,12 @@ const ErrorMsg = union(enum) {
6161 // this is a workaround for stage1 compiler bug I ran into when making it ?u32
6262 column: u32,
6363 kind: Kind,
64 count: u32,
6465 },
6566 plain: struct {
6667 msg: []const u8,
6768 kind: Kind,
69 count: u32,
6870 },
6971
7072 const Kind = enum {
......@@ -81,12 +83,14 @@ const ErrorMsg = union(enum) {
8183 .line = @intCast(u32, src.line),
8284 .column = @intCast(u32, src.column),
8385 .kind = kind,
86 .count = src.count,
8487 },
8588 },
8689 .plain => |plain| return .{
8790 .plain = .{
8891 .msg = plain.msg,
8992 .kind = kind,
93 .count = plain.count,
9094 },
9195 },
9296 }
......@@ -118,10 +122,16 @@ const ErrorMsg = union(enum) {
118122 try writer.writeAll("?: ");
119123 }
120124 }
121 return writer.print("{s}: {s}", .{ @tagName(src.kind), src.msg });
125 try writer.print("{s}: {s}", .{ @tagName(src.kind), src.msg });
126 if (src.count != 1) {
127 try writer.print(" ({d} times)", .{src.count});
128 }
122129 },
123130 .plain => |plain| {
124 return writer.print("{s}: {s}", .{ @tagName(plain.kind), plain.msg });
131 try writer.print("{s}: {s}", .{ @tagName(plain.kind), plain.msg });
132 if (plain.count != 1) {
133 try writer.print(" ({d} times)", .{plain.count});
134 }
125135 },
126136 }
127137 }
......@@ -647,12 +657,20 @@ pub const TestContext = struct {
647657 for (errors) |err_msg_line, i| {
648658 if (std.mem.startsWith(u8, err_msg_line, "error: ")) {
649659 array[i] = .{
650 .plain = .{ .msg = err_msg_line["error: ".len..], .kind = .@"error" },
660 .plain = .{
661 .msg = err_msg_line["error: ".len..],
662 .kind = .@"error",
663 .count = 1,
664 },
651665 };
652666 continue;
653667 } else if (std.mem.startsWith(u8, err_msg_line, "note: ")) {
654668 array[i] = .{
655 .plain = .{ .msg = err_msg_line["note: ".len..], .kind = .note },
669 .plain = .{
670 .msg = err_msg_line["note: ".len..],
671 .kind = .note,
672 .count = 1,
673 },
656674 };
657675 continue;
658676 }
......@@ -662,7 +680,7 @@ pub const TestContext = struct {
662680 const line_text = it.next() orelse @panic("missing line");
663681 const col_text = it.next() orelse @panic("missing column");
664682 const kind_text = it.next() orelse @panic("missing 'error'/'note'");
665 const msg = it.rest()[1..]; // skip over the space at end of "error: "
683 var msg = it.rest()[1..]; // skip over the space at end of "error: "
666684
667685 const line: ?u32 = if (std.mem.eql(u8, line_text, "?"))
668686 null
......@@ -695,6 +713,14 @@ pub const TestContext = struct {
695713 break :blk n - 1;
696714 } else std.math.maxInt(u32);
697715
716 const suffix = " times)";
717 const count = if (std.mem.endsWith(u8, msg, suffix)) count: {
718 const lparen = std.mem.lastIndexOfScalar(u8, msg, '(').?;
719 const count = std.fmt.parseInt(u32, msg[lparen + 1 .. msg.len - suffix.len], 10) catch @panic("bad error note count number");
720 msg = msg[0 .. lparen - 1];
721 break :count count;
722 } else 1;
723
698724 array[i] = .{
699725 .src = .{
700726 .src_path = src_path,
......@@ -702,6 +728,7 @@ pub const TestContext = struct {
702728 .line = line_0based,
703729 .column = column_0based,
704730 .kind = kind,
731 .count = count,
705732 },
706733 };
707734 }
......@@ -1606,7 +1633,8 @@ pub const TestContext = struct {
16061633 (case_msg.src.column == std.math.maxInt(u32) or
16071634 actual_msg.column == case_msg.src.column) and
16081635 std.mem.eql(u8, expected_msg, actual_msg.msg) and
1609 case_msg.src.kind == .@"error")
1636 case_msg.src.kind == .@"error" and
1637 actual_msg.count == case_msg.src.count)
16101638 {
16111639 handled_errors[i] = true;
16121640 break;
......@@ -1616,7 +1644,8 @@ pub const TestContext = struct {
16161644 if (ex_tag != .plain) continue;
16171645
16181646 if (std.mem.eql(u8, case_msg.plain.msg, plain.msg) and
1619 case_msg.plain.kind == .@"error")
1647 case_msg.plain.kind == .@"error" and
1648 case_msg.plain.count == plain.count)
16201649 {
16211650 handled_errors[i] = true;
16221651 break;