From 51f2442fc4160415796cf6271d1951969ab71c83 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Wed, 22 Jun 2022 22:24:52 +0200 Subject: link-tests: clean up error messages in case of failure --- lib/std/build/CheckObjectStep.zig | 47 +++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'lib/std/build/CheckObjectStep.zig') diff --git a/lib/std/build/CheckObjectStep.zig b/lib/std/build/CheckObjectStep.zig index 40266d0c85..66edc084cd 100644 --- a/lib/std/build/CheckObjectStep.zig +++ b/lib/std/build/CheckObjectStep.zig @@ -4,6 +4,7 @@ const build = std.build; const fs = std.fs; const macho = std.macho; const mem = std.mem; +const testing = std.testing; const CheckObjectStep = @This(); @@ -179,13 +180,16 @@ fn make(step: *Step) !void { switch (act) { .match => |match_act| { while (it.next()) |line| { - if (try match_act.match(line, &vars)) { - std.debug.print("{s} == {s}\n", .{ line, match_act.needle }); - break; - } else { - std.debug.print("{s} != {s}\n", .{ line, match_act.needle }); - } + if (try match_act.match(line, &vars)) break; } else { + std.debug.print( + \\ + \\========= Expected to find: ========================== + \\{s} + \\========= But parsed file does not contain it: ======= + \\{s} + \\ + , .{ match_act.needle, output }); return error.TestFailed; } }, @@ -193,7 +197,17 @@ fn make(step: *Step) !void { var values = std.ArrayList(u64).init(gpa); try values.ensureTotalCapacity(c_eq.var_stack.items.len); for (c_eq.var_stack.items) |vv| { - const val = vars.get(vv) orelse return error.TestFailed; + const val = vars.get(vv) orelse { + std.debug.print( + \\ + \\========= Variable was not extracted: =========== + \\{s} + \\========= From parsed file: ===================== + \\{s} + \\ + , .{ vv, output }); + return error.TestFailed; + }; values.appendAssumeCapacity(val); } @@ -208,17 +222,22 @@ fn make(step: *Step) !void { } } - const expected = vars.get(c_eq.expected) orelse return error.TestFailed; - if (reduced != expected) return error.TestFailed; + const expected = vars.get(c_eq.expected) orelse { + std.debug.print( + \\ + \\========= Variable was not extracted: =========== + \\{s} + \\========= From parsed file: ===================== + \\{s} + \\ + , .{ c_eq.expected, output }); + return error.TestFailed; + }; + try testing.expectEqual(reduced, expected); }, } } } - - var it = vars.iterator(); - while (it.next()) |entry| { - std.debug.print(" {s} => {x}\n", .{ entry.key_ptr.*, entry.value_ptr.* }); - } } const Opts = struct { -- cgit v1.2.3