@@ -571,53 +571,50 @@ final class FileManagerTests : XCTestCase {
571
571
572
572
#if canImport(Darwin)
573
573
// not supported on linux as the test depends on FileManager.removeItem calling removefile(3)
574
- // not supported on older versions of Darwin where removefile would return ENOENT instead of ENAMETOOLONG
575
- if #available( macOS 14 . 4 , iOS 17 . 0 , watchOS 10 . 0 , tvOS 17 . 0 , * ) {
576
- try FileManagerPlayground {
577
- } . test {
578
- // Create hierarchy in which the leaf is a long path (length > PATH_MAX)
579
- let rootDir = $0. currentDirectoryPath
580
- let aas = Array ( repeating: " a " , count: Int ( NAME_MAX) - 3 ) . joined ( )
581
- let bbs = Array ( repeating: " b " , count: Int ( NAME_MAX) - 3 ) . joined ( )
582
- let ccs = Array ( repeating: " c " , count: Int ( NAME_MAX) - 3 ) . joined ( )
583
- let dds = Array ( repeating: " d " , count: Int ( NAME_MAX) - 3 ) . joined ( )
584
- let ees = Array ( repeating: " e " , count: Int ( NAME_MAX) - 3 ) . joined ( )
585
- let leaf = " longpath "
586
-
587
- try $0. createDirectory ( atPath: aas, withIntermediateDirectories: true )
588
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( aas) )
589
- try $0. createDirectory ( atPath: bbs, withIntermediateDirectories: true )
590
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( bbs) )
591
- try $0. createDirectory ( atPath: ccs, withIntermediateDirectories: true )
592
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( ccs) )
593
- try $0. createDirectory ( atPath: dds, withIntermediateDirectories: true )
594
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( dds) )
595
- try $0. createDirectory ( atPath: ees, withIntermediateDirectories: true )
596
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( ees) )
597
- try $0. createDirectory ( atPath: leaf, withIntermediateDirectories: true )
598
-
599
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( rootDir) )
600
- let fullPath = " \( aas) / \( bbs) / \( ccs) / \( dds) / \( ees) / \( leaf) "
601
- XCTAssertThrowsError ( try $0. removeItem ( atPath: fullPath) ) {
602
- let underlyingPosixError = ( $0 as? CocoaError ) ? . underlying as? POSIXError
603
- XCTAssertEqual ( underlyingPosixError? . code, . ENAMETOOLONG, " removeItem didn't fail with ENAMETOOLONG; produced error: \( $0) " )
604
- }
605
-
606
- // Clean up
607
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( aas) )
608
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( bbs) )
609
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( ccs) )
610
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( dds) )
611
- try $0. removeItem ( atPath: ees)
612
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( " .. " ) )
613
- try $0. removeItem ( atPath: dds)
614
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( " .. " ) )
615
- try $0. removeItem ( atPath: ccs)
616
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( " .. " ) )
617
- try $0. removeItem ( atPath: bbs)
618
- XCTAssertTrue ( $0. changeCurrentDirectoryPath ( " .. " ) )
619
- try $0. removeItem ( atPath: aas)
574
+ try FileManagerPlayground {
575
+ } . test {
576
+ // Create hierarchy in which the leaf is a long path (length > PATH_MAX)
577
+ let rootDir = $0. currentDirectoryPath
578
+ let aas = Array ( repeating: " a " , count: Int ( NAME_MAX) - 3 ) . joined ( )
579
+ let bbs = Array ( repeating: " b " , count: Int ( NAME_MAX) - 3 ) . joined ( )
580
+ let ccs = Array ( repeating: " c " , count: Int ( NAME_MAX) - 3 ) . joined ( )
581
+ let dds = Array ( repeating: " d " , count: Int ( NAME_MAX) - 3 ) . joined ( )
582
+ let ees = Array ( repeating: " e " , count: Int ( NAME_MAX) - 3 ) . joined ( )
583
+ let leaf = " longpath "
584
+
585
+ try $0. createDirectory ( atPath: aas, withIntermediateDirectories: true )
586
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( aas) )
587
+ try $0. createDirectory ( atPath: bbs, withIntermediateDirectories: true )
588
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( bbs) )
589
+ try $0. createDirectory ( atPath: ccs, withIntermediateDirectories: true )
590
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( ccs) )
591
+ try $0. createDirectory ( atPath: dds, withIntermediateDirectories: true )
592
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( dds) )
593
+ try $0. createDirectory ( atPath: ees, withIntermediateDirectories: true )
594
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( ees) )
595
+ try $0. createDirectory ( atPath: leaf, withIntermediateDirectories: true )
596
+
597
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( rootDir) )
598
+ let fullPath = " \( aas) / \( bbs) / \( ccs) / \( dds) / \( ees) / \( leaf) "
599
+ XCTAssertThrowsError ( try $0. removeItem ( atPath: fullPath) ) {
600
+ let underlyingPosixError = ( $0 as? CocoaError ) ? . underlying as? POSIXError
601
+ XCTAssertEqual ( underlyingPosixError? . code, . ENAMETOOLONG, " removeItem didn't fail with ENAMETOOLONG; produced error: \( $0) " )
620
602
}
603
+
604
+ // Clean up
605
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( aas) )
606
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( bbs) )
607
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( ccs) )
608
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( dds) )
609
+ try $0. removeItem ( atPath: ees)
610
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( " .. " ) )
611
+ try $0. removeItem ( atPath: dds)
612
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( " .. " ) )
613
+ try $0. removeItem ( atPath: ccs)
614
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( " .. " ) )
615
+ try $0. removeItem ( atPath: bbs)
616
+ XCTAssertTrue ( $0. changeCurrentDirectoryPath ( " .. " ) )
617
+ try $0. removeItem ( atPath: aas)
621
618
}
622
619
#endif
623
620
}
0 commit comments