@@ -61,6 +61,7 @@ class TestNSURL : XCTestCase {
61
61
( " test_fileURLWithPath " , test_fileURLWithPath) ,
62
62
( " test_fileURLWithPath_isDirectory " , test_fileURLWithPath_isDirectory) ,
63
63
( " test_URLByResolvingSymlinksInPath " , test_URLByResolvingSymlinksInPath) ,
64
+ ( " test_reachable " , test_reachable) ,
64
65
( " test_copy " , test_copy) ,
65
66
( " test_itemNSCoding " , test_itemNSCoding) ,
66
67
]
@@ -422,6 +423,25 @@ class TestNSURL : XCTestCase {
422
423
XCTAssertEqual ( result, " file:///tmp/ " )
423
424
}
424
425
}
426
+
427
+ func test_reachable( ) {
428
+ var url = URL ( fileURLWithPath: " /usr " )
429
+ XCTAssertEqual ( true , try ? url. checkResourceIsReachable ( ) )
430
+
431
+ url = URL ( string: " https://www.swift.org " ) !
432
+ XCTAssertEqual ( false , try ? url. checkResourceIsReachable ( ) )
433
+
434
+ url = URL ( fileURLWithPath: " /some_random_path " )
435
+ do {
436
+ _ = try url. checkResourceIsReachable ( )
437
+ XCTFail ( )
438
+ } catch let error as NSError {
439
+ XCTAssertEqual ( NSCocoaErrorDomain, error. domain)
440
+ XCTAssertEqual ( CocoaError . Code. fileReadNoSuchFile. rawValue, error. code)
441
+ } catch {
442
+ XCTFail ( )
443
+ }
444
+ }
425
445
426
446
func test_copy( ) {
427
447
let url = NSURL ( string: " https://www.swift.org " )
0 commit comments