@@ -932,3 +932,75 @@ test "walker" {
932932 try testing .expectEqualStrings (expected_dir_name , try fs .path .relative (allocator , tmp_path , entry .path ));
933933 }
934934}
935+
936+ test ". and .. in fs.Dir functions" {
937+ if (builtin .os .tag == .wasi ) return error .SkipZigTest ;
938+
939+ var tmp = tmpDir (.{});
940+ defer tmp .cleanup ();
941+
942+ try tmp .dir .makeDir ("./subdir" );
943+ try tmp .dir .access ("./subdir" , .{});
944+ var created_subdir = try tmp .dir .openDir ("./subdir" , .{});
945+ created_subdir .close ();
946+
947+ const created_file = try tmp .dir .createFile ("./subdir/../file" , .{});
948+ created_file .close ();
949+ try tmp .dir .access ("./subdir/../file" , .{});
950+
951+ try tmp .dir .copyFile ("./subdir/../file" , tmp .dir , "./subdir/../copy" , .{});
952+ try tmp .dir .rename ("./subdir/../copy" , "./subdir/../rename" );
953+ const renamed_file = try tmp .dir .openFile ("./subdir/../rename" , .{});
954+ renamed_file .close ();
955+ try tmp .dir .deleteFile ("./subdir/../rename" );
956+
957+ try tmp .dir .writeFile ("./subdir/../update" , "something" );
958+ const prev_status = try tmp .dir .updateFile ("./subdir/../file" , tmp .dir , "./subdir/../update" , .{});
959+ try testing .expectEqual (fs .PrevStatus .stale , prev_status );
960+
961+ try tmp .dir .deleteDir ("./subdir" );
962+ }
963+
964+ test ". and .. in absolute functions" {
965+ if (builtin .os .tag == .wasi ) return error .SkipZigTest ;
966+
967+ var tmp = tmpDir (.{});
968+ defer tmp .cleanup ();
969+
970+ var arena = ArenaAllocator .init (testing .allocator );
971+ defer arena .deinit ();
972+ const allocator = & arena .allocator ;
973+
974+ const base_path = blk : {
975+ const relative_path = try fs .path .join (& arena .allocator , &[_ ][]const u8 { "zig-cache" , "tmp" , tmp .sub_path [0.. ] });
976+ break :blk try fs .realpathAlloc (& arena .allocator , relative_path );
977+ };
978+
979+ const subdir_path = try fs .path .join (allocator , &[_ ][]const u8 { base_path , "./subdir" });
980+ try fs .makeDirAbsolute (subdir_path );
981+ try fs .accessAbsolute (subdir_path , .{});
982+ var created_subdir = try fs .openDirAbsolute (subdir_path , .{});
983+ created_subdir .close ();
984+
985+ const created_file_path = try fs .path .join (allocator , &[_ ][]const u8 { subdir_path , "../file" });
986+ const created_file = try fs .createFileAbsolute (created_file_path , .{});
987+ created_file .close ();
988+ try fs .accessAbsolute (created_file_path , .{});
989+
990+ const copied_file_path = try fs .path .join (allocator , &[_ ][]const u8 { subdir_path , "../copy" });
991+ try fs .copyFileAbsolute (created_file_path , copied_file_path , .{});
992+ const renamed_file_path = try fs .path .join (allocator , &[_ ][]const u8 { subdir_path , "../rename" });
993+ try fs .renameAbsolute (copied_file_path , renamed_file_path );
994+ const renamed_file = try fs .openFileAbsolute (renamed_file_path , .{});
995+ renamed_file .close ();
996+ try fs .deleteFileAbsolute (renamed_file_path );
997+
998+ const update_file_path = try fs .path .join (allocator , &[_ ][]const u8 { subdir_path , "../update" });
999+ const update_file = try fs .createFileAbsolute (update_file_path , .{});
1000+ try update_file .writeAll ("something" );
1001+ update_file .close ();
1002+ const prev_status = try fs .updateFileAbsolute (created_file_path , update_file_path , .{});
1003+ try testing .expectEqual (fs .PrevStatus .stale , prev_status );
1004+
1005+ try fs .deleteDirAbsolute (subdir_path );
1006+ }
0 commit comments