#`expectExitCode` not expecting said exit code.

1 messages · Page 1 of 1 (latest)

foggy sun
#

Hello.

I made a small write-up in Ziggit here.

In short, I am adding steps to run files in a gven folder. I expect the files to give a result 0. However, the build seems to fail on the first 0 result even tho I expectExitCode(1) on all of them.

Code is here : ```ts
// in fn build
{ // zig build eye command
const eye_step = b.step("eye", "Eye test all the files in a given directory");

    if (b.option(std.Build.LazyPath, "folder", "Path to eye")) |lazy|
        try walk_tree(b, exe, eye_step, lazy)
    else
        eye_step.dependOn(&b.addFail("folder needed for eye").step);
}

// later
fn walk_tree(
b: *std.Build,
exe: *std.Build.Step.Compile,
eye_step: *std.Build.Step,
lazy: std.Build.LazyPath,
) !void {
const path = lazy.getPath3(b, null);
const dir = try path.openDir("", .{ .iterate = true });
var walker = dir.iterate();

// const fail = b.option(bool, "fail", "failing tests") orelse false; // uncommenting this

var prev_run_cmd: ?*std.Build.Step.Run = null;
while (try walker.next()) |entry| if (entry.kind == .file and
    std.mem.endsWith(u8, entry.name, ".c"))
{
    const file = entry.name;

    const bat = b.addSystemCommand(&.{ "bat", file });
    bat.addArg("--paging=never");
    bat.setCwd(lazy);
    bat.stdio = .inherit;

    if (prev_run_cmd) |c|
        bat.step.dependOn(&c.step);

    const run_cmd = b.addRunArtifact(exe);
    // if (fail) run_cmd.expectExitCode(1); // and this , doesnt make a difference
    run_cmd.setCwd(lazy);
    run_cmd.addArg(file);
    run_cmd.addArgs(b.args orelse &.{});
    run_cmd.stdio = .inherit;

    run_cmd.step.dependOn(b.getInstallStep());
    run_cmd.step.dependOn(&bat.step);

    prev_run_cmd = run_cmd;
};

eye_step.dependOn(&prev_run_cmd.?.step);

}```

thorny idol
#

if you do expectExitCode then it should fail on code 0 and succeed on code 1, is that not what happens?

foggy sun
#

it fails on code 1 and passes on code 0 regardless of whther -Dfail is passed

thorny idol
#

oh it's because you set run_cmd.stdio = .inherit

#

expectExitCode calls addCheck which sets stdio to .{ .check = .{} }

foggy sun
#

ah makes sense