From 8caa20641787944651f7c6fe2f664e93c55d79ec Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 14 Jun 2022 15:27:43 -0700 Subject: [PATCH] test-cases: fix race with `zig run` on C backend tests Also avoid redundantly doing compile-error checks on multiple targets for test cases where that is not helpful. --- src/test.zig | 7 ++++++- test/cases/compile_errors/dereference_anyopaque.zig | 1 + test/cases/compile_errors/invalid_array_elem_ty.zig | 3 ++- .../compile_errors/invalid_store_to_comptime_field.zig | 3 ++- .../compile_errors/runtime_indexing_comptime_array.zig | 3 ++- test/cases/compile_errors/stage2/comptime_unreachable.zig | 2 ++ 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/test.zig b/src/test.zig index f8b8ed8ce800c00a8c792ea0c34e231a40512e50..414a9d4d82086e07f63f52c81c438b2faaa08209 100644 --- a/src/test.zig +++ b/src/test.zig @@ -1808,6 +1808,11 @@ pub const TestContext = struct { // We wouldn't be able to run the compiled C code. return; // Pass test. } + // Use an absolute path here so that the unique directory name + // for this Case makes it into the cache hash, avoiding cache + // collisions from multiple threads doing `zig run` at the same + // time on the same test_case.c input filename. + const abs_exe_path = try tmp.dir.realpathAlloc(arena, bin_name); try argv.appendSlice(&[_][]const u8{ std.testing.zig_exe_path, "run", @@ -1818,7 +1823,7 @@ pub const TestContext = struct { "-Wno-incompatible-library-redeclaration", // https://github.com/ziglang/zig/issues/875 "--", "-lc", - exe_path, + abs_exe_path, }); } else switch (host.getExternalExecutor(target_info, .{ .link_libc = case.link_libc })) { .native => try argv.append(exe_path), diff --git a/test/cases/compile_errors/dereference_anyopaque.zig b/test/cases/compile_errors/dereference_anyopaque.zig index 68be3c97ed010337d4fc58f2ddacad5b03601646..e09f08601650780aa06ac5b8792da54dcd535b7b 100644 --- a/test/cases/compile_errors/dereference_anyopaque.zig +++ b/test/cases/compile_errors/dereference_anyopaque.zig @@ -41,6 +41,7 @@ pub export fn entry() void { } // error +// target=native // backend=llvm // // :11:22: error: comparison of 'void' with null diff --git a/test/cases/compile_errors/invalid_array_elem_ty.zig b/test/cases/compile_errors/invalid_array_elem_ty.zig index bfa79a104bfff6251900118e5d4159d02fcb4c13..c7c259724644ac4132cfbc06ef2529ddfd386f4b 100644 --- a/test/cases/compile_errors/invalid_array_elem_ty.zig +++ b/test/cases/compile_errors/invalid_array_elem_ty.zig @@ -6,6 +6,7 @@ pub export fn entry() void { } // error -// backend=stage2,llvm +// target=native +// backend=stage2 // // :4:1: error: expected type, found fn() type diff --git a/test/cases/compile_errors/invalid_store_to_comptime_field.zig b/test/cases/compile_errors/invalid_store_to_comptime_field.zig index 3bbd9bbaa85b7ba51624b0d949177181589e6b27..48743f3ba15818cb7270600e284638ca6fc6ffb3 100644 --- a/test/cases/compile_errors/invalid_store_to_comptime_field.zig +++ b/test/cases/compile_errors/invalid_store_to_comptime_field.zig @@ -14,7 +14,8 @@ pub export fn entry1() void { s.a = T{ .a = 2, .b = 2 }; } // error -// backend=stage2,llvm +// target=native +// backend=stage2 // // :6:19: error: value stored in comptime field does not match the default value of the field // :14:19: error: value stored in comptime field does not match the default value of the field diff --git a/test/cases/compile_errors/runtime_indexing_comptime_array.zig b/test/cases/compile_errors/runtime_indexing_comptime_array.zig index 3acd0feb61baa34ad5d12f309ceef3aeb101f087..16f7305f631ddce876c8896b4493fa4e817dad0b 100644 --- a/test/cases/compile_errors/runtime_indexing_comptime_array.zig +++ b/test/cases/compile_errors/runtime_indexing_comptime_array.zig @@ -21,7 +21,8 @@ pub export fn entry3() void { _ = &test_fns[i]; } // error -// backend=stage2,llvm +// target=native +// backend=stage2 // // :6:5: error: values of type '[2]fn() void' must be comptime known, but index value is runtime known // :6:5: note: use '*const fn() void' for a function pointer type diff --git a/test/cases/compile_errors/stage2/comptime_unreachable.zig b/test/cases/compile_errors/stage2/comptime_unreachable.zig index 6086dd85c6033d35f73e8d9d8e26c0a70844f82c..74b35165854f2bfa0bb9552b67da998ef0251b39 100644 --- a/test/cases/compile_errors/stage2/comptime_unreachable.zig +++ b/test/cases/compile_errors/stage2/comptime_unreachable.zig @@ -3,5 +3,7 @@ pub export fn entry() void { } // error +// target=native +// backend=stage2 // // :2:14: error: reached unreachable code -- 2.54.0