diff options
| author | Manlio Perillo <[email protected]> | 2023-05-04 16:34:17 +0200 |
|---|---|---|
| committer | Manlio Perillo <[email protected]> | 2023-05-04 16:34:17 +0200 |
| commit | 5c488a1402be83f198cc29f23f448313001a9a1c (patch) | |
| tree | 8388e1be42305a794edf15ebfb43a90e03930e80 /test | |
| parent | a2b7fbe3e590d41e434496b8266fb89dd403baea (diff) | |
| download | ziglings-5c488a1402be83f198cc29f23f448313001a9a1c.tar.xz ziglings-5c488a1402be83f198cc29f23f448313001a9a1c.zip | |
test: improve test case 1 and 2
In test case 1 and 2, remove the `i` variable and use `ex.number()`
instead.
In test case 2, when checking the exercise output from stderr, also
check that stdout is empty and vice versa.
Diffstat (limited to 'test')
| -rw-r--r-- | test/tests.zig | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/test/tests.zig b/test/tests.zig index 752ca50..060b553 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -32,21 +32,23 @@ pub fn addCliTests(b: *std.Build, exercises: []const Exercise) *Step { // Test that `zig build -Dhealed -Dn=n test` selects the nth exercise. const case_step = createCase(b, "case-1"); - var i: usize = 0; for (exercises[0 .. exercises.len - 1]) |ex| { - i += 1; + const n = ex.number(); if (ex.skip) continue; const cmd = b.addSystemCommand( - &.{ b.zig_exe, "build", "-Dhealed", b.fmt("-Dn={}", .{i}), "test" }, + &.{ b.zig_exe, "build", "-Dhealed", b.fmt("-Dn={}", .{n}), "test" }, ); - cmd.setName(b.fmt("zig build -Dhealed -Dn={} test", .{i})); + cmd.setName(b.fmt("zig build -Dhealed -Dn={} test", .{n})); cmd.expectExitCode(0); - if (ex.check_stdout) - expectStdOutMatch(cmd, ex.output) - else + if (ex.check_stdout) { + expectStdOutMatch(cmd, ex.output); + cmd.expectStdErrEqual(""); + } else { expectStdErrMatch(cmd, ex.output); + cmd.expectStdOutEqual(""); + } cmd.step.dependOn(&heal_step.step); @@ -60,15 +62,14 @@ pub fn addCliTests(b: *std.Build, exercises: []const Exercise) *Step { // Test that `zig build -Dhealed -Dn=n test` skips disabled esercises. const case_step = createCase(b, "case-2"); - var i: usize = 0; for (exercises[0 .. exercises.len - 1]) |ex| { - i += 1; + const n = ex.number(); if (!ex.skip) continue; const cmd = b.addSystemCommand( - &.{ b.zig_exe, "build", "-Dhealed", b.fmt("-Dn={}", .{i}), "test" }, + &.{ b.zig_exe, "build", "-Dhealed", b.fmt("-Dn={}", .{n}), "test" }, ); - cmd.setName(b.fmt("zig build -Dhealed -Dn={} test", .{i})); + cmd.setName(b.fmt("zig build -Dhealed -Dn={} test", .{n})); cmd.expectExitCode(0); cmd.expectStdOutEqual(""); expectStdErrMatch(cmd, b.fmt("{s} skipped", .{ex.main_file})); |
