@@ -163,12 +163,12 @@ fn testReadLink(dir: Dir, target_path: []const u8, symlink_path: []const u8) !vo
163
163
test "openDir" {
164
164
try testWithAllSupportedPathTypes (struct {
165
165
fn impl (ctx : * TestContext ) ! void {
166
+ const allocator = ctx .arena .allocator ();
166
167
const subdir_path = try ctx .transformPath ("subdir" );
167
168
try ctx .dir .makeDir (subdir_path );
168
169
169
170
for ([_ ][]const u8 { "" , "." , ".." }) | sub_path | {
170
- const dir_path = try fs .path .join (testing .allocator , &[_ ][]const u8 { subdir_path , sub_path });
171
- defer testing .allocator .free (dir_path );
171
+ const dir_path = try fs .path .join (allocator , &.{ subdir_path , sub_path });
172
172
var dir = try ctx .dir .openDir (dir_path , .{});
173
173
defer dir .close ();
174
174
}
@@ -187,7 +187,7 @@ test "accessAbsolute" {
187
187
const allocator = arena .allocator ();
188
188
189
189
const base_path = blk : {
190
- const relative_path = try fs .path .join (allocator , &[ _ ][] const u8 { "zig-cache" , "tmp" , tmp .sub_path [0.. ] });
190
+ const relative_path = try fs .path .join (allocator , &. { "zig-cache" , "tmp" , tmp .sub_path [0.. ] });
191
191
break :blk try fs .realpathAlloc (allocator , relative_path );
192
192
};
193
193
@@ -206,7 +206,7 @@ test "openDirAbsolute" {
206
206
const allocator = arena .allocator ();
207
207
208
208
const base_path = blk : {
209
- const relative_path = try fs .path .join (allocator , &[ _ ][] const u8 { "zig-cache" , "tmp" , tmp .sub_path [0.. ], "subdir" });
209
+ const relative_path = try fs .path .join (allocator , &. { "zig-cache" , "tmp" , tmp .sub_path [0.. ], "subdir" });
210
210
break :blk try fs .realpathAlloc (allocator , relative_path );
211
211
};
212
212
@@ -216,8 +216,7 @@ test "openDirAbsolute" {
216
216
}
217
217
218
218
for ([_ ][]const u8 { "." , ".." }) | sub_path | {
219
- const dir_path = try fs .path .join (allocator , &[_ ][]const u8 { base_path , sub_path });
220
- defer allocator .free (dir_path );
219
+ const dir_path = try fs .path .join (allocator , &.{ base_path , sub_path });
221
220
var dir = try fs .openDirAbsolute (dir_path , .{});
222
221
defer dir .close ();
223
222
}
@@ -270,13 +269,13 @@ test "readLinkAbsolute" {
270
269
const allocator = arena .allocator ();
271
270
272
271
const base_path = blk : {
273
- const relative_path = try fs .path .join (allocator , &[ _ ][] const u8 { "zig-cache" , "tmp" , tmp .sub_path [0.. ] });
272
+ const relative_path = try fs .path .join (allocator , &. { "zig-cache" , "tmp" , tmp .sub_path [0.. ] });
274
273
break :blk try fs .realpathAlloc (allocator , relative_path );
275
274
};
276
275
277
276
{
278
- const target_path = try fs .path .join (allocator , &[ _ ][] const u8 { base_path , "file.txt" });
279
- const symlink_path = try fs .path .join (allocator , &[ _ ][] const u8 { base_path , "symlink1" });
277
+ const target_path = try fs .path .join (allocator , &. { base_path , "file.txt" });
278
+ const symlink_path = try fs .path .join (allocator , &. { base_path , "symlink1" });
280
279
281
280
// Create symbolic link by path
282
281
fs .symLinkAbsolute (target_path , symlink_path , .{}) catch | err | switch (err ) {
@@ -287,8 +286,8 @@ test "readLinkAbsolute" {
287
286
try testReadLinkAbsolute (target_path , symlink_path );
288
287
}
289
288
{
290
- const target_path = try fs .path .join (allocator , &[ _ ][] const u8 { base_path , "subdir" });
291
- const symlink_path = try fs .path .join (allocator , &[ _ ][] const u8 { base_path , "symlink2" });
289
+ const target_path = try fs .path .join (allocator , &. { base_path , "subdir" });
290
+ const symlink_path = try fs .path .join (allocator , &. { base_path , "symlink2" });
292
291
293
292
// Create symbolic link by path
294
293
fs .symLinkAbsolute (target_path , symlink_path , .{ .is_directory = true }) catch | err | switch (err ) {
@@ -485,33 +484,31 @@ test "Dir.realpath smoke test" {
485
484
486
485
try testWithAllSupportedPathTypes (struct {
487
486
fn impl (ctx : * TestContext ) ! void {
487
+ const allocator = ctx .arena .allocator ();
488
488
const test_file_path = try ctx .transformPath ("test_file" );
489
489
const test_dir_path = try ctx .transformPath ("test_dir" );
490
490
var buf : [fs .MAX_PATH_BYTES ]u8 = undefined ;
491
491
492
492
// FileNotFound if the path doesn't exist
493
- try testing .expectError (error .FileNotFound , ctx .dir .realpathAlloc (testing . allocator , test_file_path ));
493
+ try testing .expectError (error .FileNotFound , ctx .dir .realpathAlloc (allocator , test_file_path ));
494
494
try testing .expectError (error .FileNotFound , ctx .dir .realpath (test_file_path , & buf ));
495
- try testing .expectError (error .FileNotFound , ctx .dir .realpathAlloc (testing . allocator , test_dir_path ));
495
+ try testing .expectError (error .FileNotFound , ctx .dir .realpathAlloc (allocator , test_dir_path ));
496
496
try testing .expectError (error .FileNotFound , ctx .dir .realpath (test_dir_path , & buf ));
497
497
498
498
// Now create the file and dir
499
499
try ctx .dir .writeFile (test_file_path , "" );
500
500
try ctx .dir .makeDir (test_dir_path );
501
501
502
502
const base_path = try ctx .transformPath ("." );
503
- const base_realpath = try ctx .dir .realpathAlloc (testing .allocator , base_path );
504
- defer testing .allocator .free (base_realpath );
503
+ const base_realpath = try ctx .dir .realpathAlloc (allocator , base_path );
505
504
const expected_file_path = try fs .path .join (
506
- testing . allocator ,
507
- &[ _ ][] const u8 { base_realpath , "test_file" },
505
+ allocator ,
506
+ &. { base_realpath , "test_file" },
508
507
);
509
- defer testing .allocator .free (expected_file_path );
510
508
const expected_dir_path = try fs .path .join (
511
- testing . allocator ,
512
- &[ _ ][] const u8 { base_realpath , "test_dir" },
509
+ allocator ,
510
+ &. { base_realpath , "test_dir" },
513
511
);
514
- defer testing .allocator .free (expected_dir_path );
515
512
516
513
// First, test non-alloc version
517
514
{
@@ -524,12 +521,10 @@ test "Dir.realpath smoke test" {
524
521
525
522
// Next, test alloc version
526
523
{
527
- const file_path = try ctx .dir .realpathAlloc (testing .allocator , test_file_path );
528
- defer testing .allocator .free (file_path );
524
+ const file_path = try ctx .dir .realpathAlloc (allocator , test_file_path );
529
525
try testing .expectEqualStrings (expected_file_path , file_path );
530
526
531
- const dir_path = try ctx .dir .realpathAlloc (testing .allocator , test_dir_path );
532
- defer testing .allocator .free (dir_path );
527
+ const dir_path = try ctx .dir .realpathAlloc (allocator , test_dir_path );
533
528
try testing .expectEqualStrings (expected_dir_path , dir_path );
534
529
}
535
530
}
@@ -849,13 +844,13 @@ test "renameAbsolute" {
849
844
const allocator = arena .allocator ();
850
845
851
846
const base_path = blk : {
852
- const relative_path = try fs .path .join (allocator , &[ _ ][] const u8 { "zig-cache" , "tmp" , tmp_dir .sub_path [0.. ] });
847
+ const relative_path = try fs .path .join (allocator , &. { "zig-cache" , "tmp" , tmp_dir .sub_path [0.. ] });
853
848
break :blk try fs .realpathAlloc (allocator , relative_path );
854
849
};
855
850
856
851
try testing .expectError (error .FileNotFound , fs .renameAbsolute (
857
- try fs .path .join (allocator , &[ _ ][] const u8 { base_path , "missing_file_name" }),
858
- try fs .path .join (allocator , &[ _ ][] const u8 { base_path , "something_else" }),
852
+ try fs .path .join (allocator , &. { base_path , "missing_file_name" }),
853
+ try fs .path .join (allocator , &. { base_path , "something_else" }),
859
854
));
860
855
861
856
// Renaming files
@@ -864,8 +859,8 @@ test "renameAbsolute" {
864
859
var file = try tmp_dir .dir .createFile (test_file_name , .{ .read = true });
865
860
file .close ();
866
861
try fs .renameAbsolute (
867
- try fs .path .join (allocator , &[ _ ][] const u8 { base_path , test_file_name }),
868
- try fs .path .join (allocator , &[ _ ][] const u8 { base_path , renamed_test_file_name }),
862
+ try fs .path .join (allocator , &. { base_path , test_file_name }),
863
+ try fs .path .join (allocator , &. { base_path , renamed_test_file_name }),
869
864
);
870
865
871
866
// ensure the file was renamed
@@ -880,8 +875,8 @@ test "renameAbsolute" {
880
875
const renamed_test_dir_name = "test_dir_renamed" ;
881
876
try tmp_dir .dir .makeDir (test_dir_name );
882
877
try fs .renameAbsolute (
883
- try fs .path .join (allocator , &[ _ ][] const u8 { base_path , test_dir_name }),
884
- try fs .path .join (allocator , &[ _ ][] const u8 { base_path , renamed_test_dir_name }),
878
+ try fs .path .join (allocator , &. { base_path , test_dir_name }),
879
+ try fs .path .join (allocator , &. { base_path , renamed_test_dir_name }),
885
880
);
886
881
887
882
// ensure the directory was renamed
@@ -900,11 +895,12 @@ test "openSelfExe" {
900
895
test "makePath, put some files in it, deleteTree" {
901
896
try testWithAllSupportedPathTypes (struct {
902
897
fn impl (ctx : * TestContext ) ! void {
898
+ const allocator = ctx .arena .allocator ();
903
899
const dir_path = try ctx .transformPath ("os_test_tmp" );
904
900
905
- try ctx .dir .makePath ("os_test_tmp" ++ fs .path .sep_str ++ "b" ++ fs . path . sep_str ++ "c" );
906
- try ctx .dir .writeFile ("os_test_tmp" ++ fs .path .sep_str ++ "b" ++ fs . path . sep_str ++ "c" ++ fs . path . sep_str ++ "file.txt" , "nonsense" );
907
- try ctx .dir .writeFile ("os_test_tmp" ++ fs .path .sep_str ++ "b" ++ fs . path . sep_str ++ "file2.txt" , "blah" );
901
+ try ctx .dir .makePath (try fs .path .join ( allocator , &.{ "os_test_tmp" , "b" , "c" }) );
902
+ try ctx .dir .writeFile (try fs .path .join ( allocator , &.{ "os_test_tmp" , "b" , "c" , "file.txt" }) , "nonsense" );
903
+ try ctx .dir .writeFile (try fs .path .join ( allocator , &.{ "os_test_tmp" , "b" , "file2.txt" }) , "blah" );
908
904
909
905
try ctx .dir .deleteTree (dir_path );
910
906
try testing .expectError (error .FileNotFound , ctx .dir .openDir (dir_path , .{}));
@@ -915,11 +911,12 @@ test "makePath, put some files in it, deleteTree" {
915
911
test "makePath, put some files in it, deleteTreeMinStackSize" {
916
912
try testWithAllSupportedPathTypes (struct {
917
913
fn impl (ctx : * TestContext ) ! void {
914
+ const allocator = ctx .arena .allocator ();
918
915
const dir_path = try ctx .transformPath ("os_test_tmp" );
919
916
920
- try ctx .dir .makePath ("os_test_tmp" ++ fs .path .sep_str ++ "b" ++ fs . path . sep_str ++ "c" );
921
- try ctx .dir .writeFile ("os_test_tmp" ++ fs .path .sep_str ++ "b" ++ fs . path . sep_str ++ "c" ++ fs . path . sep_str ++ "file.txt" , "nonsense" );
922
- try ctx .dir .writeFile ("os_test_tmp" ++ fs .path .sep_str ++ "b" ++ fs . path . sep_str ++ "file2.txt" , "blah" );
917
+ try ctx .dir .makePath (try fs .path .join ( allocator , &.{ "os_test_tmp" , "b" , "c" }) );
918
+ try ctx .dir .writeFile (try fs .path .join ( allocator , &.{ "os_test_tmp" , "b" , "c" , "file.txt" }) , "nonsense" );
919
+ try ctx .dir .writeFile (try fs .path .join ( allocator , &.{ "os_test_tmp" , "b" , "file2.txt" }) , "blah" );
923
920
924
921
try ctx .dir .deleteTreeMinStackSize (dir_path );
925
922
try testing .expectError (error .FileNotFound , ctx .dir .openDir (dir_path , .{}));
@@ -1204,6 +1201,7 @@ fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void {
1204
1201
test "AtomicFile" {
1205
1202
try testWithAllSupportedPathTypes (struct {
1206
1203
fn impl (ctx : * TestContext ) ! void {
1204
+ const allocator = ctx .arena .allocator ();
1207
1205
const test_out_file = try ctx .transformPath ("tmp_atomic_file_test_dest.txt" );
1208
1206
const test_content =
1209
1207
\\ hello!
@@ -1216,8 +1214,7 @@ test "AtomicFile" {
1216
1214
try af .file .writeAll (test_content );
1217
1215
try af .finish ();
1218
1216
}
1219
- const content = try ctx .dir .readFileAlloc (testing .allocator , test_out_file , 9999 );
1220
- defer testing .allocator .free (content );
1217
+ const content = try ctx .dir .readFileAlloc (allocator , test_out_file , 9999 );
1221
1218
try testing .expectEqualStrings (test_content , content );
1222
1219
1223
1220
try ctx .dir .deleteFile (test_out_file );
@@ -1337,7 +1334,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {
1337
1334
const cwd = try std .process .getCwdAlloc (gpa );
1338
1335
defer gpa .free (cwd );
1339
1336
1340
- const filename = try fs .path .resolve (gpa , &[ _ ][] const u8 { cwd , sub_path });
1337
+ const filename = try fs .path .resolve (gpa , &. { cwd , sub_path });
1341
1338
defer gpa .free (filename );
1342
1339
1343
1340
const file1 = try fs .createFileAbsolute (filename , .{
@@ -1477,30 +1474,30 @@ test ". and .. in absolute functions" {
1477
1474
const allocator = arena .allocator ();
1478
1475
1479
1476
const base_path = blk : {
1480
- const relative_path = try fs .path .join (allocator , &[ _ ][] const u8 { "zig-cache" , "tmp" , tmp .sub_path [0.. ] });
1477
+ const relative_path = try fs .path .join (allocator , &. { "zig-cache" , "tmp" , tmp .sub_path [0.. ] });
1481
1478
break :blk try fs .realpathAlloc (allocator , relative_path );
1482
1479
};
1483
1480
1484
- const subdir_path = try fs .path .join (allocator , &[ _ ][] const u8 { base_path , "./subdir" });
1481
+ const subdir_path = try fs .path .join (allocator , &. { base_path , "./subdir" });
1485
1482
try fs .makeDirAbsolute (subdir_path );
1486
1483
try fs .accessAbsolute (subdir_path , .{});
1487
1484
var created_subdir = try fs .openDirAbsolute (subdir_path , .{});
1488
1485
created_subdir .close ();
1489
1486
1490
- const created_file_path = try fs .path .join (allocator , &[ _ ][] const u8 { subdir_path , "../file" });
1487
+ const created_file_path = try fs .path .join (allocator , &. { subdir_path , "../file" });
1491
1488
const created_file = try fs .createFileAbsolute (created_file_path , .{});
1492
1489
created_file .close ();
1493
1490
try fs .accessAbsolute (created_file_path , .{});
1494
1491
1495
- const copied_file_path = try fs .path .join (allocator , &[ _ ][] const u8 { subdir_path , "../copy" });
1492
+ const copied_file_path = try fs .path .join (allocator , &. { subdir_path , "../copy" });
1496
1493
try fs .copyFileAbsolute (created_file_path , copied_file_path , .{});
1497
- const renamed_file_path = try fs .path .join (allocator , &[ _ ][] const u8 { subdir_path , "../rename" });
1494
+ const renamed_file_path = try fs .path .join (allocator , &. { subdir_path , "../rename" });
1498
1495
try fs .renameAbsolute (copied_file_path , renamed_file_path );
1499
1496
const renamed_file = try fs .openFileAbsolute (renamed_file_path , .{});
1500
1497
renamed_file .close ();
1501
1498
try fs .deleteFileAbsolute (renamed_file_path );
1502
1499
1503
- const update_file_path = try fs .path .join (allocator , &[ _ ][] const u8 { subdir_path , "../update" });
1500
+ const update_file_path = try fs .path .join (allocator , &. { subdir_path , "../update" });
1504
1501
const update_file = try fs .createFileAbsolute (update_file_path , .{});
1505
1502
try update_file .writeAll ("something" );
1506
1503
update_file .close ();
0 commit comments