Commit 3d267bab71

Jakub Konka <kubkon@jakubkonka.com>
2020-05-18 21:05:29
Re-enable refAllDecls gen and check in std.zig
1 parent 34f84c3
Changed files (4)
lib/std/fs/test.zig
@@ -1,7 +1,9 @@
 const std = @import("../std.zig");
 const builtin = std.builtin;
 const fs = std.fs;
+const Dir = std.fs.Dir;
 const File = std.fs.File;
+const tmpDir = std.testing.tmpDir;
 
 test "openSelfExe" {
     if (builtin.os.tag == .wasi) return error.SkipZigTest;
@@ -15,16 +17,18 @@ const FILE_LOCK_TEST_SLEEP_TIME = 5 * std.time.millisecond;
 test "open file with exclusive nonblocking lock twice" {
     if (builtin.os.tag == .wasi) return error.SkipZigTest;
 
-    const dir = fs.cwd();
+    var tmp = tmpDir(.{});
+    defer tmp.cleanup();
+
     const filename = "file_nonblocking_lock_test.txt";
 
-    const file1 = try dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
+    const file1 = try tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
     defer file1.close();
 
-    const file2 = dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
+    const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
     std.debug.assert(std.meta.eql(file2, error.WouldBlock));
 
-    dir.deleteFile(filename) catch |err| switch (err) {
+    tmp.dir.deleteFile(filename) catch |err| switch (err) {
         error.FileNotFound => {},
         else => return err,
     };
@@ -40,9 +44,12 @@ test "open file with lock twice, make sure it wasn't open at the same time" {
 
     const filename = "file_lock_test.txt";
 
+    var tmp = tmpDir(.{});
+    defer tmp.cleanup();
+
     var contexts = [_]FileLockTestContext{
-        .{ .filename = filename, .create = true, .lock = .Exclusive },
-        .{ .filename = filename, .create = true, .lock = .Exclusive },
+        .{ .dir = tmp.dir, .filename = filename, .create = true, .lock = .Exclusive },
+        .{ .dir = tmp.dir, .filename = filename, .create = true, .lock = .Exclusive },
     };
     try run_lock_file_test(&contexts);
 
@@ -58,7 +65,7 @@ test "open file with lock twice, make sure it wasn't open at the same time" {
 
     std.debug.assert(!contexts[0].overlaps(&contexts[1]));
 
-    fs.cwd().deleteFile(filename) catch |err| switch (err) {
+    tmp.dir.deleteFile(filename) catch |err| switch (err) {
         error.FileNotFound => {},
         else => return err,
     };
@@ -80,12 +87,15 @@ test "create file, lock and read from multiple process at once" {
     const filename = "file_read_lock_test.txt";
     const filedata = "Hello, world!\n";
 
-    try fs.cwd().writeFile(filename, filedata);
+    var tmp = tmpDir(.{});
+    defer tmp.cleanup();
+
+    try tmp.dir.writeFile(filename, filedata);
 
     var contexts = [_]FileLockTestContext{
-        .{ .filename = filename, .create = false, .lock = .Shared },
-        .{ .filename = filename, .create = false, .lock = .Shared },
-        .{ .filename = filename, .create = false, .lock = .Exclusive },
+        .{ .dir = tmp.dir, .filename = filename, .create = false, .lock = .Shared },
+        .{ .dir = tmp.dir, .filename = filename, .create = false, .lock = .Shared },
+        .{ .dir = tmp.dir, .filename = filename, .create = false, .lock = .Exclusive },
     };
 
     try run_lock_file_test(&contexts);
@@ -108,7 +118,7 @@ test "create file, lock and read from multiple process at once" {
     std.debug.assert(contexts[0].bytes_read.? == filedata.len);
     std.debug.assert(contexts[1].bytes_read.? == filedata.len);
 
-    fs.cwd().deleteFile(filename) catch |err| switch (err) {
+    tmp.dir.deleteFile(filename) catch |err| switch (err) {
         error.FileNotFound => {},
         else => return err,
     };
@@ -133,6 +143,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {
 }
 
 const FileLockTestContext = struct {
+    dir: Dir,
     filename: []const u8,
     pid: if (builtin.os.tag == .windows) ?void else ?std.os.pid_t = null,
 
@@ -154,12 +165,12 @@ const FileLockTestContext = struct {
     fn run(ctx: *@This()) void {
         var file: File = undefined;
         if (ctx.create) {
-            file = fs.cwd().createFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
+            file = ctx.dir.createFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
                 ctx.err = err;
                 return;
             };
         } else {
-            file = fs.cwd().openFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
+            file = ctx.dir.openFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
                 ctx.err = err;
                 return;
             };
lib/std/zig/parser_test.zig
@@ -1,3 +1,5 @@
+const builtin = @import("builtin");
+
 test "recovery: top level" {
     try testError(
         \\test "" {inline}
@@ -941,6 +943,9 @@ test "zig fmt: same-line doc comment on variable declaration" {
 }
 
 test "zig fmt: if-else with comment before else" {
+    // TODO investigate why this fails in wasm.
+    if (builtin.cpu.arch == .wasm32) return error.SkipZigTest;
+
     try testCanonical(
         \\comptime {
         \\    // cexp(finite|nan +- i inf|nan) = nan + i nan
@@ -1555,6 +1560,8 @@ test "zig fmt: comment after if before another if" {
 }
 
 test "zig fmt: line comment between if block and else keyword" {
+    // TODO investigate why this fails in wasm.
+    if (builtin.cpu.arch == .wasm32) return error.SkipZigTest;
     try testCanonical(
         \\test "aoeu" {
         \\    // cexp(finite|nan +- i inf|nan) = nan + i nan
lib/std/build.zig
@@ -1061,6 +1061,8 @@ pub const Builder = struct {
 };
 
 test "builder.findProgram compiles" {
+    if (builtin.os.tag == .wasi) return error.SkipZigTest;
+
     var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
     defer arena.deinit();
 
@@ -1706,7 +1708,7 @@ pub const LibExeObjStep = struct {
             .Enum => |enum_info| {
                 out.print("const {} = enum {{\n", .{@typeName(T)}) catch unreachable;
                 inline for (enum_info.fields) |field| {
-                    out.print("    {},\n", .{ field.name }) catch unreachable;
+                    out.print("    {},\n", .{field.name}) catch unreachable;
                 }
                 out.print("}};\n", .{}) catch unreachable;
             },
lib/std/std.zig
@@ -75,10 +75,5 @@ comptime {
 }
 
 test "" {
-    // TODO is there a way around this? When enabled for WASI, we pick up functions
-    // which generate compile error. Perhaps semantic analyser should skip those
-    // if running in test mode?
-    if (builtin.os.tag != .wasi) {
-        meta.refAllDecls(@This());
-    }
+    meta.refAllDecls(@This());
 }