mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.Build.Step.Compile: add a way to expect an error message
other than a compile error, specifically
This commit is contained in:
parent
1e785409bb
commit
a4cc344aa0
1 changed files with 32 additions and 8 deletions
|
|
@ -236,6 +236,7 @@ pub const ExpectedCompileErrors = union(enum) {
|
||||||
contains: []const u8,
|
contains: []const u8,
|
||||||
exact: []const []const u8,
|
exact: []const []const u8,
|
||||||
starts_with: []const u8,
|
starts_with: []const u8,
|
||||||
|
stderr_contains: []const u8,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Entry = union(enum) {
|
pub const Entry = union(enum) {
|
||||||
|
|
@ -1945,24 +1946,24 @@ fn checkCompileErrors(compile: *Compile) !void {
|
||||||
|
|
||||||
const arena = compile.step.owner.allocator;
|
const arena = compile.step.owner.allocator;
|
||||||
|
|
||||||
var actual_stderr_list = std.ArrayList(u8).init(arena);
|
var actual_errors_list = std.ArrayList(u8).init(arena);
|
||||||
try actual_eb.renderToWriter(.{
|
try actual_eb.renderToWriter(.{
|
||||||
.ttyconf = .no_color,
|
.ttyconf = .no_color,
|
||||||
.include_reference_trace = false,
|
.include_reference_trace = false,
|
||||||
.include_source_line = false,
|
.include_source_line = false,
|
||||||
}, actual_stderr_list.writer());
|
}, actual_errors_list.writer());
|
||||||
const actual_stderr = try actual_stderr_list.toOwnedSlice();
|
const actual_errors = try actual_errors_list.toOwnedSlice();
|
||||||
|
|
||||||
// Render the expected lines into a string that we can compare verbatim.
|
// Render the expected lines into a string that we can compare verbatim.
|
||||||
var expected_generated = std.ArrayList(u8).init(arena);
|
var expected_generated = std.ArrayList(u8).init(arena);
|
||||||
const expect_errors = compile.expect_errors.?;
|
const expect_errors = compile.expect_errors.?;
|
||||||
|
|
||||||
var actual_line_it = mem.splitScalar(u8, actual_stderr, '\n');
|
var actual_line_it = mem.splitScalar(u8, actual_errors, '\n');
|
||||||
|
|
||||||
// TODO merge this with the testing.expectEqualStrings logic, and also CheckFile
|
// TODO merge this with the testing.expectEqualStrings logic, and also CheckFile
|
||||||
switch (expect_errors) {
|
switch (expect_errors) {
|
||||||
.starts_with => |expect_starts_with| {
|
.starts_with => |expect_starts_with| {
|
||||||
if (std.mem.startsWith(u8, actual_stderr, expect_starts_with)) return;
|
if (std.mem.startsWith(u8, actual_errors, expect_starts_with)) return;
|
||||||
return compile.step.fail(
|
return compile.step.fail(
|
||||||
\\
|
\\
|
||||||
\\========= should start with: ============
|
\\========= should start with: ============
|
||||||
|
|
@ -1970,7 +1971,7 @@ fn checkCompileErrors(compile: *Compile) !void {
|
||||||
\\========= but not found: ================
|
\\========= but not found: ================
|
||||||
\\{s}
|
\\{s}
|
||||||
\\=========================================
|
\\=========================================
|
||||||
, .{ expect_starts_with, actual_stderr });
|
, .{ expect_starts_with, actual_errors });
|
||||||
},
|
},
|
||||||
.contains => |expect_line| {
|
.contains => |expect_line| {
|
||||||
while (actual_line_it.next()) |actual_line| {
|
while (actual_line_it.next()) |actual_line| {
|
||||||
|
|
@ -1978,6 +1979,29 @@ fn checkCompileErrors(compile: *Compile) !void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return compile.step.fail(
|
||||||
|
\\
|
||||||
|
\\========= should contain: ===============
|
||||||
|
\\{s}
|
||||||
|
\\========= but not found: ================
|
||||||
|
\\{s}
|
||||||
|
\\=========================================
|
||||||
|
, .{ expect_line, actual_errors });
|
||||||
|
},
|
||||||
|
.stderr_contains => |expect_line| {
|
||||||
|
const actual_stderr: []const u8 = if (compile.step.result_error_msgs.items.len > 0)
|
||||||
|
compile.step.result_error_msgs.items[0]
|
||||||
|
else
|
||||||
|
&.{};
|
||||||
|
compile.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 compile.step.fail(
|
return compile.step.fail(
|
||||||
\\
|
\\
|
||||||
\\========= should contain: ===============
|
\\========= should contain: ===============
|
||||||
|
|
@ -2003,7 +2027,7 @@ fn checkCompileErrors(compile: *Compile) !void {
|
||||||
try expected_generated.append('\n');
|
try expected_generated.append('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mem.eql(u8, expected_generated.items, actual_stderr)) return;
|
if (mem.eql(u8, expected_generated.items, actual_errors)) return;
|
||||||
|
|
||||||
return compile.step.fail(
|
return compile.step.fail(
|
||||||
\\
|
\\
|
||||||
|
|
@ -2012,7 +2036,7 @@ fn checkCompileErrors(compile: *Compile) !void {
|
||||||
\\========= but found: ====================
|
\\========= but found: ====================
|
||||||
\\{s}
|
\\{s}
|
||||||
\\=========================================
|
\\=========================================
|
||||||
, .{ expected_generated.items, actual_stderr });
|
, .{ expected_generated.items, actual_errors });
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue