link tests: add a way to check prefix and use it

This commit is contained in:
Andrew Kelley
2024-10-08 21:57:08 -07:00
parent 31d70cb1e1
commit 22661f3d67
2 changed files with 13 additions and 1 deletions

View File

@@ -235,6 +235,7 @@ sanitize_coverage_trace_pc_guard: ?bool = null,
pub const ExpectedCompileErrors = union(enum) {
contains: []const u8,
exact: []const []const u8,
starts_with: []const u8,
};
pub const Entry = union(enum) {
@@ -1958,6 +1959,17 @@ fn checkCompileErrors(compile: *Compile) !void {
// TODO merge this with the testing.expectEqualStrings logic, and also CheckFile
switch (expect_errors) {
.starts_with => |expect_starts_with| {
if (std.mem.startsWith(u8, actual_stderr, expect_starts_with)) return;
return compile.step.fail(
\\
\\========= should start with: ============
\\{s}
\\========= but not found: ================
\\{s}
\\=========================================
, .{ expect_starts_with, actual_stderr });
},
.contains => |expect_line| {
while (actual_line_it.next()) |actual_line| {
if (!matchCompileError(actual_line, expect_line)) continue;

View File

@@ -3916,7 +3916,7 @@ fn testUnknownFileTypeError(b: *Build, opts: Options) *Step {
// "note: while parsing /?/liba.dylib",
// } });
expectLinkErrors(exe, test_step, .{
.contains = "error: invalid token in LD script: '\\x00\\x00\\x00\\x0c\\x00\\x00\\x00/usr/lib/dyld\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x0d' (0:1069)",
.starts_with = "error: invalid token in LD script: '\\x00\\x00\\x00\\x0c\\x00\\x00\\x00/usr/lib/dyld\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x0d' (",
});
return test_step;