Skip to content

Commit 0870e68

Browse files
committed
DarwinCompatibility: Update tests to compile against native Foundation
1 parent 2df7895 commit 0870e68

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

DarwinCompatibilityTests.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
B98E33DF2136AC120044EBE9 /* TestFileWithZeros.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = TestFileWithZeros.txt; path = TestFoundation/Resources/TestFileWithZeros.txt; sourceTree = "<group>"; };
191191
B99EAE6E23602FFA00C8FB46 /* TestsToSkip.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TestsToSkip.txt; sourceTree = "<group>"; };
192192
B99EAE6F23602FFA00C8FB46 /* xcode-build.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = "xcode-build.sh"; sourceTree = "<group>"; };
193+
B99EAE742360577C00C8FB46 /* TestCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestCodable.swift; path = TestFoundation/TestCodable.swift; sourceTree = "<group>"; };
193194
B9C1C63322607372002BBEA0 /* FixtureValues.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FixtureValues.swift; path = TestFoundation/FixtureValues.swift; sourceTree = "<group>"; };
194195
B9C89ED11F6BF67C00087AF4 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
195196
B9C89ED71F6BF77E00087AF4 /* DarwinCompatibilityTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DarwinCompatibilityTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -326,6 +327,7 @@
326327
B9C89EB81F6BF47D00087AF4 = {
327328
isa = PBXGroup;
328329
children = (
330+
B99EAE742360577C00C8FB46 /* TestCodable.swift */,
329331
B906C30322AC6E2A00FCFA2D /* FTPServer.swift */,
330332
B906C2FF22AC6CE600FCFA2D /* TestNSSortDescriptor.swift */,
331333
B906C30022AC6CE600FCFA2D /* TestURLSessionFTP.swift */,
@@ -610,6 +612,7 @@
610612
isa = PBXSourcesBuildPhase;
611613
buildActionMask = 2147483647;
612614
files = (
615+
B9C89F411F6BF89C00087AF4 /* TestCodable.swift in Sources */,
613616
B906C30422AC6E2A00FCFA2D /* FTPServer.swift in Sources */,
614617
B906C30122AC6CE700FCFA2D /* TestNSSortDescriptor.swift in Sources */,
615618
B906C30222AC6CE700FCFA2D /* TestURLSessionFTP.swift in Sources */,
@@ -642,7 +645,6 @@
642645
B9C89F3E1F6BF89C00087AF4 /* TestISO8601DateFormatter.swift in Sources */,
643646
B9C89F3F1F6BF89C00087AF4 /* TestNSTextCheckingResult.swift in Sources */,
644647
B9C89F401F6BF89C00087AF4 /* TestCharacterSet.swift in Sources */,
645-
B9C89F411F6BF89C00087AF4 /* TestCodable.swift in Sources */,
646648
B9C89F421F6BF89C00087AF4 /* TestIndexPath.swift in Sources */,
647649
B9C89F431F6BF89C00087AF4 /* TestMassFormatter.swift in Sources */,
648650
B9C89F441F6BF89C00087AF4 /* TestNSSet.swift in Sources */,

TestFoundation/TestNSString.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,12 +1266,10 @@ class TestNSString: LoopbackServerTest {
12661266
let firstLine = string[rangeOfFirstLine]
12671267
XCTAssertEqual(firstLine, "LINE1_67あ\n")
12681268
}
1269-
}
12701269

1271-
func test_reflection() {
1272-
}
1270+
func test_reflection() {
1271+
}
12731272

1274-
extension TestNSString {
12751273
func test_replacingOccurrences() {
12761274
let testPrefix = "ab"
12771275
let testSuffix = "cd"
@@ -1342,6 +1340,8 @@ extension TestNSString {
13421340
}
13431341

13441342
func test_replacingOccurrencesInSubclass() {
1343+
// NSMutableString doesnt subclasss correctly
1344+
#if !DARWIN_COMPATIBILITY_TESTS
13451345
class TestMutableString: NSMutableString {
13461346
private var wrapped: NSMutableString
13471347
var replaceCharactersCount: Int = 0
@@ -1396,6 +1396,7 @@ extension TestNSString {
13961396
let testString = TestMutableString(stringLiteral: "ababab")
13971397
XCTAssertEqual(testString.replacingOccurrences(of: "ab", with: "xx"), "xxxxxx")
13981398
XCTAssertEqual(testString.replaceCharactersCount, 3)
1399+
#endif
13991400
}
14001401

14011402

@@ -1556,7 +1557,7 @@ extension TestNSString {
15561557
("test_ExternalRepresentation", test_ExternalRepresentation),
15571558
("test_mutableStringConstructor", test_mutableStringConstructor),
15581559
("test_emptyStringPrefixAndSuffix",test_emptyStringPrefixAndSuffix),
1559-
("test_reflection", { _ in test_reflection }),
1560+
("test_reflection", test_reflection),
15601561
("test_replacingOccurrences", test_replacingOccurrences),
15611562
("test_getLineStart", test_getLineStart),
15621563
("test_substringWithRange", test_substringWithRange),

TestFoundation/TestProcess.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ class TestProcess : XCTestCase {
8484
try process.run()
8585
let msg = try XCTUnwrap("Hello, 🐶.\n".data(using: .utf8))
8686
do {
87+
#if DARWIN_COMPATIBILITY_TESTS
88+
inputPipe.fileHandleForWriting.write(msg)
89+
#else
8790
try inputPipe.fileHandleForWriting.write(contentsOf: msg)
91+
#endif
8892
} catch {
8993
XCTFail("Cant write to pipe: \(error)")
9094
return

TestFoundation/TestRunLoop.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ class TestPort: Port {
134134
self.sentinel = sentinel
135135
super.init()
136136
}
137-
137+
138+
// Required on Darwin
139+
required init?(coder: NSCoder) {
140+
fatalError("init(coder:) has not been implemented")
141+
}
142+
138143
deinit {
139144
invalidate()
140145
sentinel()

TestFoundation/Utilities.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,11 @@ func shouldAttemptAndroidXFailTests(_ reason: String) -> Bool {
560560
#endif
561561
}
562562

563+
#if !DARWIN_COMPATIBILITY_TESTS
563564
func testCaseExpectedToFail<T: XCTestCase>(_ allTests: [(String, (T) -> () throws -> Void)], _ reason: String) -> XCTestCaseEntry {
564565
return testCase(allTests.map { ($0.0, testExpectedToFail($0.1, "This test suite is disabled: \(reason)")) })
565566
}
567+
#endif
566568

567569
func appendTestCaseExpectedToFail<T: XCTestCase>(_ reason: String, _ allTests: [(String, (T) -> () throws -> Void)], into array: inout [XCTestCaseEntry]) {
568570
if shouldAttemptXFailTests(reason) {

0 commit comments

Comments
 (0)