@@ -516,7 +516,7 @@ class TestFileManager : XCTestCase {
516
516
let fm = FileManager . default
517
517
let srcPath = NSTemporaryDirectory ( ) + " testdir \( NSUUID ( ) . uuidString) "
518
518
let destPath = NSTemporaryDirectory ( ) + " testdir \( NSUUID ( ) . uuidString) "
519
-
519
+
520
520
func cleanup( ) {
521
521
ignoreError { try fm. removeItem ( atPath: srcPath) }
522
522
ignoreError { try fm. removeItem ( atPath: destPath) }
@@ -552,8 +552,13 @@ class TestFileManager : XCTestCase {
552
552
cleanup ( )
553
553
createDirectory ( atPath: srcPath)
554
554
createDirectory ( atPath: " \( srcPath) /tempdir " )
555
+ createDirectory ( atPath: " \( srcPath) /tempdir/subdir " )
556
+ createDirectory ( atPath: " \( srcPath) /tempdir/subdir/otherdir " )
557
+ createDirectory ( atPath: " \( srcPath) /tempdir/subdir/otherdir/extradir " )
555
558
createFile ( atPath: " \( srcPath) /tempdir/tempfile " )
556
559
createFile ( atPath: " \( srcPath) /tempdir/tempfile2 " )
560
+ createFile ( atPath: " \( srcPath) /tempdir/subdir/otherdir/extradir/tempfile2 " )
561
+
557
562
do {
558
563
try fm. copyItem ( atPath: srcPath, toPath: destPath)
559
564
} catch let error {
@@ -563,16 +568,36 @@ class TestFileManager : XCTestCase {
563
568
XCTAssertTrue ( directoryExists ( atPath: " \( destPath) /tempdir " ) )
564
569
XCTAssertTrue ( fm. fileExists ( atPath: " \( destPath) /tempdir/tempfile " ) )
565
570
XCTAssertTrue ( fm. fileExists ( atPath: " \( destPath) /tempdir/tempfile2 " ) )
566
-
571
+ XCTAssertTrue ( directoryExists ( atPath: " \( destPath) /tempdir/subdir/otherdir/extradir " ) )
572
+ XCTAssertTrue ( fm. fileExists ( atPath: " \( destPath) /tempdir/subdir/otherdir/extradir/tempfile2 " ) )
573
+
567
574
if ( false == directoryExists ( atPath: destPath) ) {
568
575
return
569
576
}
570
577
do {
571
578
try fm. copyItem ( atPath: srcPath, toPath: destPath)
579
+ XCTFail ( " Copy overwrites a file/folder that already exists " )
572
580
} catch {
573
- return
581
+ // ignore
582
+ }
583
+
584
+ // Test copying a symlink
585
+ let srcLink = srcPath + " /testlink "
586
+ let destLink = destPath + " /testlink "
587
+ do {
588
+ try fm. createSymbolicLink ( atPath: srcLink, withDestinationPath: " linkdest " )
589
+ try fm. copyItem ( atPath: srcLink, toPath: destLink)
590
+ XCTAssertEqual ( try fm. destinationOfSymbolicLink ( atPath: destLink) , " linkdest " )
591
+ } catch {
592
+ XCTFail ( " \( error) " )
593
+ }
594
+
595
+ do {
596
+ try fm. copyItem ( atPath: srcLink, toPath: destLink)
597
+ XCTFail ( " Creating link where one already exists " )
598
+ } catch {
599
+ // ignore
574
600
}
575
- XCTFail ( " Copy overwrites a file/folder that already exists " )
576
601
}
577
602
578
603
func test_homedirectoryForUser( ) {
0 commit comments