diff options
| author | g-w1 <58830309+g-w1@users.noreply.github.com> | 2020-11-18 02:42:35 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-18 08:42:35 +0100 |
| commit | a0226ab05b50341622ace8314bdad3da7cd7e35d (patch) | |
| tree | f200ba0b5dd6aacde4428b13f19f5c6ab5743b45 /lib/std/fs | |
| parent | 238718b93abfe97bd5531103cf39714ec66fd86e (diff) | |
| download | zig-a0226ab05b50341622ace8314bdad3da7cd7e35d.tar.gz zig-a0226ab05b50341622ace8314bdad3da7cd7e35d.zip | |
std: openDirAbsolute and accessAbsolute (#7082)
* add more abosolutes
* added wrong files
* adding 2 tests and changing the function signatures because of lazy analysis not checking them
* fix a bug that got uncovered by lazy eval
* Add compile error when using WASI with openDirAbsolute and accessAbsolute
* typo
Diffstat (limited to 'lib/std/fs')
| -rw-r--r-- | lib/std/fs/test.zig | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index 8c24265db8..5469192f6c 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -49,6 +49,40 @@ fn testReadLink(dir: Dir, target_path: []const u8, symlink_path: []const u8) !vo testing.expect(mem.eql(u8, target_path, given)); } +test "accessAbsolute" { + if (builtin.os.tag == .wasi) return error.SkipZigTest; + + var tmp = tmpDir(.{}); + defer tmp.cleanup(); + + var arena = ArenaAllocator.init(testing.allocator); + defer arena.deinit(); + const base_path = blk: { + const relative_path = try fs.path.join(&arena.allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); + break :blk try fs.realpathAlloc(&arena.allocator, relative_path); + }; + + try fs.accessAbsolute(base_path, .{}); +} + +test "openDirAbsolute" { + if (builtin.os.tag == .wasi) return error.SkipZigTest; + + var tmp = tmpDir(.{}); + defer tmp.cleanup(); + + try tmp.dir.makeDir("subdir"); + var arena = ArenaAllocator.init(testing.allocator); + defer arena.deinit(); + const base_path = blk: { + const relative_path = try fs.path.join(&arena.allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..], "subdir" }); + break :blk try fs.realpathAlloc(&arena.allocator, relative_path); + }; + + var dir = try fs.openDirAbsolute(base_path, .{}); + defer dir.close(); +} + test "readLinkAbsolute" { if (builtin.os.tag == .wasi) return error.SkipZigTest; |
