zig icon indicating copy to clipboard operation
zig copied to clipboard

std: Add regression test for #18942

Open abhinav opened this issue 1 year ago • 5 comments

This change adds a regression test for the issue reported in #18942 and fixed by PR #18945.

This test fails to compile on 0.12.0-dev.2750+5f9255829 (where this bug is present). On versions where it compiles, it'll verify that bits for common flags convert from C to Zig correctly.

The test will only compile on platforms where tc_flag_t is defined, and has libc linked. These conditions are comptime-checked, skipping the test if not set.

abhinav avatar Feb 16 '24 04:02 abhinav

/home/ci/actions-runner2/_work/zig/zig/lib/std/c.zig:1313:17: error: C import failed
/home/ci/actions-runner2/_work/zig/zig/lib/std/c.zig:1313:17: note: libc headers not available; compilation does not link against libc
/home/ci/actions-runner2/_work/zig/zig/build-release/zig-local-cache/o/be0ccdf4bfd13410a6bf58086c7c80a0/cimport.h:1:10: error: 'termios.h' file not found

Okay, that answers that question. This worked on macOS, so I assumed it was allowed. Looks like these may be moved to test/.

abhinav avatar Feb 16 '24 13:02 abhinav

This test can only work if libc is linked, that's why windows and macos work - windows doesn't test anything and macos always links libc. You should probably write a guard checking for linking libc

der-teufel-programming avatar Feb 16 '24 13:02 der-teufel-programming

Okay, that should work on all targets now.

I've moved it closer to some other tests that also do a cInclude. For some reason, unlike the other behavior tests that cInclude, for this I needed to check for builtin.link_libc on Linux.

Verified that the test works on macOS and Linux, and that on Linux despite the link_libc check, there's at least one failure if I break the test:

(ubuntu):zig$ zig build test-behavior -Dtest-filter=tc_lflag_t -Dskip-release -Dskip-non-native
test-behavior
└─ run test behavior-aarch64-linux.4.19...6.5.7-musl-generic-Debug-libc 7/8 passed, 1 failed
error: 'test.tc_lflag_t' failed: could not convert IEXTEN
[..]/zig/lib/std/testing.zig:546:14: 0x104fde7 in expect (test)
    if (!ok) return error.TestUnexpectedResult;
             ^
[..]/zig/test/behavior/termios_compat.zig:20:5: 0x10506ff in lflag_test__anon_9449 (test)
    try std.testing.expect(https://github.com/field(got, field_name));
    ^
[..]/zig/test/behavior/termios_compat.zig:13:5: 0x10509f3 in test.tc_lflag_t (test)
    try lflag_test(c.tcflag_t, c.ICANON, "IEXTEN");

abhinav avatar Feb 16 '24 13:02 abhinav

This test can only work if libc is linked, that's why windows and macos work - windows doesn't test anything and macos always links libc. You should probably write a guard checking for linking libc

Thanks, that's helpful! I stumbled my way to that eventually. 😄

abhinav avatar Feb 16 '24 13:02 abhinav

Makes sense. Done.

abhinav avatar Feb 17 '24 16:02 abhinav