Skip to content

Commit 5dfe636

Browse files
authored
Merge pull request #2158 from millenomi/build-fix-testurl-nserror
2 parents 95fcab2 + 0a5d278 commit 5dfe636

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

TestFoundation/TestURL.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,29 +244,29 @@ class TestURL : XCTestCase {
244244

245245
do {
246246
try FileManager.default.removeItem(atPath: gFileDoesNotExistPath)
247-
} catch let error as NSError {
247+
} catch {
248248
// The error code is a CocoaError
249-
if error.code != CocoaError.fileNoSuchFile.rawValue {
249+
if (error as? NSError)?.code != CocoaError.fileNoSuchFile.rawValue {
250250
return false
251251
}
252252
}
253253

254254
do {
255255
try FileManager.default.createDirectory(atPath: gDirectoryExistsPath, withIntermediateDirectories: false)
256-
} catch let error as NSError {
257-
// The error code is a CocoaError
258-
if error.code != CocoaError.fileWriteFileExists.rawValue {
259-
return false
260-
}
256+
} catch {
257+
// The error code is a CocoaError
258+
if (error as? NSError)?.code != CocoaError.fileNoSuchFile.rawValue {
259+
return false
260+
}
261261
}
262262

263263
do {
264264
try FileManager.default.removeItem(atPath: gDirectoryDoesNotExistPath)
265-
} catch let error as NSError {
266-
// The error code is a CocoaError
267-
if error.code != CocoaError.fileNoSuchFile.rawValue {
268-
return false
269-
}
265+
} catch {
266+
// The error code is a CocoaError
267+
if (error as? NSError)?.code != CocoaError.fileNoSuchFile.rawValue {
268+
return false
269+
}
270270
}
271271

272272
#if os(Android)

TestFoundation/Utilities.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,12 @@ func shouldAttemptXFailTests(_ reason: String) -> Bool {
456456
}
457457
}
458458

459+
func appendTestCaseExpectedToFail<T: XCTestCase>(_ reason: String, _ allTests: [(String, (T) -> () throws -> Void)], into array: inout [XCTestCaseEntry]) {
460+
if shouldAttemptXFailTests(reason) {
461+
array.append(testCase(allTests))
462+
}
463+
}
464+
459465
func testExpectedToFail<T>(_ test: @escaping (T) -> () throws -> Void, _ reason: String) -> (T) -> () throws -> Void {
460466
if shouldAttemptXFailTests(reason) {
461467
return test

TestFoundation/main.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ _ = signal(SIGPIPE, SIG_IGN)
2121
#endif
2222

2323
// For the Swift version of the Foundation tests, we must manually list all test cases here.
24-
XCTMain([
24+
var allTestCases = [
2525
testCase(TestAffineTransform.allTests),
2626
testCase(TestNSArray.allTests),
2727
testCase(TestBundle.allTests),
@@ -80,7 +80,7 @@ XCTMain([
8080
testCase(TestNSTextCheckingResult.allTests),
8181
testCase(TestTimer.allTests),
8282
testCase(TestTimeZone.allTests),
83-
testCase(TestURL.allTests),
83+
/* ⚠️ */ // testCase(TestURL.allTests),
8484
testCase(TestURLComponents.allTests),
8585
testCase(TestURLCredential.allTests),
8686
testCase(TestURLProtectionSpace.allTests),
@@ -112,4 +112,10 @@ XCTMain([
112112
testCase(TestDimension.allTests),
113113
testCase(TestMeasurement.allTests),
114114
testCase(TestNSLock.allTests),
115-
])
115+
]
116+
117+
appendTestCaseExpectedToFail("TestURL is not deleting its temporary directory correctly. https://bugs.swift.org/browse/SR-10538",
118+
TestURL.allTests,
119+
into: &allTestCases)
120+
121+
XCTMain(allTestCases)

0 commit comments

Comments
 (0)