Skip to content

Commit ef0828e

Browse files
committed
[DarwinCompatibility] Minor fixes for DarwinCompatibility tests
- un-XFAIL some Darwin tests that run on 10.13.3 - Process.executableURL only available on 10.13 - Dont deallocate an autoreleasing pointer on Darwin. - Add TestBundle.testBundleName() to handle 'TestFoundation' v 'DarwinCompatibiltyTests' naming.
1 parent 6fb308c commit ef0828e

11 files changed

+30
-21
lines changed

DarwinCompatibilityTests.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@
702702
CLANG_ENABLE_MODULES = YES;
703703
CODE_SIGN_STYLE = Automatic;
704704
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
705-
MACOSX_DEPLOYMENT_TARGET = 10.12;
705+
MACOSX_DEPLOYMENT_TARGET = 10.13;
706706
OTHER_SWIFT_FLAGS = "";
707707
"OTHER_SWIFT_FLAGS[arch=*]" = "";
708708
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -717,7 +717,7 @@
717717
CLANG_ENABLE_MODULES = YES;
718718
CODE_SIGN_STYLE = Automatic;
719719
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
720-
MACOSX_DEPLOYMENT_TARGET = 10.12;
720+
MACOSX_DEPLOYMENT_TARGET = 10.13;
721721
OTHER_SWIFT_FLAGS = "";
722722
PRODUCT_NAME = "$(TARGET_NAME)";
723723
SWIFT_VERSION = 4.0;

