fix: runtime test fixture compilation errors

This commit is contained in:
Brett Broadhurst 2026-03-25 22:19:16 -06:00
parent 440ec68481
commit 2dfa6cd842
Failed to generate hash of commit

View file

@ -1,5 +1,6 @@
const std = @import("std"); const std = @import("std");
const Compilation = @import("compile.zig").Compilation; const compile = @import("compile.zig");
const Module = compile.Module;
test "compiler: unknown global variable" { test "compiler: unknown global variable" {
try testEqual( try testEqual(
@ -42,11 +43,16 @@ test "compiler: invalid divert target" {
fn testEqual(source_bytes: [:0]const u8, expected_error: []const u8) !void { fn testEqual(source_bytes: [:0]const u8, expected_error: []const u8) !void {
const gpa = std.testing.allocator; const gpa = std.testing.allocator;
var arena_allocator = std.heap.ArenaAllocator.init(gpa);
defer arena_allocator.deinit();
var allocating = std.io.Writer.Allocating.init(gpa); var allocating = std.io.Writer.Allocating.init(gpa);
defer allocating.deinit(); defer allocating.deinit();
const io_w = &allocating.writer;
var c = try Compilation.compile(gpa, .{ const io_w = &allocating.writer;
const arena = arena_allocator.allocator();
var c = try Module.compile(gpa, arena, .{
.source_bytes = source_bytes, .source_bytes = source_bytes,
.filename = "<STDIN>", .filename = "<STDIN>",
.dump_writer = null, .dump_writer = null,
@ -56,7 +62,7 @@ fn testEqual(source_bytes: [:0]const u8, expected_error: []const u8) !void {
}); });
defer c.deinit(); defer c.deinit();
try std.testing.expect(c.errors.len > 0); try std.testing.expect(c.errors.items.len > 0);
for (c.errors) |err| try c.renderError(io_w, err); for (c.errors.items) |err| try c.renderError(io_w, err);
return std.testing.expectEqualSlices(u8, expected_error, allocating.written()); return std.testing.expectEqualSlices(u8, expected_error, allocating.written());
} }