@@ -412,9 +412,13 @@ final class FileManagerTests : XCTestCase {
412
412
func testCreateSymbolicLinkAtPath( ) throws {
413
413
try FileManagerPlayground {
414
414
" foo "
415
+ Directory ( " dir " ) { }
415
416
} . test {
416
417
try $0. createSymbolicLink ( atPath: " bar " , withDestinationPath: " foo " )
417
418
XCTAssertEqual ( try $0. destinationOfSymbolicLink ( atPath: " bar " ) , " foo " )
419
+
420
+ try $0. createSymbolicLink ( atPath: " dir_link " , withDestinationPath: " dir " )
421
+ XCTAssertEqual ( try $0. destinationOfSymbolicLink ( atPath: " dir_link " ) , " dir " )
418
422
419
423
XCTAssertThrowsError ( try $0. createSymbolicLink ( atPath: " bar " , withDestinationPath: " foo " ) ) {
420
424
XCTAssertEqual ( ( $0 as? CocoaError ) ? . code, . fileWriteFileExists)
@@ -426,6 +430,41 @@ final class FileManagerTests : XCTestCase {
426
430
XCTAssertEqual ( ( $0 as? CocoaError ) ? . code, . fileReadUnknown)
427
431
}
428
432
}
433
+
434
+ try FileManagerPlayground {
435
+ Directory ( " dir " ) {
436
+ Directory ( " other_dir " ) {
437
+ " file "
438
+ }
439
+ }
440
+ } . test {
441
+ // Create a relative symlink to other_dir from within dir (tests windows special dir symlink handling)
442
+ try $0. createSymbolicLink ( atPath: " dir/link " , withDestinationPath: " other_dir " )
443
+
444
+ // Ensure it is created successfully
445
+ XCTAssertEqual ( try $0. destinationOfSymbolicLink ( atPath: " dir/link " ) , " other_dir " )
446
+ XCTAssertEqual ( try $0. contentsOfDirectory ( atPath: " dir/link " ) , [ " file " ] )
447
+
448
+ do {
449
+ // Second symlink creation with an absolute path
450
+ let absolute = URL ( filePath: " dir/link2 " , relativeTo: URL ( filePath: $0. currentDirectoryPath, directoryHint: . isDirectory) ) . path
451
+ try $0. createSymbolicLink ( atPath: absolute, withDestinationPath: " other_dir " )
452
+
453
+ // Ensure it is created successfully
454
+ XCTAssertEqual ( try $0. destinationOfSymbolicLink ( atPath: " dir/link2 " ) , " other_dir " )
455
+ XCTAssertEqual ( try $0. contentsOfDirectory ( atPath: " dir/link2 " ) , [ " file " ] )
456
+ }
457
+
458
+ do {
459
+ // And lastly a symlink to an absolute path
460
+ let absolute = URL ( filePath: " dir/other_dir " , relativeTo: URL ( filePath: $0. currentDirectoryPath, directoryHint: . isDirectory) ) . path
461
+ try $0. createSymbolicLink ( atPath: " dir/link3 " , withDestinationPath: absolute)
462
+
463
+ // Ensure it is created successfully
464
+ XCTAssertEqual ( try $0. destinationOfSymbolicLink ( atPath: " dir/link3 " ) , absolute. withFileSystemRepresentation { String ( cString: $0!) } )
465
+ XCTAssertEqual ( try $0. contentsOfDirectory ( atPath: " dir/link3 " ) , [ " file " ] )
466
+ }
467
+ }
429
468
}
430
469
431
470
func testMoveItemAtPathToPath( ) throws {
0 commit comments