feature. See also
. The project being documented here (as the example) is the Zig library itself.
Compile.checkCompileErrors
fn checkCompileErrors(arena: Allocator, maker: *Maker, step_index: Configuration.Step.Index) Step.ExtendedMakeError!void
File
Code
fn checkCompileErrors(arena: Allocator, maker: *Maker, step_index: Configuration.Step.Index) Step.ExtendedMakeError!void {
const step = maker.stepByIndex(step_index);
const conf = &maker.scanned_config.configuration;
const conf_step = step_index.ptr(conf);
const conf_comp = conf_step.extended.get(conf.extra).compile;
var actual_eb = step.result_error_bundle;
step.result_error_bundle = .empty;
defer actual_eb.deinit(maker.gpa);
const actual_errors = ae: {
var aw: std.Io.Writer.Allocating = .init(arena);
defer aw.deinit();
actual_eb.renderToWriter(.{
.include_reference_trace = false,
.include_source_line = false,
}, &aw.writer) catch |err| switch (err) {
error.WriteFailed => return error.OutOfMemory,
};
break :ae try aw.toOwnedSlice();
};
var expected_generated: std.ArrayList(u8) = .empty;
var actual_line_it = mem.splitScalar(u8, actual_errors, '\n');
switch (conf_comp.expect_errors.u) {
.none => unreachable,
.starts_with => |expect_starts_with_string| {
const expect_starts_with = expect_starts_with_string.slice(conf);
if (mem.startsWith(u8, actual_errors, expect_starts_with)) return;
return step.fail(maker,
\\
\\========= should start with: ============
\\{s}
\\========= but not found: ================
\\{s}
\\=========================================
, .{ expect_starts_with, actual_errors });
},
.contains => |expect_line_string| {
const expect_line = expect_line_string.slice(conf);
while (actual_line_it.next()) |actual_line| {
if (!matchCompileError(actual_line, expect_line)) continue;
return;
}
return step.fail(maker,
\\
\\========= should contain: ===============
\\{s}
\\========= but not found: ================
\\{s}
\\=========================================
, .{ expect_line, actual_errors });
},
.stderr_contains => |expect_line_string| {
const expect_line = expect_line_string.slice(conf);
const actual_stderr: []const u8 = if (step.result_error_msgs.items.len > 0)
step.result_error_msgs.items[0]
else
&.{};
step.result_error_msgs.clearRetainingCapacity();
var stderr_line_it = mem.splitScalar(u8, actual_stderr, '\n');
while (stderr_line_it.next()) |actual_line| {
if (!matchCompileError(actual_line, expect_line)) continue;
return;
}
return step.fail(maker,
\\
\\========= should contain: ===============
\\{s}
\\========= but not found: ================
\\{s}
\\=========================================
, .{ expect_line, actual_stderr });
},
.exact => |expect_lines| {
for (expect_lines.slice) |expect_line_string| {
const expect_line = expect_line_string.slice(conf);
const actual_line = actual_line_it.next() orelse {
try expected_generated.appendSlice(arena, expect_line);
try expected_generated.append(arena, '\n');
continue;
};
if (matchCompileError(actual_line, expect_line)) {
try expected_generated.appendSlice(arena, actual_line);
try expected_generated.append(arena, '\n');
continue;
}
try expected_generated.appendSlice(arena, expect_line);
try expected_generated.append(arena, '\n');
}
if (mem.eql(u8, expected_generated.items, actual_errors)) return;
return step.fail(maker,
\\
\\========= expected: =====================
\\{s}
\\========= but found: ====================
\\{s}
\\=========================================
, .{ expected_generated.items, actual_errors });
},
}
}