@@ -551,13 +551,12 @@ final class FileManagerTests : XCTestCase {
551
551
}
552
552
553
553
func testFileAccessAtPath( ) throws {
554
- #if os(Windows)
555
- throw XCTSkip ( " Windows filesystems do not conform to POSIX semantics " )
556
- #else
554
+ #if !os(Windows)
557
555
guard getuid ( ) != 0 else {
558
556
// Root users can always access anything, so this test will not function when run as root
559
557
throw XCTSkip ( " This test is not available when running as the root user " )
560
558
}
559
+ #endif
561
560
562
561
try FileManagerPlayground {
563
562
File ( " 000 " , attributes: [ . posixPermissions: 0o000 ] )
@@ -569,18 +568,29 @@ final class FileManagerTests : XCTestCase {
569
568
File ( " 666 " , attributes: [ . posixPermissions: 0o666 ] )
570
569
File ( " 777 " , attributes: [ . posixPermissions: 0o777 ] )
571
570
} . test {
571
+ #if os(Windows)
572
+ // All files are readable on Windows
573
+ let readable = [ " 000 " , " 111 " , " 222 " , " 333 " , " 444 " , " 555 " , " 666 " , " 777 " ]
574
+ // None of these files are executable on Windows
575
+ let executable : [ String ] = [ ]
576
+ #else
572
577
let readable = [ " 444 " , " 555 " , " 666 " , " 777 " ]
573
- let writable = [ " 222 " , " 333 " , " 666 " , " 777 " ]
574
578
let executable = [ " 111 " , " 333 " , " 555 " , " 777 " ]
579
+ #endif
580
+ let writable = [ " 222 " , " 333 " , " 666 " , " 777 " ]
575
581
for number in 0 ... 7 {
576
582
let file = " \( number) \( number) \( number) "
577
583
XCTAssertEqual ( $0. isReadableFile ( atPath: file) , readable. contains ( file) , " ' \( file) ' failed readable check " )
578
584
XCTAssertEqual ( $0. isWritableFile ( atPath: file) , writable. contains ( file) , " ' \( file) ' failed writable check " )
579
585
XCTAssertEqual ( $0. isExecutableFile ( atPath: file) , executable. contains ( file) , " ' \( file) ' failed executable check " )
586
+ #if os(Windows)
587
+ // Only writable files are deletable on Windows
588
+ XCTAssertEqual ( $0. isDeletableFile ( atPath: file) , writable. contains ( file) , " ' \( file) ' failed deletable check " )
589
+ #else
580
590
XCTAssertTrue ( $0. isDeletableFile ( atPath: file) , " ' \( file) ' failed deletable check " )
591
+ #endif
581
592
}
582
593
}
583
- #endif
584
594
}
585
595
586
596
func testFileSystemAttributesAtPath( ) throws {
@@ -660,16 +670,21 @@ final class FileManagerTests : XCTestCase {
660
670
File ( " foo " , attributes: [ . posixPermissions : UInt16 ( 0o644 ) ] )
661
671
} . test {
662
672
let attributes = try $0. attributesOfItem ( atPath: " foo " )
663
- #if !os(Windows)
673
+
664
674
// Ensure the unconventional UInt16 was accepted as input
675
+ #if os(Windows)
676
+ XCTAssertEqual ( attributes [ . posixPermissions] as? UInt , 0o600 )
677
+ #else
665
678
XCTAssertEqual ( attributes [ . posixPermissions] as? UInt , 0o644 )
679
+ #endif
680
+
666
681
#if FOUNDATION_FRAMEWORK
667
682
// Where we have NSNumber, ensure that we can get the value back as an unconventional Double value
668
683
XCTAssertEqual ( attributes [ . posixPermissions] as? Double , Double ( 0o644 ) )
669
684
// Ensure that the file type can be converted to a String when it is an ObjC enum
670
685
XCTAssertEqual ( attributes [ . type] as? String , FileAttributeType . typeRegular. rawValue)
671
686
#endif
672
- #endif
687
+
673
688
// Ensure that the file type can be converted to a FileAttributeType when it is an ObjC enum and in swift-foundation
674
689
XCTAssertEqual ( attributes [ . type] as? FileAttributeType , . typeRegular)
675
690
0 commit comments