2018-03-04 21:57:02 -08:00
|
|
|
const std = @import("../index.zig");
|
|
|
|
const os = std.os;
|
2018-04-03 21:08:10 -07:00
|
|
|
const assert = std.debug.assert;
|
2018-03-04 21:57:02 -08:00
|
|
|
const io = std.io;
|
|
|
|
|
|
|
|
const a = std.debug.global_allocator;
|
|
|
|
|
2018-04-03 21:08:10 -07:00
|
|
|
const builtin = @import("builtin");
|
|
|
|
|
2018-03-04 21:57:02 -08:00
|
|
|
test "makePath, put some files in it, deleteTree" {
|
2018-04-03 21:08:10 -07:00
|
|
|
if (builtin.os == builtin.Os.windows) {
|
|
|
|
// TODO implement os.Dir for windows
|
|
|
|
// https://github.com/zig-lang/zig/issues/709
|
|
|
|
return;
|
|
|
|
}
|
2018-03-04 21:57:02 -08:00
|
|
|
try os.makePath(a, "os_test_tmp/b/c");
|
|
|
|
try io.writeFile(a, "os_test_tmp/b/c/file.txt", "nonsense");
|
|
|
|
try io.writeFile(a, "os_test_tmp/b/file2.txt", "blah");
|
|
|
|
try os.deleteTree(a, "os_test_tmp");
|
2018-03-29 01:23:44 -07:00
|
|
|
if (os.Dir.open(a, "os_test_tmp")) |dir| {
|
2018-04-03 21:08:10 -07:00
|
|
|
@panic("expected error");
|
2018-03-29 01:23:44 -07:00
|
|
|
} else |err| {
|
2018-04-03 21:08:10 -07:00
|
|
|
assert(err == error.PathNotFound);
|
2018-03-29 01:23:44 -07:00
|
|
|
}
|
2018-03-04 21:57:02 -08:00
|
|
|
}
|
2018-04-13 02:27:09 -07:00
|
|
|
|
|
|
|
test "access file" {
|
|
|
|
if (builtin.os == builtin.Os.windows) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try os.makePath(a, "os_test_tmp");
|
|
|
|
if (os.File.access(a, "os_test_tmp/file.txt", os.default_file_mode)) |ok| {
|
|
|
|
unreachable;
|
|
|
|
} else |err| {
|
|
|
|
assert(err == error.NotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
try io.writeFile(a, "os_test_tmp/file.txt", "");
|
|
|
|
assert((try os.File.access(a, "os_test_tmp/file.txt", os.default_file_mode)) == true);
|
|
|
|
try os.deleteTree(a, "os_test_tmp");
|
|
|
|
}
|