Commit afec3e72f4
Changed files (2)
src-self-hosted
test
stage2
src-self-hosted/test.zig
@@ -110,20 +110,25 @@ pub const TestContext = struct {
pub fn addError(self: *ZIRCase, src: [:0]const u8, errors: []const []const u8) void {
var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch unreachable;
for (errors) |e, i| {
+ if (e[0] != ':') {
+ std.debug.panic("Invalid test: error must be specified as follows:\n:line:column: error: message\n=========\n", .{});
+ }
var cur = e[1..];
var line_index = std.mem.indexOf(u8, cur, ":");
if (line_index == null) {
- std.debug.panic("Invalid test: error must be specified as ':line:column: error: msg', found '{}'", .{e});
+ std.debug.panic("Invalid test: error must be specified as follows:\n:line:column: error: message\n=========\n", .{});
}
const line = std.fmt.parseInt(u32, cur[0..line_index.?], 10) catch @panic("Unable to parse line number");
cur = cur[line_index.? + 1 ..];
const column_index = std.mem.indexOf(u8, cur, ":");
if (column_index == null) {
- std.debug.panic("Invalid test: error must be specified as ':line:column: error: msg', found '{}'", .{e});
+ std.debug.panic("Invalid test: error must be specified as follows:\n:line:column: error: message\n=========\n", .{});
}
const column = std.fmt.parseInt(u32, cur[0..column_index.?], 10) catch @panic("Unable to parse column number");
cur = cur[column_index.? + 2 ..];
- std.debug.assert(std.mem.eql(u8, cur[0..7], "error: "));
+ if (!std.mem.eql(u8, cur[0..7], "error: ")) {
+ std.debug.panic("Invalid test: error must be specified as follows:\n:line:column: error: message\n=========\n", .{});
+ }
const msg = cur[7..];
if (line == 0 or column == 0) {
@@ -312,7 +317,7 @@ pub const TestContext = struct {
break;
}
} else {
- std.debug.warn("{}\nUnexpected error:\n================\n{}:{}: {}\n================\nTest failed.\n", .{ case.name, a.line + 1, a.column + 1, a.msg });
+ std.debug.warn("{}\nUnexpected error:\n================\n:{}:{}: error: {}\n================\nTest failed.\n", .{ case.name, a.line + 1, a.column + 1, a.msg });
std.process.exit(1);
}
}
test/stage2/compile_errors.zig
@@ -18,20 +18,20 @@ pub fn addCases(ctx: *TestContext) !void {
\\@start = fn(@start_fnty, {
\\ %0 = call(%test, [])
\\})
- , &[_][]const u8{":5:13: error: unrecognized identifier: %test"});
+ // TODO: address inconsistency in this message and the one in the next test
+ , &[_][]const u8{":5:13: error: unrecognized identifier: %test"});
- // TODO: fix this test
- // ctx.addZIRError("call with non-existent target", linux_x64,
- // \\@noreturn = primitive(noreturn)
- // \\
- // \\@start_fnty = fntype([], @noreturn, cc=Naked)
- // \\@start = fn(@start_fnty, {
- // \\ %0 = call(@notafunc, [])
- // \\})
- // \\@0 = str("_start")
- // \\@1 = ref(@0)
- // \\@2 = export(@1, @start)
- // , &[_][]const u8{"5:13:unrecognized identifier: @notafunc"});
+ ctx.addZIRError("call with non-existent target", linux_x64,
+ \\@noreturn = primitive(noreturn)
+ \\
+ \\@start_fnty = fntype([], @noreturn, cc=Naked)
+ \\@start = fn(@start_fnty, {
+ \\ %0 = call(@notafunc, [])
+ \\})
+ \\@0 = str("_start")
+ \\@1 = ref(@0)
+ \\@2 = export(@1, @start)
+ , &[_][]const u8{":5:13: error: use of undeclared identifier 'notafunc'"});
// TODO: this error should occur at the call site, not the fntype decl
ctx.addZIRError("call naked function", linux_x64,