zig
zig copied to clipboard
lld: link errors still allow `zig test` to succeed
Zig Version
0.10.0-dev.4472+a4eb221b9
Steps to Reproduce
echo > repro.zig
zig test repro.zig
echo $?
echo 'extern fn this_function_does_not_exist() void; test { this_function_does_not_exist(); }' > repro.zig
zig test repro.zig
echo $?
Expected Behavior
$ echo > repro.zig
$ zig test repro.zig
All 0 tests passed.
$ echo $?
0
$ echo 'extern fn this_function_does_not_exist() void; test { this_function_does_not_exist(); }' > repro.zig
$ zig test repro.zig
LLD Link... ld.lld: error: undefined symbol: this_function_does_not_exist
>>> referenced by repro.zig:1 (./repro.zig:1)
>>> /home/jacob/Source/zig/zig-cache/o/836f76c54df629e0f8e38b174388b09f/test.o:(repro.test_0)
$ echo $?
1
Actual Behavior
$ echo > repro.zig
$ zig test repro.zig
All 0 tests passed.
$ echo $?
0
$ echo 'extern fn this_function_does_not_exist() void; test { this_function_does_not_exist(); }' > repro.zig
$ zig test repro.zig
LLD Link... ld.lld: error: undefined symbol: this_function_does_not_exist
>>> referenced by repro.zig:1 (./repro.zig:1)
>>> /home/jacob/Source/zig/zig-cache/o/836f76c54df629e0f8e38b174388b09f/test.o:(repro.test_0)
All 0 tests passed.
$ echo $?
0
Code path of note: https://github.com/ziglang/zig/blob/a4eb221b9ef7dab8fa1c6cc07c7891e25d98d2b6/src/Compilation.zig#L2457
Workaround
Add std.process.exit(1)
to the above case.