diff options
author | Chris Boesch <chrboesch@noreply.codeberg.org> | 2023-01-21 17:17:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-21 17:17:46 +0100 |
commit | ce8102f83016378887ad3c7214126a940fe0d19a (patch) | |
tree | 2b0b205b3aa79cc5cbaa66301318aae72dbbb73b /build.zig | |
parent | 4e8d91c8f2f6095cc27ab31960fe081e55268ecb (diff) | |
parent | 68af87518f1b56170bb6c526fe0770c3c20ebabb (diff) |
Merge pull request #145 from dasimmet/check_output_len
add check for trailing output characters
Diffstat (limited to 'build.zig')
-rw-r--r-- | build.zig | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -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", @@ -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.", }, .{ @@ -622,7 +622,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); }; } @@ -683,17 +683,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) { + 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; } |