refactor: new direction for error reporting

This commit is contained in:
Brett Broadhurst 2026-03-18 17:52:07 -06:00
parent 72b686d750
commit c940374f27
Failed to generate hash of commit
11 changed files with 758 additions and 582 deletions

37
src/error_tests.zig Normal file
View file

@ -0,0 +1,37 @@
const std = @import("std");
const Compilation = @import("compile.zig").Compilation;
test "compiler: global variable shadowing" {
try testEqual(
\\VAR a = 0
\\VAR b = 2
\\VAR a = 1
,
\\<STDIN>:3:1: error: redefined identifier
\\3 | VAR a = 1
\\ | ^
\\
,
);
}
fn testEqual(source_bytes: [:0]const u8, expected_error: []const u8) !void {
const gpa = std.testing.allocator;
var allocating = std.io.Writer.Allocating.init(gpa);
defer allocating.deinit();
const io_w = &allocating.writer;
var c = try Compilation.compile(gpa, .{
.source_bytes = source_bytes,
.filename = "<STDIN>",
.dump_writer = null,
.dump_use_color = false,
.dump_ast = false,
.dump_ir = false,
});
defer c.deinit();
try std.testing.expect(c.errors.len > 0);
for (c.errors) |err| try c.renderError(io_w, err);
return std.testing.expectEqualSlices(u8, expected_error, allocating.written());
}