| ... | @@ -17,6 +17,9 @@ const AtomicOrder = std.builtin.AtomicOrder; | ... | @@ -17,6 +17,9 @@ const AtomicOrder = std.builtin.AtomicOrder; |
| 17 | const native_os = builtin.target.os.tag; | 17 | const native_os = builtin.target.os.tag; |
| 18 | const tmpDir = std.testing.tmpDir; | 18 | const tmpDir = std.testing.tmpDir; |
| 19 | | 19 | |
| | 20 | // NOTE: several additional tests are in test/standalone/posix/. Any tests that mutate |
| | 21 | // process-wide POSIX state (cwd, signals, etc) cannot be Zig unit tests and should be over there. |
| | 22 | |
| 20 | // https://github.com/ziglang/zig/issues/20288 | 23 | // https://github.com/ziglang/zig/issues/20288 |
| 21 | test "WTF-8 to WTF-16 conversion buffer overflows" { | 24 | test "WTF-8 to WTF-16 conversion buffer overflows" { |
| 22 | if (native_os != .windows) return error.SkipZigTest; | 25 | if (native_os != .windows) return error.SkipZigTest; |
| ... | @@ -39,68 +42,6 @@ test "check WASI CWD" { | ... | @@ -39,68 +42,6 @@ test "check WASI CWD" { |
| 39 | } | 42 | } |
| 40 | } | 43 | } |
| 41 | | 44 | |
| 42 | test "chdir absolute parent" { | | |
| 43 | if (native_os == .wasi) return error.SkipZigTest; | | |
| 44 | | | |
| 45 | // Restore default CWD at end of test. | | |
| 46 | const orig_cwd = try fs.cwd().openDir(".", .{}); | | |
| 47 | defer orig_cwd.setAsCwd() catch unreachable; | | |
| 48 | | | |
| 49 | // Get current working directory path | | |
| 50 | var old_cwd_buf: [fs.max_path_bytes]u8 = undefined; | | |
| 51 | const old_cwd = try posix.getcwd(old_cwd_buf[0..]); | | |
| 52 | | | |
| 53 | { | | |
| 54 | // Firstly, changing to itself should have no effect | | |
| 55 | try posix.chdir(old_cwd); | | |
| 56 | var new_cwd_buf: [fs.max_path_bytes]u8 = undefined; | | |
| 57 | const new_cwd = try posix.getcwd(new_cwd_buf[0..]); | | |
| 58 | try expect(mem.eql(u8, old_cwd, new_cwd)); | | |
| 59 | } | | |
| 60 | | | |
| 61 | // Next, change current working directory to one level above | | |
| 62 | const parent = fs.path.dirname(old_cwd) orelse unreachable; // old_cwd should be absolute | | |
| 63 | try posix.chdir(parent); | | |
| 64 | | | |
| 65 | var new_cwd_buf: [fs.max_path_bytes]u8 = undefined; | | |
| 66 | const new_cwd = try posix.getcwd(new_cwd_buf[0..]); | | |
| 67 | try expect(mem.eql(u8, parent, new_cwd)); | | |
| 68 | } | | |
| 69 | | | |
| 70 | test "chdir relative" { | | |
| 71 | if (native_os == .wasi) return error.SkipZigTest; | | |
| 72 | | | |
| 73 | var tmp = tmpDir(.{}); | | |
| 74 | defer tmp.cleanup(); | | |
| 75 | | | |
| 76 | // Restore default CWD at end of test. | | |
| 77 | const orig_cwd = try fs.cwd().openDir(".", .{}); | | |
| 78 | defer orig_cwd.setAsCwd() catch unreachable; | | |
| 79 | | | |
| 80 | // Use the tmpDir parent_dir as the "base" for the test. Then cd into the child | | |
| 81 | try tmp.parent_dir.setAsCwd(); | | |
| 82 | | | |
| 83 | // Capture base working directory path, to build expected full path | | |
| 84 | var base_cwd_buf: [fs.max_path_bytes]u8 = undefined; | | |
| 85 | const base_cwd = try posix.getcwd(base_cwd_buf[0..]); | | |
| 86 | | | |
| 87 | const dir_name = &tmp.sub_path; | | |
| 88 | const expected_path = try fs.path.resolve(a, &.{ base_cwd, dir_name }); | | |
| 89 | defer a.free(expected_path); | | |
| 90 | | | |
| 91 | // change current working directory to new directory | | |
| 92 | try posix.chdir(dir_name); | | |
| 93 | | | |
| 94 | var new_cwd_buf: [fs.max_path_bytes]u8 = undefined; | | |
| 95 | const new_cwd = try posix.getcwd(new_cwd_buf[0..]); | | |
| 96 | | | |
| 97 | // On Windows, fs.path.resolve returns an uppercase drive letter, but the drive letter returned by getcwd may be lowercase | | |
| 98 | const resolved_cwd = try fs.path.resolve(a, &.{new_cwd}); | | |
| 99 | defer a.free(resolved_cwd); | | |
| 100 | | | |
| 101 | try expect(mem.eql(u8, expected_path, resolved_cwd)); | | |
| 102 | } | | |
| 103 | | | |
| 104 | test "open smoke test" { | 45 | test "open smoke test" { |
| 105 | if (native_os == .wasi) return error.SkipZigTest; | 46 | if (native_os == .wasi) return error.SkipZigTest; |
| 106 | if (native_os == .windows) return error.SkipZigTest; | 47 | if (native_os == .windows) return error.SkipZigTest; |
| ... | @@ -455,12 +396,6 @@ test "getrandom" { | ... | @@ -455,12 +396,6 @@ test "getrandom" { |
| 455 | try expect(!mem.eql(u8, &buf_a, &buf_b)); | 396 | try expect(!mem.eql(u8, &buf_a, &buf_b)); |
| 456 | } | 397 | } |
| 457 | | 398 | |
| 458 | test "getcwd" { | | |
| 459 | // at least call it so it gets compiled | | |
| 460 | var buf: [std.fs.max_path_bytes]u8 = undefined; | | |
| 461 | _ = posix.getcwd(&buf) catch undefined; | | |
| 462 | } | | |
| 463 | | | |
| 464 | test "getuid" { | 399 | test "getuid" { |
| 465 | if (native_os == .windows or native_os == .wasi) return error.SkipZigTest; | 400 | if (native_os == .windows or native_os == .wasi) return error.SkipZigTest; |
| 466 | _ = posix.getuid(); | 401 | _ = posix.getuid(); |