Skip to content

Foundation: add ProcessInfo SPI for tests #2141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Foundation/ProcessInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,10 @@ open class ProcessInfo: NSObject {
return NSFullUserName()
}
}

// SPI for TestFoundation
internal extension ProcessInfo {
var _processPath: String {
return String(cString: _CFProcessPath())
}
}
17 changes: 13 additions & 4 deletions TestFoundation/TestBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class BundlePlayground {
class TestBundle : XCTestCase {

static var allTests: [(String, (TestBundle) -> () throws -> Void)] {
return [
var tests: [(String, (TestBundle) -> () throws -> Void)] = [
("test_paths", test_paths),
("test_resources", test_resources),
("test_infoPlist", test_infoPlist),
Expand All @@ -353,10 +353,17 @@ class TestBundle : XCTestCase {
("test_bundleFindExecutable", test_bundleFindExecutable),
("test_bundleFindAuxiliaryExecutables", test_bundleFindAuxiliaryExecutables),
("test_bundleReverseBundleLookup", test_bundleReverseBundleLookup),
("test_mainBundleExecutableURL", test_mainBundleExecutableURL),
]

#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
tests.append(contentsOf: [
("test_mainBundleExecutableURL", test_mainBundleExecutableURL),
])
#endif

return tests
}

func test_paths() {
let bundle = testBundle()

Expand Down Expand Up @@ -560,13 +567,15 @@ class TestBundle : XCTestCase {
}
}

#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
func test_mainBundleExecutableURL() {
#if !DARWIN_COMPATIBILITY_TESTS // _CFProcessPath() is unavailable on native Foundation
let maybeURL = Bundle.main.executableURL
XCTAssertNotNil(maybeURL)
guard let url = maybeURL else { return }

XCTAssertEqual(url.path, String(cString: _CFProcessPath()))
XCTAssertEqual(url.path, ProcessInfo.processInfo._processPath)
#endif
}
#endif
}