Skip to content

Commit db319a3

Browse files
committed
Foundation: add ProcessInfo SPI for tests
Add the `_processPath` computed property on `ProcessInfo` to allow the tests to access `_CFProcessPath`. This removes the last CoreFoundation API usage in the test suite, allowing it to build on Windows which does not provide the CoreFoundation APIs to users.
1 parent 3708a15 commit db319a3

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Foundation/ProcessInfo.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,10 @@ open class ProcessInfo: NSObject {
196196
return NSFullUserName()
197197
}
198198
}
199+
200+
// SPI for TestFoundation
201+
internal extension ProcessInfo {
202+
var _processPath: String {
203+
return String(cString: _CFProcessPath())
204+
}
205+
}

TestFoundation/TestBundle.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class BundlePlayground {
340340
class TestBundle : XCTestCase {
341341

342342
static var allTests: [(String, (TestBundle) -> () throws -> Void)] {
343-
return [
343+
var tests: [(String, (TestBundle) -> () throws -> Void)] = [
344344
("test_paths", test_paths),
345345
("test_resources", test_resources),
346346
("test_infoPlist", test_infoPlist),
@@ -353,10 +353,17 @@ class TestBundle : XCTestCase {
353353
("test_bundleFindExecutable", test_bundleFindExecutable),
354354
("test_bundleFindAuxiliaryExecutables", test_bundleFindAuxiliaryExecutables),
355355
("test_bundleReverseBundleLookup", test_bundleReverseBundleLookup),
356-
("test_mainBundleExecutableURL", test_mainBundleExecutableURL),
357356
]
357+
358+
#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
359+
tests.append(contentsOf: [
360+
("test_mainBundleExecutableURL", test_mainBundleExecutableURL),
361+
])
362+
#endif
363+
364+
return tests
358365
}
359-
366+
360367
func test_paths() {
361368
let bundle = testBundle()
362369

@@ -560,13 +567,15 @@ class TestBundle : XCTestCase {
560567
}
561568
}
562569

570+
#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
563571
func test_mainBundleExecutableURL() {
564572
#if !DARWIN_COMPATIBILITY_TESTS // _CFProcessPath() is unavailable on native Foundation
565573
let maybeURL = Bundle.main.executableURL
566574
XCTAssertNotNil(maybeURL)
567575
guard let url = maybeURL else { return }
568576

569-
XCTAssertEqual(url.path, String(cString: _CFProcessPath()))
577+
XCTAssertEqual(url.path, ProcessInfo.processInfo._processPath)
570578
#endif
571579
}
580+
#endif
572581
}

0 commit comments

Comments
 (0)