@@ -72,9 +72,8 @@ const PathType = enum {
const TestContext = struct {
path_type: PathType,
arena: ArenaAllocator,
tmp: testing.TmpIterableDir,
tmp: testing.TmpDir,
dir: std.fs.Dir,
iterable_dir: std.fs.Dir,
transform_fn: *const PathType.TransformFn,
pub fn init(path_type: PathType, allocator: mem.Allocator, transform_fn: *const PathType.TransformFn) TestContext {
@@ -83,8 +82,7 @@ const TestContext = struct {
.path_type = path_type,
.arena = ArenaAllocator.init(allocator),
.tmp = tmp,
.dir = tmp.iterable_dir.dir,
.iterable_dir = tmp.iterable_dir,
.dir = tmp.dir,
.transform_fn = transform_fn,
};
}
@@ -359,7 +357,7 @@ test "Dir.Iterator many entries" {
var buf: [4]u8 = undefined; // Enough to store "1024".
while (i < num) : (i += 1) {
const name = try std.fmt.bufPrint(&buf, "{}", .{i});
const file = try tmp_dir.iterable_dir.dir.createFile(name, .{});
const file = try tmp_dir.dir.createFile(name, .{});
file.close();
}
@@ -370,7 +368,7 @@ test "Dir.Iterator many entries" {
var entries = std.ArrayList(Dir.Entry).init(allocator);
// Create iterator.
var iter = tmp_dir.iterable_dir.iterate();
var iter = tmp_dir.dir.iterate();
while (try iter.next()) |entry| {
// We cannot just store `entry` as on Windows, we're re-using the name buffer
// which means we'll actually share the `name` pointer between entries!
@@ -423,17 +421,17 @@ test "Dir.Iterator reset" {
defer tmp_dir.cleanup();
// First, create a couple of entries to iterate over.
const file = try tmp_dir.iterable_dir.dir.createFile("some_file", .{});
const file = try tmp_dir.dir.createFile("some_file", .{});
file.close();
try tmp_dir.iterable_dir.dir.makeDir("some_dir");
try tmp_dir.dir.makeDir("some_dir");
var arena = ArenaAllocator.init(testing.allocator);
defer arena.deinit();
const allocator = arena.allocator();
// Create iterator.
var iter = tmp_dir.iterable_dir.iterate();
var iter = tmp_dir.dir.iterate();
var i: u8 = 0;
while (i < 2) : (i += 1) {
@@ -459,10 +457,10 @@ test "Dir.Iterator but dir is deleted during iteration" {
defer tmp.cleanup();
// Create directory and setup an iterator for it
var iterable_subdir = try tmp.dir.makeOpenPathIterable("subdir", .{});
defer iterable_subdir.close();
var subdir = try tmp.dir.makeOpenPath("subdir", .{ .iterate = true });
defer subdir.close();
var iterator = iterable_subdir.iterate();
var iterator = subdir.iterate();
// Create something to iterate over within the subdir
try tmp.dir.makePath("subdir/b");
@@ -964,7 +962,7 @@ test "makePath in a directory that no longer exists" {
fn testFilenameLimits(iterable_dir: Dir, maxed_filename: []const u8) !void {
// setup, create a dir and a nested file both with maxed filenames, and walk the dir
{
var maxed_dir = try iterable_dir.dir.makeOpenPath(maxed_filename, .{});
var maxed_dir = try iterable_dir.makeOpenPath(maxed_filename, .{});
defer maxed_dir.close();
try maxed_dir.writeFile(maxed_filename, "");
@@ -981,7 +979,7 @@ fn testFilenameLimits(iterable_dir: Dir, maxed_filename: []const u8) !void {
}
// ensure that we can delete the tree
try iterable_dir.dir.deleteTree(maxed_filename);
try iterable_dir.deleteTree(maxed_filename);
}
test "max file name component lengths" {
@@ -992,16 +990,16 @@ test "max file name component lengths" {
// U+FFFF is the character with the largest code point that is encoded as a single
// UTF-16 code unit, so Windows allows for NAME_MAX of them.
const maxed_windows_filename = ("\u{FFFF}".*) ** std.os.windows.NAME_MAX;
try testFilenameLimits(tmp.iterable_dir, &maxed_windows_filename);
try testFilenameLimits(tmp.dir, &maxed_windows_filename);
} else if (builtin.os.tag == .wasi) {
// On WASI, the maxed filename depends on the host OS, so in order for this test to
// work on any host, we need to use a length that will work for all platforms
// (i.e. the minimum MAX_NAME_BYTES of all supported platforms).
const maxed_wasi_filename = [_]u8{'1'} ** 255;
try testFilenameLimits(tmp.iterable_dir, &maxed_wasi_filename);
try testFilenameLimits(tmp.dir, &maxed_wasi_filename);
} else {
const maxed_ascii_filename = [_]u8{'1'} ** std.fs.MAX_NAME_BYTES;
try testFilenameLimits(tmp.iterable_dir, &maxed_ascii_filename);
try testFilenameLimits(tmp.dir, &maxed_ascii_filename);
}
}
@@ -1438,14 +1436,14 @@ test "walker without fully iterating" {
var tmp = tmpDir(.{ .iterate = true });
defer tmp.cleanup();
var walker = try tmp.iterable_dir.walk(testing.allocator);
var walker = try tmp.dir.walk(testing.allocator);
defer walker.deinit();
// Create 2 directories inside the tmp directory, but then only iterate once before breaking.
// This ensures that walker doesn't try to close the initial directory when not fully iterating.
try tmp.iterable_dir.dir.makePath("a");
try tmp.iterable_dir.dir.makePath("b");
try tmp.dir.makePath("a");
try tmp.dir.makePath("b");
var num_walked: usize = 0;
while (try walker.next()) |_| {