Skip to content

Zig build system does not fail when a test fails #15009

@Hejsil

Description

@Hejsil

Zig Version

0.11.0-dev.2165+8f481dfc3

Steps to Reproduce and Observed Behavior

// build.zig
const std = @import("std");

pub fn build(b: *std.Build) void {
    const exe_tests = b.addTest(.{
        .root_source_file = .{ .path = "src/main.zig" },
    });
    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&exe_tests.step);
}
// src/main.zig
test "simple test" {
    unreachable;
}
$ zig build test

Expected Behavior

I expect to get a stack trace in my terminal showing the test failure. Instead, the command silently exits with a successful status code.

Running zig build test --verbose we can see that it seems to be actually running the test:

$ zig build test --verbose
<path-to>/zig test <path-to>/src/main.zig --cache-dir <path-to>/zig-cache --global-cache-dir <path-to>/.cache/zig --name test --enable-cache --listen=-

If I take the same command, remove --listen=-, this works just fine:

$ <path-to>/zig test <path-to>/src/main.zig --cache-dir <path-to>/zig-cache --global-cache-dir <path-to>/.cache/zig --name test --enable-cache
<path-to>/zig-cache/o/25622b855bc097280dff3f8cb897732b
Test [1/1] test.simple test... thread 80083 panic: reached unreachable code
<path-to>/src/main.zig:2:5: 0x20dc95 in test.simple test (test)
    unreachable;
    ^
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingImplementing this issue could cause existing code to no longer compile or have different behavior.enhancementSolving this issue will likely involve adding new logic or components to the codebase.zig build systemstd.Build, the build runner, `zig build` subcommand, package management

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions