Skip to content

Commit a66193f

Browse files
committed
Only enable testing requiring @testable import if it’s actually available.
Additionally: allow building in Release correctly during development on Darwin.
1 parent 850b65f commit a66193f

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

Foundation.xcodeproj/project.pbxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2207,7 +2207,7 @@
22072207
);
22082208
runOnlyForDeploymentPostprocessing = 0;
22092209
shellPath = /bin/sh;
2210-
shellScript = "cp ${BUILD_ROOT}/Debug/xdgTestHelper.app/Contents/MacOS/xdgTestHelper ${BUILD_ROOT}/Debug/TestFoundation.app/Contents/MacOS/";
2210+
shellScript = "cp ${BUILT_PRODUCTS_DIR}/xdgTestHelper.app/Contents/MacOS/xdgTestHelper ${BUILT_PRODUCTS_DIR}/TestFoundation.app/Contents/MacOS/\n";
22112211
};
22122212
/* End PBXShellScriptBuildPhase section */
22132213

@@ -2650,6 +2650,7 @@
26502650
MTL_ENABLE_DEBUG_INFO = YES;
26512651
ONLY_ACTIVE_ARCH = YES;
26522652
SDKROOT = macosx;
2653+
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT DEBUG";
26532654
VERSIONING_SYSTEM = "apple-generic";
26542655
VERSION_INFO_PREFIX = "";
26552656
};

TestFoundation/TestFileManager.swift

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10-
#if !DEPLOYMENT_RUNTIME_OBJC && (os(Linux) || os(Android))
11-
@testable import Foundation
12-
#else
13-
@testable import SwiftFoundation
10+
#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
11+
#if (os(Linux) || os(Android))
12+
@testable import Foundation
13+
#else
14+
@testable import SwiftFoundation
15+
#endif
1416
#endif
1517

1618
class TestFileManager : XCTestCase {
@@ -35,13 +37,18 @@ class TestFileManager : XCTestCase {
3537
("test_temporaryDirectoryForUser", test_temporaryDirectoryForUser),
3638
("test_creatingDirectoryWithShortIntermediatePath", test_creatingDirectoryWithShortIntermediatePath),
3739
("test_mountedVolumeURLs", test_mountedVolumeURLs),
38-
("test_XDGStopgapsCoverAllConstants", test_XDGStopgapsCoverAllConstants),
3940
]
4041

41-
#if !DEPLOYMENT_RUNTIME_OBJC
42+
#if !DEPLOYMENT_RUNTIME_OBJC && NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
4243
tests.append(contentsOf: [
44+
("test_xdgStopgapsCoverAllConstants", test_xdgStopgapsCoverAllConstants),
4345
("test_parseXDGConfiguration", test_parseXDGConfiguration),
4446
("test_xdgURLSelection", test_xdgURLSelection),
47+
])
48+
#endif
49+
50+
#if !DEPLOYMENT_RUNTIME_OBJC
51+
tests.append(contentsOf: [
4552
("test_fetchXDGPathsFromHelper", test_fetchXDGPathsFromHelper),
4653
])
4754
#endif
@@ -965,7 +972,9 @@ class TestFileManager : XCTestCase {
965972
}
966973

967974
#if !DEPLOYMENT_RUNTIME_OBJC // XDG tests require swift-corelibs-foundation
968-
func test_XDGStopgapsCoverAllConstants() {
975+
976+
#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT // These are white box tests for the internals of XDG parsing:
977+
func test_xdgStopgapsCoverAllConstants() {
969978
let stopgaps = _XDGUserDirectory.stopgapDefaultDirectoryURLs
970979
for directory in _XDGUserDirectory.allDirectories {
971980
XCTAssertNotNil(stopgaps[directory])
@@ -1076,6 +1085,9 @@ VIDEOS=StopgapVideos
10761085
assertSameAbsolutePath(_XDGUserDirectory.publicShare.url(userConfiguration: configuration, osDefaultConfiguration: osDefaults, stopgaps: stopgaps), home.appendingPathComponent("SystemPublicShare"))
10771086
assertSameAbsolutePath(_XDGUserDirectory.music.url(userConfiguration: configuration, osDefaultConfiguration: osDefaults, stopgaps: stopgaps), home.appendingPathComponent("StopgapMusic"))
10781087
}
1088+
#endif // NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
1089+
1090+
// This test below is a black box test, and does not require @testable import.
10791091

10801092
enum TestError: Error {
10811093
case notImplementedOnThisPlatform

lib/script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def generate_products(self):
124124
swift_flags += """
125125
TARGET_SWIFTEXE_FLAGS = -I${SDKROOT}/lib/swift/""" + Configuration.current.target.swift_sdk_name + """ -L${SDKROOT}/lib/swift/""" + Configuration.current.target.swift_sdk_name + """ """
126126
if Configuration.current.build_mode == Configuration.Debug:
127-
swift_flags += "-g -Onone -enable-testing "
127+
swift_flags += "-g -Onone -enable-testing -DNS_FOUNDATION_ALLOWS_TESTABLE_IMPORT "
128128
elif Configuration.current.build_mode == Configuration.Release:
129129
swift_flags += " "
130130
swift_flags += Configuration.current.extra_swift_flags

0 commit comments

Comments
 (0)