authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-06-22 22:24:52+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-06-22 22:24:52+02:00
log51f2442fc4160415796cf6271d1951969ab71c83
tree1ba34f266051183294004a55c7b0cd117d69c6a7
parentba768614aceb486bc387e60a6026f4f48188402e

link-tests: clean up error messages in case of failure


1 files changed, 33 insertions(+), 14 deletions(-)

lib/std/build/CheckObjectStep.zig+33-14
...@@ -4,6 +4,7 @@ const build = std.build;...@@ -4,6 +4,7 @@ const build = std.build;
4const fs = std.fs;4const fs = std.fs;
5const macho = std.macho;5const macho = std.macho;
6const mem = std.mem;6const mem = std.mem;
7const testing = std.testing;
78
8const CheckObjectStep = @This();9const CheckObjectStep = @This();
910
...@@ -179,13 +180,16 @@ fn make(step: *Step) !void {...@@ -179,13 +180,16 @@ fn make(step: *Step) !void {
179 switch (act) {180 switch (act) {
180 .match => |match_act| {181 .match => |match_act| {
181 while (it.next()) |line| {182 while (it.next()) |line| {
182 if (try match_act.match(line, &vars)) {183 if (try match_act.match(line, &vars)) break;
183 std.debug.print("{s} == {s}\n", .{ line, match_act.needle });
184 break;
185 } else {
186 std.debug.print("{s} != {s}\n", .{ line, match_act.needle });
187 }
188 } else {184 } else {
185 std.debug.print(
186 \\
187 \\========= Expected to find: ==========================
188 \\{s}
189 \\========= But parsed file does not contain it: =======
190 \\{s}
191 \\
192 , .{ match_act.needle, output });
189 return error.TestFailed;193 return error.TestFailed;
190 }194 }
191 },195 },
...@@ -193,7 +197,17 @@ fn make(step: *Step) !void {...@@ -193,7 +197,17 @@ fn make(step: *Step) !void {
193 var values = std.ArrayList(u64).init(gpa);197 var values = std.ArrayList(u64).init(gpa);
194 try values.ensureTotalCapacity(c_eq.var_stack.items.len);198 try values.ensureTotalCapacity(c_eq.var_stack.items.len);
195 for (c_eq.var_stack.items) |vv| {199 for (c_eq.var_stack.items) |vv| {
196 const val = vars.get(vv) orelse return error.TestFailed;200 const val = vars.get(vv) orelse {
201 std.debug.print(
202 \\
203 \\========= Variable was not extracted: ===========
204 \\{s}
205 \\========= From parsed file: =====================
206 \\{s}
207 \\
208 , .{ vv, output });
209 return error.TestFailed;
210 };
197 values.appendAssumeCapacity(val);211 values.appendAssumeCapacity(val);
198 }212 }
199213
...@@ -208,17 +222,22 @@ fn make(step: *Step) !void {...@@ -208,17 +222,22 @@ fn make(step: *Step) !void {
208 }222 }
209 }223 }
210224
211 const expected = vars.get(c_eq.expected) orelse return error.TestFailed;225 const expected = vars.get(c_eq.expected) orelse {
212 if (reduced != expected) return error.TestFailed;226 std.debug.print(
227 \\
228 \\========= Variable was not extracted: ===========
229 \\{s}
230 \\========= From parsed file: =====================
231 \\{s}
232 \\
233 , .{ c_eq.expected, output });
234 return error.TestFailed;
235 };
236 try testing.expectEqual(reduced, expected);
213 },237 },
214 }238 }
215 }239 }
216 }240 }
217
218 var it = vars.iterator();
219 while (it.next()) |entry| {
220 std.debug.print(" {s} => {x}\n", .{ entry.key_ptr.*, entry.value_ptr.* });
221 }
222}241}
223242
224const Opts = struct {243const Opts = struct {