| ... | ... | @@ -794,3 +794,42 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" { |
| 794 | 794 | |
| 795 | 795 | try fs.deleteFileAbsolute(filename); |
| 796 | 796 | } |
| 797 | |
| 798 | test "walker" { |
| 799 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| 800 | |
| 801 | var arena = ArenaAllocator.init(testing.allocator); |
| 802 | defer arena.deinit(); |
| 803 | var allocator = &arena.allocator; |
| 804 | |
| 805 | var tmp = tmpDir(.{}); |
| 806 | defer tmp.cleanup(); |
| 807 | |
| 808 | const nb_dirs = 8; |
| 809 | |
| 810 | var i: usize = 0; |
| 811 | var sub_dir = tmp.dir; |
| 812 | while (i < nb_dirs) : (i += 1) { |
| 813 | const dir_name = try std.fmt.allocPrint(allocator, "{}", .{i}); |
| 814 | try sub_dir.makeDir(dir_name); |
| 815 | sub_dir = try sub_dir.openDir(dir_name, .{}); |
| 816 | } |
| 817 | |
| 818 | const tmp_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); |
| 819 | |
| 820 | var walker = try fs.walkPath(testing.allocator, tmp_path); |
| 821 | defer walker.deinit(); |
| 822 | |
| 823 | i = 0; |
| 824 | var expected_dir_name: []const u8 = ""; |
| 825 | while (i < nb_dirs) : (i += 1) { |
| 826 | const name = try std.fmt.allocPrint(allocator, "{}", .{i}); |
| 827 | expected_dir_name = if (expected_dir_name.len == 0) |
| 828 | name |
| 829 | else |
| 830 | try fs.path.join(allocator, &[_][]const u8{ expected_dir_name, name }); |
| 831 | |
| 832 | var entry = (try walker.next()).?; |
| 833 | testing.expectEqualStrings(expected_dir_name, try fs.path.relative(allocator, tmp_path, entry.path)); |
| 834 | } |
| 835 | } |