Commit 8d5acf7693

Jakub Konka <kubkon@jakubkonka.com>
2022-04-27 21:29:25
test: recursively walk dir with tests
Prune incremental tests by moving non-incremental behavior tests to behavior test suite instead.
1 parent c8a0d8f
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
test/incremental/issue_10138_callee_preserved_regs_working_x86_64_linux.zig → test/behavior/bugs/10138.zig
@@ -1,4 +1,11 @@
-pub fn main() void {
+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);
@@ -25,7 +32,3 @@ fn close(fd: usize) usize {
         unreachable;
     return 0;
 }
-
-// run
-// target=x86_64-linux
-//
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;
+}
test/incremental/hello_world_with_updates_x86_64_linux.0.zig → test/incremental/x86_64-linux/hello_world_with_updates.0.zig
File renamed without changes
test/incremental/hello_world_with_updates_x86_64_linux.1.zig → test/incremental/x86_64-linux/hello_world_with_updates.1.zig
File renamed without changes
test/incremental/hello_world_with_updates_x86_64_linux.2.zig → test/incremental/x86_64-linux/hello_world_with_updates.2.zig
File renamed without changes
test/incremental/hello_world_with_updates_x86_64_linux.3.zig → test/incremental/x86_64-linux/hello_world_with_updates.3.zig
File renamed without changes
test/incremental/hello_world_with_updates_x86_64_linux.4.zig → test/incremental/x86_64-linux/hello_world_with_updates.4.zig
File renamed without changes
test/incremental/hello_world_with_updates_x86_64_linux.5.zig → test/incremental/x86_64-linux/hello_world_with_updates.5.zig
File renamed without changes
test/incremental/inline_assembly_x86_64_linux.0.zig → test/incremental/x86_64-linux/inline_assembly.0.zig
File renamed without changes
test/incremental/inline_assembly_x86_64_linux.1.zig → test/incremental/x86_64-linux/inline_assembly.1.zig
File renamed without changes
test/incremental/inline_assembly_x86_64_linux.2.zig → test/incremental/x86_64-linux/inline_assembly.2.zig
File renamed without changes
test/incremental/inline_assembly_x86_64_linux.3.zig → test/incremental/x86_64-linux/inline_assembly.3.zig
File renamed without changes
test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.0.zig → test/incremental/x86_64-linux/only_1_function_and_it_gets_updated.0.zig
File renamed without changes
test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.1.zig → test/incremental/x86_64-linux/only_1_function_and_it_gets_updated.1.zig
File renamed without changes
test/incremental/hello_world_with_updates_x86_64_macos.0.zig → test/incremental/x86_64-macos/hello_world_with_updates.0.zig
File renamed without changes
test/incremental/hello_world_with_updates_x86_64_macos.1.zig → test/incremental/x86_64-macos/hello_world_with_updates.1.zig
File renamed without changes
test/incremental/hello_world_with_updates_x86_64_macos.2.zig → test/incremental/x86_64-macos/hello_world_with_updates.2.zig
File renamed without changes
test/incremental/hello_world_with_updates_x86_64_macos.3.zig → test/incremental/x86_64-macos/hello_world_with_updates.3.zig
File renamed without changes
test/incremental/hello_world_with_updates_x86_64_macos.4.zig → test/incremental/x86_64-macos/hello_world_with_updates.4.zig
File renamed without changes
test/incremental/hello_world_with_updates_x86_64_macos.5.zig → test/incremental/x86_64-macos/hello_world_with_updates.5.zig
File renamed without changes
test/incremental/hello_world_with_updates_x86_64_macos.6.zig → test/incremental/x86_64-macos/hello_world_with_updates.6.zig
File renamed without changes
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
-//
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
-//
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
-//
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
-//
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
-//
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
-//
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
-//
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
-//
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
-//
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
-//
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
-//
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");