DarwinCompatibilityTests/DarwinShims.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extension Thread {
5050
extension Scanner {
5151
public func scanString(_ searchString: String) -> String? {
5252
var result: NSString? = nil
53-
if scanString(string, into: &result), let str = result {
53+
if scanString(searchString, into: &result), let str = result {
5454
return str as String
5555
}
5656
return nil

TestFoundation/TestBundle.swift

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ internal func testBundle() -> Bundle {
3131
#endif
3232
}
3333

34+
internal func testBundleName() -> String {
35+
// Either 'TestFoundation' or 'DarwinCompatibilityTests'
36+
return testBundle().infoDictionary!["CFBundleName"] as! String
37+
}
38+
3439
class BundlePlayground {
3540
enum Layout {
3641
case flat

TestFoundation/TestCodable.swift

-2
Original file line numberDiff line numberDiff line change
@@ -561,15 +561,13 @@ class TestCodable : XCTestCase {
561561
]
562562

563563
func test_URLComponents_JSON() {
564-
#if !DARWIN_COMPATIBILITY_TESTS // crashes on native Darwin
565564
for (components) in urlComponentsValues {
566565
do {
567566
try expectRoundTripEqualityThroughJSON(for: components)
568567
} catch let error {
569568
XCTFail("\(error)")
570569
}
571570
}
572-
#endif
573571
}
574572
}
575573

TestFoundation/TestFileManager.swift

+3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ class TestFileManager : XCTestCase {
155155
XCTAssertEqual(UInt8(bitPattern: result[0]), 0xE2)
156156
XCTAssertEqual(UInt8(bitPattern: result[1]), 0x98)
157157
XCTAssertEqual(UInt8(bitPattern: result[2]), 0x83)
158+
159+
#if !DARWIN_COMPATIBILITY_TESTS // auto-released by Darwin's Foundation
158160
result.deallocate()
161+
#endif
159162
}
160163

161164
func test_fileAttributes() {

TestFoundation/TestNSData.swift

-4
Original file line numberDiff line numberDiff line change
@@ -4110,15 +4110,13 @@ extension TestNSData {
41104110
}
41114111

41124112
func test_validateMutation_slice_mutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound() {
4113-
#if !DARWIN_COMPATIBILITY_TESTS // Crashes on native Darwin
41144113
var base = Data(referencing: NSData(bytes: "hello world", length: 11))
41154114
base.append(contentsOf: [1, 2, 3, 4, 5, 6])
41164115
var data = base[4..<6]
41174116
data.withUnsafeMutableBytes { (ptr: UnsafeMutablePointer<UInt8>) in
41184117
ptr.advanced(by: 1).pointee = 0xFF
41194118
}
41204119
XCTAssertEqual(data[data.startIndex.advanced(by: 1)], 0xFF)
4121-
#endif
41224120
}
41234121

41244122
func test_validateMutation_slice_customBacking_withUnsafeMutableBytes_lengthLessThanLowerBound() {
@@ -4130,15 +4128,13 @@ extension TestNSData {
41304128
}
41314129

41324130
func test_validateMutation_slice_customMutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound() {
4133-
#if !DARWIN_COMPATIBILITY_TESTS // Crashes on native Darwin
41344131
var base = Data(referencing: AllOnesData(length: 1))
41354132
base.count = 10
41364133
var data = base[4..<6]
41374134
data.withUnsafeMutableBytes { (ptr: UnsafeMutablePointer<UInt8>) in
41384135
ptr.advanced(by: 1).pointee = 0xFF
41394136
}
41404137
XCTAssertEqual(data[data.startIndex.advanced(by: 1)], 0xFF)
4141-
#endif
41424138
}
41434139
}
41444140

TestFoundation/TestNSError.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class TestNSError : XCTestCase {
5050
}
5151

5252
func test_CustomNSError_domain() {
53-
XCTAssertEqual(SwiftCustomNSError.errorDomain, "TestFoundation.SwiftCustomNSError")
53+
let name = testBundleName()
54+
XCTAssertEqual(SwiftCustomNSError.errorDomain, "\(name).SwiftCustomNSError")
5455
}
5556

5657
func test_CustomNSError_userInfo() {

TestFoundation/TestObjCRuntime.swift

+5-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ class TestObjCRuntime: XCTestCase {
3232
}
3333

3434
func testStringFromClass() {
35+
let name = testBundleName()
3536
XCTAssertEqual(NSStringFromClass(NSObject.self), "NSObject")
36-
XCTAssertEqual(NSStringFromClass(SwiftClass.self), "TestFoundation.SwiftClass")
37+
XCTAssertEqual(NSStringFromClass(SwiftClass.self), "\(name).SwiftClass")
3738
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
3839
XCTAssertEqual(NSStringFromClass(XCTestCase.self), "XCTest.XCTestCase");
3940
#else
@@ -42,9 +43,10 @@ class TestObjCRuntime: XCTestCase {
4243
}
4344

4445
func testClassFromString() {
46+
let name = testBundleName()
4547
XCTAssertNotNil(NSClassFromString("NSObject"))
46-
XCTAssertNotNil(NSClassFromString("TestFoundation.SwiftClass"))
47-
XCTAssertNil(NSClassFromString("TestFoundation.SwiftClass.InnerClass"))
48+
XCTAssertNotNil(NSClassFromString("\(name).SwiftClass"))
49+
XCTAssertNil(NSClassFromString("\(name).SwiftClass.InnerClass"))
4850
XCTAssertNil(NSClassFromString("SwiftClass"))
4951
XCTAssertNil(NSClassFromString("MadeUpClassName"))
5052
XCTAssertNil(NSClassFromString("SwiftStruct"));

TestFoundation/TestProcess.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ class TestProcess : XCTestCase {
4646
let process = Process()
4747

4848
let executablePath = "/bin/bash"
49-
process.executableURL = URL(fileURLWithPath: executablePath)
50-
49+
if #available(OSX 10.13, *) {
50+
process.executableURL = URL(fileURLWithPath: executablePath)
51+
} else {
52+
// Fallback on earlier versions
53+
process.launchPath = executablePath
54+
}
5155
XCTAssertEqual(executablePath, process.launchPath)
52-
56+
5357
process.arguments = ["-c", "exit 0"]
5458
process.launch()
5559
process.waitUntilExit()

TestFoundation/TestProcessInfo.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ class TestProcessInfo : XCTestCase {
4141
// Assert that the original process name is "TestFoundation". This test
4242
// will fail if the test target ever gets renamed, so maybe it should
4343
// just test that the initial name is not empty or something?
44-
let processInfo = ProcessInfo.processInfo
44+
#if DARWIN_COMPATIBILITY_TESTS
45+
let targetName = "xctest"
46+
#else
4547
let targetName = "TestFoundation"
48+
#endif
49+
let processInfo = ProcessInfo.processInfo
4650
let originalProcessName = processInfo.processName
4751
XCTAssertEqual(originalProcessName, targetName, "\"\(originalProcessName)\" not equal to \"TestFoundation\"")
4852

TestFoundation/TestUserDefaults.swift

-4
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,12 @@ class TestUserDefaults : XCTestCase {
180180
}
181181

182182
func test_setValue_String() {
183-
#if !DARWIN_COMPATIBILITY_TESTS // Works if run on its own, hangs if all tests in class are run
184183
let defaults = UserDefaults.standard
185184

186185
// Register a String value. UserDefaults.string(forKey:) is supposed to return the String
187186
defaults.set("hello", forKey: "key1")
188187

189188
XCTAssertEqual(defaults.string(forKey: "key1"), "hello")
190-
#endif
191189
}
192190

193191
func test_setValue_NSURL() {
@@ -200,14 +198,12 @@ class TestUserDefaults : XCTestCase {
200198
}
201199

202200
func test_setValue_URL() {
203-
#if !DARWIN_COMPATIBILITY_TESTS // Works if run on its own, hangs if all tests in class are run
204201
let defaults = UserDefaults.standard
205202

206203
// Set a URL value. UserDefaults.url(forKey:) is supposed to return the URL
207204
defaults.set(URL(fileURLWithPath: "/hello/world"), forKey: "key1")
208205

209206
XCTAssertEqual(defaults.url(forKey: "key1"), URL(fileURLWithPath: "/hello/world"))
210-
#endif
211207
}
212208

213209
func test_setValue_NSData() {

0 commit comments

Comments
 (0)