authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-05-18 22:22:27+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-05-18 22:22:27+02:00
logcd8daa533ad7e53a3d071dcb782bc14c6fc72711
tree6ddb2c9ce9914d88cae3883c45356d2ef1071873
parent57719006bbae3d003f442864339ad7d30a8e05cc

Undo accidentally checked-in changes to fs/test.zig


1 files changed, 14 insertions(+), 26 deletions(-)

lib/std/fs/test.zig+14-26
......@@ -1,9 +1,7 @@
11const std = @import("../std.zig");
22const builtin = std.builtin;
33const fs = std.fs;
4const Dir = std.fs.Dir;
54const File = std.fs.File;
6const tmpDir = std.testing.tmpDir;
75
86test "openSelfExe" {
97 if (builtin.os.tag == .wasi) return error.SkipZigTest;
......@@ -17,18 +15,16 @@ const FILE_LOCK_TEST_SLEEP_TIME = 5 * std.time.millisecond;
1715test "open file with exclusive nonblocking lock twice" {
1816 if (builtin.os.tag == .wasi) return error.SkipZigTest;
1917
20 var tmp = tmpDir(.{});
21 defer tmp.cleanup();
22
18 const dir = fs.cwd();
2319 const filename = "file_nonblocking_lock_test.txt";
2420
25 const file1 = try tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
21 const file1 = try dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
2622 defer file1.close();
2723
28 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
24 const file2 = dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
2925 std.debug.assert(std.meta.eql(file2, error.WouldBlock));
3026
31 tmp.dir.deleteFile(filename) catch |err| switch (err) {
27 dir.deleteFile(filename) catch |err| switch (err) {
3228 error.FileNotFound => {},
3329 else => return err,
3430 };
......@@ -43,13 +39,9 @@ test "open file with lock twice, make sure it wasn't open at the same time" {
4339 }
4440
4541 const filename = "file_lock_test.txt";
46
47 var tmp = tmpDir(.{});
48 defer tmp.cleanup();
49
5042 var contexts = [_]FileLockTestContext{
51 .{ .dir = tmp.dir, .filename = filename, .create = true, .lock = .Exclusive },
52 .{ .dir = tmp.dir, .filename = filename, .create = true, .lock = .Exclusive },
43 .{ .filename = filename, .create = true, .lock = .Exclusive },
44 .{ .filename = filename, .create = true, .lock = .Exclusive },
5345 };
5446 try run_lock_file_test(&contexts);
5547
......@@ -65,7 +57,7 @@ test "open file with lock twice, make sure it wasn't open at the same time" {
6557
6658 std.debug.assert(!contexts[0].overlaps(&contexts[1]));
6759
68 tmp.dir.deleteFile(filename) catch |err| switch (err) {
60 fs.cwd().deleteFile(filename) catch |err| switch (err) {
6961 error.FileNotFound => {},
7062 else => return err,
7163 };
......@@ -87,15 +79,12 @@ test "create file, lock and read from multiple process at once" {
8779 const filename = "file_read_lock_test.txt";
8880 const filedata = "Hello, world!\n";
8981
90 var tmp = tmpDir(.{});
91 defer tmp.cleanup();
92
93 try tmp.dir.writeFile(filename, filedata);
82 try fs.cwd().writeFile(filename, filedata);
9483
9584 var contexts = [_]FileLockTestContext{
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 },
85 .{ .filename = filename, .create = false, .lock = .Shared },
86 .{ .filename = filename, .create = false, .lock = .Shared },
87 .{ .filename = filename, .create = false, .lock = .Exclusive },
9988 };
10089
10190 try run_lock_file_test(&contexts);
......@@ -118,7 +107,7 @@ test "create file, lock and read from multiple process at once" {
118107 std.debug.assert(contexts[0].bytes_read.? == filedata.len);
119108 std.debug.assert(contexts[1].bytes_read.? == filedata.len);
120109
121 tmp.dir.deleteFile(filename) catch |err| switch (err) {
110 fs.cwd().deleteFile(filename) catch |err| switch (err) {
122111 error.FileNotFound => {},
123112 else => return err,
124113 };
......@@ -143,7 +132,6 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {
143132}
144133
145134const FileLockTestContext = struct {
146 dir: Dir,
147135 filename: []const u8,
148136 pid: if (builtin.os.tag == .windows) ?void else ?std.os.pid_t = null,
149137
......@@ -165,12 +153,12 @@ const FileLockTestContext = struct {
165153 fn run(ctx: *@This()) void {
166154 var file: File = undefined;
167155 if (ctx.create) {
168 file = ctx.dir.createFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
156 file = fs.cwd().createFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
169157 ctx.err = err;
170158 return;
171159 };
172160 } else {
173 file = ctx.dir.openFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
161 file = fs.cwd().openFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
174162 ctx.err = err;
175163 return;
176164 };