diff options
| author | Manlio Perillo <[email protected]> | 2023-05-15 15:23:10 +0200 |
|---|---|---|
| committer | Manlio Perillo <[email protected]> | 2023-05-15 15:36:31 +0200 |
| commit | 9ab9ebf33f7637236cea568a3565888b78fd08e5 (patch) | |
| tree | d2ce675276be2d2a2d4a4d8370892fa603a6b469 /test/tests.zig | |
| parent | 3dafa3518b9a9309de101abe225266a279a23a8c (diff) | |
| download | ziglings-9ab9ebf33f7637236cea568a3565888b78fd08e5.tar.xz ziglings-9ab9ebf33f7637236cea568a3565888b78fd08e5.zip | |
Refactor testing support
Following the implementation in `std.Build.Step.Compile, add the Kind
type to differentiate between a normal executable and a test executable
running zig tests. Replace `Exercise.run_test` field with `kind`.
Compile the exercise in both the exe and test cases, reducing code
duplication.
Add the `check_output` and `check_test` methods in ZiglingStep, in order
to differentiate the code checking a normal executable and a test
executable.
Update the tests to correctly check both the exe and test cases. Remove
the temporary code added in commit 832772c.
Diffstat (limited to 'test/tests.zig')
| -rw-r--r-- | test/tests.zig | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/test/tests.zig b/test/tests.zig index b25b29c..45c075c 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -93,7 +93,7 @@ pub fn addCliTests(b: *std.Build, exercises: []const Exercise) *Step { const case_step = createCase(b, "case-3"); for (exercises[0 .. exercises.len - 1]) |ex| { - if (ex.skip or ex.run_test) continue; + if (ex.skip) continue; if (ex.hint) |hint| { const n = ex.number(); @@ -249,21 +249,6 @@ fn check_output(step: *Step, exercise: Exercise, reader: Reader) !void { return; } - if (exercise.run_test) { - { - const actual = try readLine(reader, &buf) orelse "EOF"; - const expect = b.fmt("Testing {s}...", .{exercise.main_file}); - try check(step, exercise, expect, actual); - } - - { - const actual = try readLine(reader, &buf) orelse "EOF"; - try check(step, exercise, "", actual); - } - - return; - } - { const actual = try readLine(reader, &buf) orelse "EOF"; const expect = b.fmt("Compiling {s}...", .{exercise.main_file}); @@ -278,12 +263,19 @@ fn check_output(step: *Step, exercise: Exercise, reader: Reader) !void { { const actual = try readLine(reader, &buf) orelse "EOF"; - const expect = "PASSED:"; + const expect = switch (exercise.kind) { + .exe => "PASSED:", + .@"test" => "PASSED", + }; try check(step, exercise, expect, actual); } // Skip the exercise output. - const nlines = 1 + mem.count(u8, exercise.output, "\n") + 1; + const nlines = switch (exercise.kind) { + .exe => 1 + mem.count(u8, exercise.output, "\n") + 1, + .@"test" => 1, + }; + var lineno: usize = 0; while (lineno < nlines) : (lineno += 1) { _ = try readLine(reader, &buf) orelse @panic("EOF"); |
