Skip to content

Commit ba0ab25

Browse files
author
Sergey Minakov
committed
additonal URL tests
1 parent f346c7e commit ba0ab25

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

TestFoundation/TestNSURL.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class TestNSURL : XCTestCase {
6161
("test_fileURLWithPath", test_fileURLWithPath),
6262
("test_fileURLWithPath_isDirectory", test_fileURLWithPath_isDirectory),
6363
("test_URLByResolvingSymlinksInPath", test_URLByResolvingSymlinksInPath),
64+
("test_reachable", test_reachable),
6465
("test_copy", test_copy),
6566
("test_itemNSCoding", test_itemNSCoding),
6667
]
@@ -422,6 +423,25 @@ class TestNSURL : XCTestCase {
422423
XCTAssertEqual(result, "file:///tmp/")
423424
}
424425
}
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+
}
425445

426446
func test_copy() {
427447
let url = NSURL(string: "https://www.swift.org")

0 commit comments

Comments
 (0)