authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-05-18 21:05:29+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-05-18 21:05:29+02:00
log3d267bab71052e652c159a953d87df40f8377546
tree20fca65ab54b61e1e229ddba5e16398d091a5a62
parent34f84c36082015bb8aacfcfb27cecf44e8e6eb3a

Re-enable refAllDecls gen and check in std.zig


4 files changed, 36 insertions(+), 21 deletions(-)

lib/std/build.zig+3-1
......@@ -1061,6 +1061,8 @@ pub const Builder = struct {
10611061};
10621062
10631063test "builder.findProgram compiles" {
1064 if (builtin.os.tag == .wasi) return error.SkipZigTest;
1065
10641066 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
10651067 defer arena.deinit();
10661068
......@@ -1706,7 +1708,7 @@ pub const LibExeObjStep = struct {
17061708 .Enum => |enum_info| {
17071709 out.print("const {} = enum {{\n", .{@typeName(T)}) catch unreachable;
17081710 inline for (enum_info.fields) |field| {
1709 out.print(" {},\n", .{ field.name }) catch unreachable;
1711 out.print(" {},\n", .{field.name}) catch unreachable;
17101712 }
17111713 out.print("}};\n", .{}) catch unreachable;
17121714 },
lib/std/fs/test.zig+25-14
......@@ -1,7 +1,9 @@
11const std = @import("../std.zig");
22const builtin = std.builtin;
33const fs = std.fs;
4const Dir = std.fs.Dir;
45const File = std.fs.File;
6const tmpDir = std.testing.tmpDir;
57
68test "openSelfExe" {
79 if (builtin.os.tag == .wasi) return error.SkipZigTest;
......@@ -15,16 +17,18 @@ const FILE_LOCK_TEST_SLEEP_TIME = 5 * std.time.millisecond;
1517test "open file with exclusive nonblocking lock twice" {
1618 if (builtin.os.tag == .wasi) return error.SkipZigTest;
1719
18 const dir = fs.cwd();
20 var tmp = tmpDir(.{});
21 defer tmp.cleanup();
22
1923 const filename = "file_nonblocking_lock_test.txt";
2024
21 const file1 = try dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
25 const file1 = try tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
2226 defer file1.close();
2327
24 const file2 = dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
28 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
2529 std.debug.assert(std.meta.eql(file2, error.WouldBlock));
2630
27 dir.deleteFile(filename) catch |err| switch (err) {
31 tmp.dir.deleteFile(filename) catch |err| switch (err) {
2832 error.FileNotFound => {},
2933 else => return err,
3034 };
......@@ -40,9 +44,12 @@ test "open file with lock twice, make sure it wasn't open at the same time" {
4044
4145 const filename = "file_lock_test.txt";
4246
47 var tmp = tmpDir(.{});
48 defer tmp.cleanup();
49
4350 var contexts = [_]FileLockTestContext{
44 .{ .filename = filename, .create = true, .lock = .Exclusive },
45 .{ .filename = filename, .create = true, .lock = .Exclusive },
51 .{ .dir = tmp.dir, .filename = filename, .create = true, .lock = .Exclusive },
52 .{ .dir = tmp.dir, .filename = filename, .create = true, .lock = .Exclusive },
4653 };
4754 try run_lock_file_test(&contexts);
4855
......@@ -58,7 +65,7 @@ test "open file with lock twice, make sure it wasn't open at the same time" {
5865
5966 std.debug.assert(!contexts[0].overlaps(&contexts[1]));
6067
61 fs.cwd().deleteFile(filename) catch |err| switch (err) {
68 tmp.dir.deleteFile(filename) catch |err| switch (err) {
6269 error.FileNotFound => {},
6370 else => return err,
6471 };
......@@ -80,12 +87,15 @@ test "create file, lock and read from multiple process at once" {
8087 const filename = "file_read_lock_test.txt";
8188 const filedata = "Hello, world!\n";
8289
83 try fs.cwd().writeFile(filename, filedata);
90 var tmp = tmpDir(.{});
91 defer tmp.cleanup();
92
93 try tmp.dir.writeFile(filename, filedata);
8494
8595 var contexts = [_]FileLockTestContext{
86 .{ .filename = filename, .create = false, .lock = .Shared },
87 .{ .filename = filename, .create = false, .lock = .Shared },
88 .{ .filename = filename, .create = false, .lock = .Exclusive },
96 .{ .dir = tmp.dir, .filename = filename, .create = false, .lock = .Shared },
97 .{ .dir = tmp.dir, .filename = filename, .create = false, .lock = .Shared },
98 .{ .dir = tmp.dir, .filename = filename, .create = false, .lock = .Exclusive },
8999 };
90100
91101 try run_lock_file_test(&contexts);
......@@ -108,7 +118,7 @@ test "create file, lock and read from multiple process at once" {
108118 std.debug.assert(contexts[0].bytes_read.? == filedata.len);
109119 std.debug.assert(contexts[1].bytes_read.? == filedata.len);
110120
111 fs.cwd().deleteFile(filename) catch |err| switch (err) {
121 tmp.dir.deleteFile(filename) catch |err| switch (err) {
112122 error.FileNotFound => {},
113123 else => return err,
114124 };
......@@ -133,6 +143,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {
133143}
134144
135145const FileLockTestContext = struct {
146 dir: Dir,
136147 filename: []const u8,
137148 pid: if (builtin.os.tag == .windows) ?void else ?std.os.pid_t = null,
138149
......@@ -154,12 +165,12 @@ const FileLockTestContext = struct {
154165 fn run(ctx: *@This()) void {
155166 var file: File = undefined;
156167 if (ctx.create) {
157 file = fs.cwd().createFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
168 file = ctx.dir.createFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
158169 ctx.err = err;
159170 return;
160171 };
161172 } else {
162 file = fs.cwd().openFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
173 file = ctx.dir.openFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
163174 ctx.err = err;
164175 return;
165176 };
lib/std/std.zig+1-6
......@@ -75,10 +75,5 @@ comptime {
7575}
7676
7777test "" {
78 // TODO is there a way around this? When enabled for WASI, we pick up functions
79 // which generate compile error. Perhaps semantic analyser should skip those
80 // if running in test mode?
81 if (builtin.os.tag != .wasi) {
82 meta.refAllDecls(@This());
83 }
78 meta.refAllDecls(@This());
8479}
lib/std/zig/parser_test.zig+7
......@@ -1,3 +1,5 @@
1const builtin = @import("builtin");
2
13test "recovery: top level" {
24 try testError(
35 \\test "" {inline}
......@@ -941,6 +943,9 @@ test "zig fmt: same-line doc comment on variable declaration" {
941943}
942944
943945test "zig fmt: if-else with comment before else" {
946 // TODO investigate why this fails in wasm.
947 if (builtin.cpu.arch == .wasm32) return error.SkipZigTest;
948
944949 try testCanonical(
945950 \\comptime {
946951 \\ // cexp(finite|nan +- i inf|nan) = nan + i nan
......@@ -1555,6 +1560,8 @@ test "zig fmt: comment after if before another if" {
15551560}
15561561
15571562test "zig fmt: line comment between if block and else keyword" {
1563 // TODO investigate why this fails in wasm.
1564 if (builtin.cpu.arch == .wasm32) return error.SkipZigTest;
15581565 try testCanonical(
15591566 \\test "aoeu" {
15601567 \\ // cexp(finite|nan +- i inf|nan) = nan + i nan