Skip to content

Commit 180cb2f

Browse files
committed
Test fixes:
- Add infrastructure to mark a test as XFAIL. You can set the `NS_FOUNDATION_ATTEMPT_XFAIL_TESTS` environment variable to `YES` to attempt them. - TestFileManager fails to find a creationDate on kernel >= 4.11.0 in Docker. Mark this as XFAIL; - test_substringFromCFString is crashing on Ubuntu 14.04. Mark this as XFAIL. - test_FromContentsOfURL is failing in CI occasionally. Mark this as XFAIL.
1 parent 92bbdd1 commit 180cb2f

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

TestFoundation/TestFileManager.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,20 @@ class TestFileManager : XCTestCase {
353353
XCTAssertNotNil(fileGroupOwnerAccountID)
354354

355355
#if os(Linux)
356-
let requiredVersion = OperatingSystemVersion(majorVersion: 4, minorVersion: 11, patchVersion: 0)
357-
let creationDate = attrs[.creationDate] as? Date
358-
if ProcessInfo.processInfo.isOperatingSystemAtLeast(requiredVersion) {
359-
XCTAssertNotNil(creationDate)
360-
XCTAssertGreaterThan(Date().timeIntervalSince1970, try creationDate.unwrapped().timeIntervalSince1970)
361-
} else {
362-
XCTAssertNil(creationDate)
356+
/* ⚠️ */
357+
if shouldAttemptXFailTests("Checking that .creationDate is set is failing on Ubuntu 16.04 when running from a Docker image. https://bugs.swift.org/browse/SR-10512") {
358+
let requiredVersion = OperatingSystemVersion(majorVersion: 4, minorVersion: 11, patchVersion: 0)
359+
let creationDate = attrs[.creationDate] as? Date
360+
if ProcessInfo.processInfo.isOperatingSystemAtLeast(requiredVersion) {
361+
XCTAssertNotNil(creationDate)
362+
XCTAssertGreaterThan(Date().timeIntervalSince1970, try creationDate.unwrapped().timeIntervalSince1970)
363+
} else {
364+
XCTAssertNil(creationDate)
365+
}
363366
}
367+
/* ⚠️ */
364368
#endif
369+
365370
if let fileOwnerAccountName = attrs[.ownerAccountName] {
366371
XCTAssertNotNil(fileOwnerAccountName as? String)
367372
if let fileOwnerAccountNameStr = fileOwnerAccountName as? String {

TestFoundation/TestNSString.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class TestNSString: LoopbackServerTest {
5555
("test_longLongValue", test_longLongValue ),
5656
("test_rangeOfCharacterFromSet", test_rangeOfCharacterFromSet ),
5757
("test_CFStringCreateMutableCopy", test_CFStringCreateMutableCopy),
58-
("test_FromContentsOfURL",test_FromContentsOfURL),
58+
/* ⚠️ */ ("test_FromContentsOfURL", testExpectedToFail(test_FromContentsOfURL,
59+
/* ⚠️ */ "test_FromContentsOfURL is flaky on CI, with unclear causes. https://bugs.swift.org/browse/SR-10514")),
5960
("test_FromContentOfFileUsedEncodingIgnored", test_FromContentOfFileUsedEncodingIgnored),
6061
("test_FromContentOfFileUsedEncodingUTF8", test_FromContentOfFileUsedEncodingUTF8),
6162
("test_FromContentsOfURLUsedEncodingUTF16BE", test_FromContentsOfURLUsedEncodingUTF16BE),
@@ -92,7 +93,8 @@ class TestNSString: LoopbackServerTest {
9293
("test_replacingOccurrences", test_replacingOccurrences),
9394
("test_getLineStart", test_getLineStart),
9495
("test_substringWithRange", test_substringWithRange),
95-
("test_substringFromCFString", test_substringFromCFString),
96+
/* ⚠️ */ ("test_substringFromCFString", testExpectedToFail(test_substringFromCFString,
97+
/* ⚠️ */ "test_substringFromCFString is crashing unexpectedly on Ubuntu 14.04, possibly as a regression of something upstream. https://bugs.swift.org/browse/SR-10513")),
9698
("test_createCopy", test_createCopy),
9799
("test_commonPrefix", test_commonPrefix),
98100
("test_lineRangeFor", test_lineRangeFor),

TestFoundation/Utilities.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,24 @@ public func checkHashableGroups<Groups: Collection>(
442442
file: file,
443443
line: line)
444444
}
445+
446+
private var shouldRunXFailTests: Bool {
447+
return ProcessInfo.processInfo.environment["NS_FOUNDATION_ATTEMPT_XFAIL_TESTS"] == "YES"
448+
}
449+
450+
func shouldAttemptXFailTests(_ reason: String) -> Bool {
451+
if shouldRunXFailTests {
452+
return true
453+
} else {
454+
try? FileHandle.standardError.write(contentsOf: Data("warning: Skipping test expected to fail with reason '\(reason)'\n".utf8))
455+
return false
456+
}
457+
}
458+
459+
func testExpectedToFail<T>(_ test: @escaping (T) -> () throws -> Void, _ reason: String) -> (T) -> () throws -> Void {
460+
if shouldAttemptXFailTests(reason) {
461+
return test
462+
} else {
463+
return { _ in return { } }
464+
}
465+
}

0 commit comments

Comments
 (0)