| ... | ... | @@ -916,14 +916,30 @@ test "walker" { |
| 916 | 916 | var tmp = tmpDir(.{}); |
| 917 | 917 | defer tmp.cleanup(); |
| 918 | 918 | |
| 919 | | const nb_dirs = 8; |
| 920 | | |
| 921 | | var i: usize = 0; |
| 922 | | var sub_dir = tmp.dir; |
| 923 | | while (i < nb_dirs) : (i += 1) { |
| 924 | | const dir_name = try std.fmt.allocPrint(allocator, "{}", .{i}); |
| 925 | | try sub_dir.makeDir(dir_name); |
| 926 | | sub_dir = try sub_dir.openDir(dir_name, .{}); |
| 919 | // iteration order of walker is undefined, so need lookup maps to check against |
| 920 | |
| 921 | const expected_paths = std.ComptimeStringMap(void, .{ |
| 922 | .{"dir1"}, |
| 923 | .{"dir2"}, |
| 924 | .{"dir3"}, |
| 925 | .{"dir4"}, |
| 926 | .{"dir3" ++ std.fs.path.sep_str ++ "sub1"}, |
| 927 | .{"dir3" ++ std.fs.path.sep_str ++ "sub2"}, |
| 928 | .{"dir3" ++ std.fs.path.sep_str ++ "sub2" ++ std.fs.path.sep_str ++ "subsub1"}, |
| 929 | }); |
| 930 | |
| 931 | const expected_basenames = std.ComptimeStringMap(void, .{ |
| 932 | .{"dir1"}, |
| 933 | .{"dir2"}, |
| 934 | .{"dir3"}, |
| 935 | .{"dir4"}, |
| 936 | .{"sub1"}, |
| 937 | .{"sub2"}, |
| 938 | .{"subsub1"}, |
| 939 | }); |
| 940 | |
| 941 | for (expected_paths.kvs) |kv| { |
| 942 | try tmp.dir.makePath(kv.key); |
| 927 | 943 | } |
| 928 | 944 | |
| 929 | 945 | const tmp_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); |
| ... | ... | @@ -932,18 +948,19 @@ test "walker" { |
| 932 | 948 | var walker = try tmp_dir.walk(testing.allocator); |
| 933 | 949 | defer walker.deinit(); |
| 934 | 950 | |
| 935 | | i = 0; |
| 936 | | var expected_dir_name: []const u8 = ""; |
| 937 | | while (i < nb_dirs) : (i += 1) { |
| 938 | | const name = try std.fmt.allocPrint(allocator, "{}", .{i}); |
| 939 | | expected_dir_name = if (expected_dir_name.len == 0) |
| 940 | | name |
| 941 | | else |
| 942 | | try fs.path.join(allocator, &[_][]const u8{ expected_dir_name, name }); |
| 943 | | |
| 944 | | var entry = (try walker.next()).?; |
| 945 | | try testing.expectEqualStrings(expected_dir_name, entry.path); |
| 951 | var num_walked: usize = 0; |
| 952 | while (try walker.next()) |entry| { |
| 953 | testing.expect(expected_basenames.has(entry.basename)) catch |err| { |
| 954 | std.debug.print("found unexpected basename: {s}\n", .{std.fmt.fmtSliceEscapeLower(entry.basename)}); |
| 955 | return err; |
| 956 | }; |
| 957 | testing.expect(expected_paths.has(entry.path)) catch |err| { |
| 958 | std.debug.print("found unexpected path: {s}\n", .{std.fmt.fmtSliceEscapeLower(entry.path)}); |
| 959 | return err; |
| 960 | }; |
| 961 | num_walked += 1; |
| 946 | 962 | } |
| 963 | try testing.expectEqual(expected_paths.kvs.len, num_walked); |
| 947 | 964 | } |
| 948 | 965 | |
| 949 | 966 | test ". and .. in fs.Dir functions" { |