commit 8d5acf769336051a18c4905b4fc258349092b36e (tree) parent c8a0d8ff2b8557e3e7c3956a37293a0ce06dd3d0 Author: Jakub Konka <kubkon@jakubkonka.com> Date: Wed, 27 Apr 2022 21:29:25 +0200 test: recursively walk dir with tests Prune incremental tests by moving non-incremental behavior tests to behavior test suite instead. Diffstat:
35 files changed, 57 insertions(+), 196 deletions(-)
diff --git a/src/test.zig b/src/test.zig @@ -1012,18 +1012,18 @@ pub const TestContext = struct { ) !void { var cases = std.ArrayList(usize).init(ctx.arena); - var it = dir.iterate(); + var it = try dir.walk(ctx.arena); var filenames = std.ArrayList([]const u8).init(ctx.arena); while (try it.next()) |entry| { if (entry.kind != .File) continue; // Ignore stuff such as .swp files - switch (Compilation.classifyFileExt(entry.name)) { + switch (Compilation.classifyFileExt(entry.basename)) { .unknown => continue, else => {}, } - try filenames.append(try ctx.arena.dupe(u8, entry.name)); + try filenames.append(try ctx.arena.dupe(u8, entry.path)); } // Sort filenames, so that incremental tests are contiguous and in-order diff --git a/test/behavior.zig b/test/behavior.zig @@ -69,8 +69,10 @@ test { _ = @import("behavior/bugs/7003.zig"); _ = @import("behavior/bugs/7027.zig"); _ = @import("behavior/bugs/7047.zig"); + _ = @import("behavior/bugs/7187.zig"); _ = @import("behavior/bugs/7250.zig"); _ = @import("behavior/bugs/9584.zig"); + _ = @import("behavior/bugs/10138.zig"); _ = @import("behavior/bugs/10147.zig"); _ = @import("behavior/bugs/10970.zig"); _ = @import("behavior/bugs/11046.zig"); diff --git a/test/behavior/bugs/10138.zig b/test/behavior/bugs/10138.zig @@ -0,0 +1,34 @@ +const std = @import("std"); +const builtin = @import("builtin"); + +test "registers get overwritten when ignoring return" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.cpu.arch != .x86_64 or builtin.os.tag != .linux) return error.SkipZigTest; + + const fd = open(); + _ = write(fd, "a", 1); + _ = close(fd); +} + +fn open() usize { + return 42; +} + +fn write(fd: usize, a: [*]const u8, len: usize) usize { + return syscall4(.WRITE, fd, @ptrToInt(a), len); +} + +fn syscall4(n: enum { WRITE }, a: usize, b: usize, c: usize) usize { + _ = n; + _ = a; + _ = b; + _ = c; + return 23; +} + +fn close(fd: usize) usize { + if (fd != 42) + unreachable; + return 0; +} diff --git a/test/behavior/bugs/7187.zig b/test/behavior/bugs/7187.zig @@ -0,0 +1,18 @@ +const std = @import("std"); +const builtin = @import("builtin"); +const expect = std.testing.expect; + +test "miscompilation with bool return type" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + + var x: usize = 1; + var y: bool = getFalse(); + _ = y; + + try expect(x == 1); +} + +fn getFalse() bool { + return false; +} diff --git a/test/incremental/access_slice_element_by_index_slice_elem_val.zig b/test/incremental/access_slice_element_by_index_slice_elem_val.zig @@ -1,17 +0,0 @@ -var array = [_]usize{ 0, 42, 123, 34 }; -var slice: []const usize = &array; - -pub fn main() void { - assert(slice[0] == 0); - assert(slice[1] == 42); - assert(slice[2] == 123); - assert(slice[3] == 34); -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// target=x86_64-linux,x86_64-macos -// diff --git a/test/incremental/issue_10138_callee_preserved_regs_working_x86_64_linux.zig b/test/incremental/issue_10138_callee_preserved_regs_working_x86_64_linux.zig @@ -1,31 +0,0 @@ -pub fn main() void { - const fd = open(); - _ = write(fd, "a", 1); - _ = close(fd); -} - -fn open() usize { - return 42; -} - -fn write(fd: usize, a: [*]const u8, len: usize) usize { - return syscall4(.WRITE, fd, @ptrToInt(a), len); -} - -fn syscall4(n: enum { WRITE }, a: usize, b: usize, c: usize) usize { - _ = n; - _ = a; - _ = b; - _ = c; - return 23; -} - -fn close(fd: usize) usize { - if (fd != 42) - unreachable; - return 0; -} - -// run -// target=x86_64-linux -// diff --git a/test/incremental/issue_7187_miscompilation_with_bool_return_type.zig b/test/incremental/issue_7187_miscompilation_with_bool_return_type.zig @@ -1,18 +0,0 @@ -pub fn main() void { - var x: usize = 1; - var y: bool = getFalse(); - _ = y; - - assert(x == 1); -} - -fn getFalse() bool { - return false; -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// diff --git a/test/incremental/load_store_via_pointer_deref.0.zig b/test/incremental/load_store_via_pointer_deref.0.zig @@ -1,16 +0,0 @@ -pub fn main() void { - var x: u32 = undefined; - set(&x); - assert(x == 123); -} - -fn set(x: *u32) void { - x.* = 123; -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// diff --git a/test/incremental/load_store_via_pointer_deref.1.zig b/test/incremental/load_store_via_pointer_deref.1.zig @@ -1,16 +0,0 @@ -pub fn main() void { - var x: u16 = undefined; - set(&x); - assert(x == 123); -} - -fn set(x: *u16) void { - x.* = 123; -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// diff --git a/test/incremental/load_store_via_pointer_deref.2.zig b/test/incremental/load_store_via_pointer_deref.2.zig @@ -1,16 +0,0 @@ -pub fn main() void { - var x: u8 = undefined; - set(&x); - assert(x == 123); -} - -fn set(x: *u8) void { - x.* = 123; -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// diff --git a/test/incremental/saving_vars_of_different_abi_size_to_stack.0.zig b/test/incremental/saving_vars_of_different_abi_size_to_stack.0.zig @@ -1,16 +0,0 @@ -pub fn main() void { - assert(callMe(2) == 24); -} - -fn callMe(a: u8) u8 { - var b: u8 = a + 10; - const c = 2 * b; - return c; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/incremental/saving_vars_of_different_abi_size_to_stack.1.zig b/test/incremental/saving_vars_of_different_abi_size_to_stack.1.zig @@ -1,16 +0,0 @@ -pub fn main() void { - assert(callMe(2) == 24); -} - -fn callMe(a: u16) u16 { - var b: u16 = a + 10; - const c = 2 * b; - return c; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/incremental/saving_vars_of_different_abi_size_to_stack.2.zig b/test/incremental/saving_vars_of_different_abi_size_to_stack.2.zig @@ -1,16 +0,0 @@ -pub fn main() void { - assert(callMe(2) == 24); -} - -fn callMe(a: u32) u32 { - var b: u32 = a + 10; - const c = 2 * b; - return c; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/incremental/subtracting_numbers_at_runtime.zig b/test/incremental/subtracting_numbers_at_runtime.zig @@ -1,10 +0,0 @@ -pub fn main() void { - sub(7, 4); -} - -fn sub(a: u32, b: u32) void { - if (a - b != 3) unreachable; -} - -// run -// diff --git a/test/incremental/unwrap_error_union_simple_errors.0.zig b/test/incremental/unwrap_error_union_simple_errors.0.zig @@ -1,10 +0,0 @@ -pub fn main() void { - maybeErr() catch unreachable; -} - -fn maybeErr() !void { - return; -} - -// run -// diff --git a/test/incremental/unwrap_error_union_simple_errors.1.zig b/test/incremental/unwrap_error_union_simple_errors.1.zig @@ -1,11 +0,0 @@ -pub fn main() void { - maybeErr() catch return; - unreachable; -} - -fn maybeErr() !void { - return error.NoWay; -} - -// run -// diff --git a/test/incremental/hello_world_with_updates_x86_64_linux.0.zig b/test/incremental/x86_64-linux/hello_world_with_updates.0.zig diff --git a/test/incremental/hello_world_with_updates_x86_64_linux.1.zig b/test/incremental/x86_64-linux/hello_world_with_updates.1.zig diff --git a/test/incremental/hello_world_with_updates_x86_64_linux.2.zig b/test/incremental/x86_64-linux/hello_world_with_updates.2.zig diff --git a/test/incremental/hello_world_with_updates_x86_64_linux.3.zig b/test/incremental/x86_64-linux/hello_world_with_updates.3.zig diff --git a/test/incremental/hello_world_with_updates_x86_64_linux.4.zig b/test/incremental/x86_64-linux/hello_world_with_updates.4.zig diff --git a/test/incremental/hello_world_with_updates_x86_64_linux.5.zig b/test/incremental/x86_64-linux/hello_world_with_updates.5.zig diff --git a/test/incremental/inline_assembly_x86_64_linux.0.zig b/test/incremental/x86_64-linux/inline_assembly.0.zig diff --git a/test/incremental/inline_assembly_x86_64_linux.1.zig b/test/incremental/x86_64-linux/inline_assembly.1.zig diff --git a/test/incremental/inline_assembly_x86_64_linux.2.zig b/test/incremental/x86_64-linux/inline_assembly.2.zig diff --git a/test/incremental/inline_assembly_x86_64_linux.3.zig b/test/incremental/x86_64-linux/inline_assembly.3.zig diff --git a/test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.0.zig b/test/incremental/x86_64-linux/only_1_function_and_it_gets_updated.0.zig diff --git a/test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.1.zig b/test/incremental/x86_64-linux/only_1_function_and_it_gets_updated.1.zig diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.0.zig b/test/incremental/x86_64-macos/hello_world_with_updates.0.zig diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.1.zig b/test/incremental/x86_64-macos/hello_world_with_updates.1.zig diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.2.zig b/test/incremental/x86_64-macos/hello_world_with_updates.2.zig diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.3.zig b/test/incremental/x86_64-macos/hello_world_with_updates.3.zig diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.4.zig b/test/incremental/x86_64-macos/hello_world_with_updates.4.zig diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.5.zig b/test/incremental/x86_64-macos/hello_world_with_updates.5.zig diff --git a/test/incremental/hello_world_with_updates_x86_64_macos.6.zig b/test/incremental/x86_64-macos/hello_world_with_updates.6.zig