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

This commit is contained in:
Jakub Konka 2020-05-18 22:22:27 +02:00
parent 57719006bb
commit cd8daa533a

View File

@ -1,9 +1,7 @@
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;
@ -17,18 +15,16 @@ 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;
var tmp = tmpDir(.{});
defer tmp.cleanup();
const dir = fs.cwd();
const filename = "file_nonblocking_lock_test.txt";
const file1 = try tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
const file1 = try dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
defer file1.close();
const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
const file2 = dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
std.debug.assert(std.meta.eql(file2, error.WouldBlock));
tmp.dir.deleteFile(filename) catch |err| switch (err) {
dir.deleteFile(filename) catch |err| switch (err) {
error.FileNotFound => {},
else => return err,
};
@ -43,13 +39,9 @@ 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{
.{ .dir = tmp.dir, .filename = filename, .create = true, .lock = .Exclusive },
.{ .dir = tmp.dir, .filename = filename, .create = true, .lock = .Exclusive },
.{ .filename = filename, .create = true, .lock = .Exclusive },
.{ .filename = filename, .create = true, .lock = .Exclusive },
};
try run_lock_file_test(&contexts);
@ -65,7 +57,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]));
tmp.dir.deleteFile(filename) catch |err| switch (err) {
fs.cwd().deleteFile(filename) catch |err| switch (err) {
error.FileNotFound => {},
else => return err,
};
@ -87,15 +79,12 @@ test "create file, lock and read from multiple process at once" {
const filename = "file_read_lock_test.txt";
const filedata = "Hello, world!\n";
var tmp = tmpDir(.{});
defer tmp.cleanup();
try tmp.dir.writeFile(filename, filedata);
try fs.cwd().writeFile(filename, filedata);
var contexts = [_]FileLockTestContext{
.{ .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 },
.{ .filename = filename, .create = false, .lock = .Shared },
.{ .filename = filename, .create = false, .lock = .Shared },
.{ .filename = filename, .create = false, .lock = .Exclusive },
};
try run_lock_file_test(&contexts);
@ -118,7 +107,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);
tmp.dir.deleteFile(filename) catch |err| switch (err) {
fs.cwd().deleteFile(filename) catch |err| switch (err) {
error.FileNotFound => {},
else => return err,
};
@ -143,7 +132,6 @@ 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,
@ -165,12 +153,12 @@ const FileLockTestContext = struct {
fn run(ctx: *@This()) void {
var file: File = undefined;
if (ctx.create) {
file = ctx.dir.createFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
file = fs.cwd().createFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
ctx.err = err;
return;
};
} else {
file = ctx.dir.openFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
file = fs.cwd().openFile(ctx.filename, .{ .lock = ctx.lock }) catch |err| {
ctx.err = err;
return;
};