test: fix incorrect cleanup code

The current cleanup code is incorrect, since it may delete the healed
directory while one test case is running.

The solution is to make each test case isolate, with its own setup and
teardown.  Unfortunately it is currently not possible, since each test
case modify the same directory.

Disable the cleanup step, until a better solution is found.
This commit is contained in:
Manlio Perillo 2023-04-20 21:13:13 +02:00
parent 108c145bdd
commit cec0aa51db

View file

@ -7,8 +7,8 @@ const fs = std.fs;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const Build = std.build; const Build = std.build;
const Step = Build.Step;
const RunStep = std.Build.RunStep; const RunStep = std.Build.RunStep;
const Step = Build.Step;
const Exercise = root.Exercise; const Exercise = root.Exercise;
@ -27,9 +27,9 @@ pub fn addCliTests(b: *std.Build, exercises: []const Exercise) *Step {
}; };
{ {
// Test that `zig build -Dn=n -Dhealed test` selects the nth exercise.
const case_step = createCase(b, "case-1"); const case_step = createCase(b, "case-1");
// Test that `zig build -Dn=n -Dhealed test` selects the nth exercise.
var i: usize = 0; var i: usize = 0;
for (exercises[0 .. exercises.len - 1]) |ex| { for (exercises[0 .. exercises.len - 1]) |ex| {
i += 1; i += 1;
@ -54,9 +54,9 @@ pub fn addCliTests(b: *std.Build, exercises: []const Exercise) *Step {
} }
{ {
// Test that `zig build -Dn=n -Dhealed test` skips disabled esercises.
const case_step = createCase(b, "case-2"); const case_step = createCase(b, "case-2");
// Test that `zig build -Dn=n -Dhealed test` skips disabled esercises.
var i: usize = 0; var i: usize = 0;
for (exercises[0 .. exercises.len - 1]) |ex| { for (exercises[0 .. exercises.len - 1]) |ex| {
i += 1; i += 1;
@ -76,8 +76,10 @@ pub fn addCliTests(b: *std.Build, exercises: []const Exercise) *Step {
step.dependOn(case_step); step.dependOn(case_step);
} }
const cleanup = b.addRemoveDirTree(outdir); // Don't add the cleanup step, since it may delete outdir while a test case
step.dependOn(&cleanup.step); // is running.
//const cleanup = b.addRemoveDirTree(outdir);
//step.dependOn(&cleanup.step);
return step; return step;
} }