From 980a278cccd342510f5d8513f1e05b15dcfc84a7 Mon Sep 17 00:00:00 2001 From: Tobias Simetsreiter Date: Wed, 16 Nov 2022 12:36:31 +0100 Subject: [PATCH 1/4] add check for trailing output characters --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 1cfa098..4a67266 100644 --- a/build.zig +++ b/build.zig @@ -683,7 +683,7 @@ const ZiglingStep = struct { } // validate the output - if (std.mem.indexOf(u8, output, self.exercise.output) == null) { + if (std.mem.indexOf(u8, output, self.exercise.output) == null or output.len != self.exercise.output.len) { print( \\ \\{s}----------- Expected this output -----------{s} From ae193c08c3bfbef3e144c427f647fdf8b77aad98 Mon Sep 17 00:00:00 2001 From: Tobias Simetsreiter Date: Wed, 16 Nov 2022 13:00:36 +0100 Subject: [PATCH 2/4] exclude trailing newlines and spaces --- build.zig | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/build.zig b/build.zig index 4a67266..8be7ea3 100644 --- a/build.zig +++ b/build.zig @@ -54,12 +54,12 @@ const Exercise = struct { const exercises = [_]Exercise{ .{ .main_file = "001_hello.zig", - .output = "Hello world", + .output = "Hello world!", .hint = "DON'T PANIC!\nRead the error above.\nSee how it has something to do with 'main'?\nOpen up the source file as noted and read the comments.\nYou can do this!", }, .{ .main_file = "002_std.zig", - .output = "Standard Library", + .output = "Standard Library.", }, .{ .main_file = "003_assignment.zig", @@ -420,7 +420,7 @@ const exercises = [_]Exercise{ }, .{ .main_file = "084_async.zig", - .output = "foo() A", + .output = "foo() A\nfoo() B", .hint = "Read the facts. Use the facts.", .@"async" = true, }, @@ -682,17 +682,19 @@ const ZiglingStep = struct { }, } + const trimOutput = std.mem.trimRight(u8, output, " \r\n"); + const trimExerciseOutput = std.mem.trimRight(u8, self.exercise.output, " \r\n"); // validate the output - if (std.mem.indexOf(u8, output, self.exercise.output) == null or output.len != self.exercise.output.len) { + if (std.mem.indexOf(u8, trimOutput, trimExerciseOutput) == null or trimOutput.len != trimExerciseOutput.len) { print( \\ \\{s}----------- Expected this output -----------{s} - \\{s} + \\"{s}" \\{s}----------- but found -----------{s} - \\{s} + \\"{s}" \\{s}-----------{s} \\ - , .{ red_text, reset_text, self.exercise.output, red_text, reset_text, output, red_text, reset_text }); + , .{ red_text, reset_text, trimExerciseOutput, red_text, reset_text, trimOutput, red_text, reset_text }); return error.InvalidOutput; } From eb24c6291a971cfcde293f6787b1081136b1648a Mon Sep 17 00:00:00 2001 From: Tobias Simetsreiter Date: Wed, 16 Nov 2022 13:05:25 +0100 Subject: [PATCH 3/4] exit non zero on error --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 8be7ea3..4a68704 100644 --- a/build.zig +++ b/build.zig @@ -621,7 +621,7 @@ const ZiglingStep = struct { print("\n{s}Edit exercises/{s} and run this again.{s}", .{ red_text, self.exercise.main_file, reset_text }); print("\n{s}To continue from this zigling, use this command:{s}\n {s}zig build {s}{s}\n", .{ red_text, reset_text, bold_text, self.exercise.key(), reset_text }); - std.os.exit(0); + std.os.exit(1); }; } From e978b09a0ac98919cbad5fe89d2e8e8adbea5a1c Mon Sep 17 00:00:00 2001 From: Tobias Simetsreiter Date: Wed, 16 Nov 2022 13:43:34 +0100 Subject: [PATCH 4/4] output fixes to 16 and 19 --- build.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.zig b/build.zig index 4a68704..852e8c3 100644 --- a/build.zig +++ b/build.zig @@ -123,7 +123,7 @@ const exercises = [_]Exercise{ }, .{ .main_file = "016_for2.zig", - .output = "13", + .output = "The value of bits '1101': 13.", }, .{ .main_file = "017_quiz2.zig", @@ -137,7 +137,7 @@ const exercises = [_]Exercise{ }, .{ .main_file = "019_functions2.zig", - .output = "2 4 8 16", + .output = "Powers of two: 2 4 8 16", }, .{ .main_file = "020_quiz3.zig", @@ -151,7 +151,7 @@ const exercises = [_]Exercise{ }, .{ .main_file = "022_errors2.zig", - .output = "I compiled", + .output = "I compiled!", .hint = "Get the error union type right to allow this to compile.", }, .{