From 22661f3d67251688a1fabf9e5fe65210ce284b9f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 8 Oct 2024 21:57:08 -0700 Subject: [PATCH] link tests: add a way to check prefix and use it --- lib/std/Build/Step/Compile.zig | 12 ++++++++++++ test/link/elf.zig | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 0f0b5d3201..a977dc3056 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -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; diff --git a/test/link/elf.zig b/test/link/elf.zig index d261185851..2d66051cdf 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -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;