mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-12-22 06:03:09 -05:00
build: make Exercise.hint
optional
Use an optional type, instead of an empty string, since it is more idiomatic.
This commit is contained in:
parent
1c73ad29a7
commit
be43e2d010
2 changed files with 6 additions and 12 deletions
16
build.zig
16
build.zig
|
@ -25,7 +25,7 @@ pub const Exercise = struct {
|
|||
output: []const u8,
|
||||
|
||||
/// This is an optional hint to give if the program does not succeed.
|
||||
hint: []const u8 = "",
|
||||
hint: ?[]const u8 = null,
|
||||
|
||||
/// By default, we verify output against stderr.
|
||||
/// Set this to true to check stdout instead.
|
||||
|
@ -254,22 +254,16 @@ const ZiglingStep = struct {
|
|||
}
|
||||
|
||||
const exe_path = self.compile(prog_node) catch {
|
||||
if (self.exercise.hint.len > 0) {
|
||||
print("\n{s}HINT: {s}{s}", .{
|
||||
bold_text, self.exercise.hint, reset_text,
|
||||
});
|
||||
}
|
||||
if (self.exercise.hint) |hint|
|
||||
print("\n{s}HINT: {s}{s}", .{ bold_text, hint, reset_text });
|
||||
|
||||
self.help();
|
||||
std.os.exit(1);
|
||||
};
|
||||
|
||||
self.run(exe_path, prog_node) catch {
|
||||
if (self.exercise.hint.len > 0) {
|
||||
print("\n{s}HINT: {s}{s}", .{
|
||||
bold_text, self.exercise.hint, reset_text,
|
||||
});
|
||||
}
|
||||
if (self.exercise.hint) |hint|
|
||||
print("\n{s}HINT: {s}{s}", .{ bold_text, hint, reset_text });
|
||||
|
||||
self.help();
|
||||
std.os.exit(1);
|
||||
|
|
|
@ -175,7 +175,7 @@ pub fn addCliTests(b: *std.Build, exercises: []const Exercise) *Step {
|
|||
const cmd = b.addSystemCommand(&.{ b.zig_exe, "build", "-Dn=1" });
|
||||
cmd.setName("zig build -Dn=1");
|
||||
cmd.expectExitCode(1);
|
||||
expectStdErrMatch(cmd, exercises[0].hint);
|
||||
expectStdErrMatch(cmd, exercises[0].hint orelse "");
|
||||
|
||||
cmd.step.dependOn(case_step);
|
||||
|
||||
|
|
Loading…
Reference in a new issue