@@ -516,7 +516,7 @@ class TestFileManager : XCTestCase {
516516 let fm = FileManager . default
517517 let srcPath = NSTemporaryDirectory ( ) + " testdir \( NSUUID ( ) . uuidString) "
518518 let destPath = NSTemporaryDirectory ( ) + " testdir \( NSUUID ( ) . uuidString) "
519-
519+
520520 func cleanup( ) {
521521 ignoreError { try fm. removeItem ( atPath: srcPath) }
522522 ignoreError { try fm. removeItem ( atPath: destPath) }
@@ -552,8 +552,13 @@ class TestFileManager : XCTestCase {
552552 cleanup ( )
553553 createDirectory ( atPath: srcPath)
554554 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 " )
555558 createFile ( atPath: " \( srcPath) /tempdir/tempfile " )
556559 createFile ( atPath: " \( srcPath) /tempdir/tempfile2 " )
560+ createFile ( atPath: " \( srcPath) /tempdir/subdir/otherdir/extradir/tempfile2 " )
561+
557562 do {
558563 try fm. copyItem ( atPath: srcPath, toPath: destPath)
559564 } catch let error {
@@ -563,16 +568,36 @@ class TestFileManager : XCTestCase {
563568 XCTAssertTrue ( directoryExists ( atPath: " \( destPath) /tempdir " ) )
564569 XCTAssertTrue ( fm. fileExists ( atPath: " \( destPath) /tempdir/tempfile " ) )
565570 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+
567574 if ( false == directoryExists ( atPath: destPath) ) {
568575 return
569576 }
570577 do {
571578 try fm. copyItem ( atPath: srcPath, toPath: destPath)
579+ XCTFail ( " Copy overwrites a file/folder that already exists " )
572580 } 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
574600 }
575- XCTFail ( " Copy overwrites a file/folder that already exists " )
576601 }
577602
578603 func test_homedirectoryForUser( ) {
0 commit comments