Skip to content

build system hides error name when test fails #23860

@nektro

Description

@nektro

Zig Version

0.14.0, 0.15.0-dev.482+2c241b263

Steps to Reproduce and Observed Behavior

const std = @import("std");

test {
    try foo(3);
}

fn foo(x: u32) !void {
    return switch (x) {
        1 => error.A,
        2 => error.B,
        3 => error.C,
        4 => error.D,
        5 => error.E,
        else => {},
    };
}
const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const tests = b.addTest(.{
        .root_source_file = b.path("./test.zig"),
        .target = target,
        .optimize = optimize,
    });

    const run_tests = b.addRunArtifact(tests);

    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&run_tests.step);
}
$ zig-master build test
test
└─ run test 0/1 passed, 1 failed
error: 'test.test_0' failed: $PWD/test.zig:8:5: 0x1048a98 in foo (test)
    return switch (x) {
    ^
$PWD/test.zig:4:5: 0x1048b38 in test_0 (test)
    try foo(3);
    ^
error: while executing test 'test.test_0', the following test command failed:
/home/meghan/zig-cache/o/cf287d5d26fc1fe6bb9ac472375e2fbc/test --seed=0x9f3ac6b2 --cache-dir=/home/meghan/zig-cache --listen=- 
Build Summary: 1/3 steps succeeded; 1 failed; 0/1 tests passed; 1 failed
test transitive failure
└─ run test 0/1 passed, 1 failed
error: the following build command failed with exit code 1:
/home/meghan/zig-cache/o/a7826d30cced5fa524e6556d6f8a77dd/build /home/meghan/.local/share/zig/0.15.0-dev.482+2c241b263/zig /home/meghan/.local/share/zig/0.15.0-dev.482+2c241b263/lib $PWD /home/meghan/zig-cache /home/meghan/.cache/zig --seed 0x9f3ac6b2 -Zb314f2171d48cad5 test

Expected Behavior

$ zig-master test test.zig 
1/1 test.test_0...FAIL (C)
$PWD/test.zig:8:5: 0x1048a98 in foo (test)
    return switch (x) {
    ^
$PWD/test.zig:4:5: 0x1048b38 in test_0 (test)
    try foo(3);
    ^
0 passed; 0 skipped; 1 failed.
error: the following test command failed with exit code 1:
/home/meghan/zig-cache/o/3e4ab8e3c5a2f9cd281a60fdef8e6d07/test --seed=0xe5ed918a

in most zig code this can be easily worked around because the source location in the stack trace will include the specific line that says return error.Foo; etc but here that's also not the case

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions