88//
99
1010
11-
1211#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
1312 import Foundation
1413 import XCTest
1817#endif
1918
2019
20+ internal func testBundle( ) -> Bundle {
21+ #if DARWIN_COMPATIBILITY_TESTS
22+ for bundle in Bundle . allBundles {
23+ if let bundleId = bundle. bundleIdentifier, bundleId == " org.swift.DarwinCompatibilityTests " , bundle. resourcePath != nil {
24+ return bundle
25+ }
26+ }
27+ fatalError ( " Cant find test bundle " )
28+ #else
29+ return Bundle . main
30+ #endif
31+ }
32+
2133
2234class TestBundle : XCTestCase {
2335
@@ -36,29 +48,35 @@ class TestBundle : XCTestCase {
3648 }
3749
3850 func test_paths( ) {
39- let bundle = Bundle . main
40-
51+ let bundle = testBundle ( )
52+
4153 // bundlePath
4254 XCTAssert ( !bundle. bundlePath. isEmpty)
4355 XCTAssertEqual ( bundle. bundleURL. path, bundle. bundlePath)
4456 let path = bundle. bundlePath
45-
57+
4658 // etc
4759 #if os(OSX)
4860 XCTAssertEqual ( " \( path) /Contents/Resources " , bundle. resourcePath)
61+ #if DARWIN_COMPATIBILITY_TESTS
62+ XCTAssertEqual ( " \( path) /Contents/MacOS/DarwinCompatibilityTests " , bundle. executablePath)
63+ #else
4964 XCTAssertEqual ( " \( path) /Contents/MacOS/TestFoundation " , bundle. executablePath)
65+ #endif
5066 XCTAssertEqual ( " \( path) /Contents/Frameworks " , bundle. privateFrameworksPath)
5167 XCTAssertEqual ( " \( path) /Contents/SharedFrameworks " , bundle. sharedFrameworksPath)
5268 XCTAssertEqual ( " \( path) /Contents/SharedSupport " , bundle. sharedSupportPath)
5369 #endif
5470
5571 XCTAssertNil ( bundle. path ( forAuxiliaryExecutable: " no_such_file " ) )
72+ #if !DARWIN_COMPATIBILITY_TESTS
5673 XCTAssertNil ( bundle. appStoreReceiptURL)
74+ #endif
5775 }
5876
5977 func test_resources( ) {
60- let bundle = Bundle . main
61-
78+ let bundle = testBundle ( )
79+
6280 // bad resources
6381 XCTAssertNil ( bundle. url ( forResource: nil , withExtension: nil , subdirectory: nil ) )
6482 XCTAssertNil ( bundle. url ( forResource: " " , withExtension: " " , subdirectory: nil ) )
@@ -77,24 +95,34 @@ class TestBundle : XCTestCase {
7795 }
7896
7997 func test_infoPlist( ) {
80- let bundle = Bundle . main
98+ let bundle = testBundle ( )
8199
82100 // bundleIdentifier
101+ #if DARWIN_COMPATIBILITY_TESTS
102+ XCTAssertEqual ( " org.swift.DarwinCompatibilityTests " , bundle. bundleIdentifier)
103+ #else
83104 XCTAssertEqual ( " org.swift.TestFoundation " , bundle. bundleIdentifier)
84-
105+ #endif
106+
85107 // infoDictionary
86108 let info = bundle. infoDictionary
87109 XCTAssertNotNil ( info)
88- XCTAssert ( " org.swift.TestFoundation " == info![ " CFBundleIdentifier " ] as! String )
110+
111+ #if DARWIN_COMPATIBILITY_TESTS
112+ XCTAssert ( " DarwinCompatibilityTests " == info![ " CFBundleName " ] as! String )
113+ XCTAssert ( " org.swift.DarwinCompatibilityTests " == info![ " CFBundleIdentifier " ] as! String )
114+ #else
89115 XCTAssert ( " TestFoundation " == info![ " CFBundleName " ] as! String )
90-
116+ XCTAssert ( " org.swift.TestFoundation " == info![ " CFBundleIdentifier " ] as! String )
117+ #endif
118+
91119 // localizedInfoDictionary
92120 XCTAssertNil ( bundle. localizedInfoDictionary) // FIXME: Add a localized Info.plist for testing
93121 }
94122
95123 func test_localizations( ) {
96- let bundle = Bundle . main
97-
124+ let bundle = testBundle ( )
125+
98126 XCTAssertEqual ( [ " en " ] , bundle. localizations)
99127 XCTAssertEqual ( [ " en " ] , bundle. preferredLocalizations)
100128 XCTAssertEqual ( [ " en " ] , Bundle . preferredLocalizations ( from: [ " en " , " pl " , " es " ] ) )
@@ -196,6 +224,4 @@ class TestBundle : XCTestCase {
196224 XCTAssertThrowsError ( try bundle!. preflight ( ) )
197225 _cleanupPlayground ( playground)
198226 }
199-
200-
201227}
0 commit comments