Skip to content

Commit fbe5ec3

Browse files
committed
Replace Bundle.main with testBundle()
1 parent 5d04589 commit fbe5ec3

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

TestFoundation/TestBundle.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
//
99

1010

11-
1211
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
1312
import Foundation
1413
import XCTest
@@ -18,6 +17,9 @@
1817
#endif
1918

2019

20+
internal func testBundle() -> Bundle {
21+
return Bundle.main
22+
}
2123

2224
class TestBundle : XCTestCase {
2325

@@ -36,29 +38,35 @@ class TestBundle : XCTestCase {
3638
}
3739

3840
func test_paths() {
39-
let bundle = Bundle.main
40-
41+
let bundle = testBundle()
42+
4143
// bundlePath
4244
XCTAssert(!bundle.bundlePath.isEmpty)
4345
XCTAssertEqual(bundle.bundleURL.path, bundle.bundlePath)
4446
let path = bundle.bundlePath
45-
47+
4648
// etc
4749
#if os(OSX)
4850
XCTAssertEqual("\(path)/Contents/Resources", bundle.resourcePath)
51+
#if DARWIN_COMPATIBILITY_TESTS
52+
XCTAssertEqual("\(path)/Contents/MacOS/DarwinCompatibilityTests", bundle.executablePath)
53+
#else
4954
XCTAssertEqual("\(path)/Contents/MacOS/TestFoundation", bundle.executablePath)
55+
#endif
5056
XCTAssertEqual("\(path)/Contents/Frameworks", bundle.privateFrameworksPath)
5157
XCTAssertEqual("\(path)/Contents/SharedFrameworks", bundle.sharedFrameworksPath)
5258
XCTAssertEqual("\(path)/Contents/SharedSupport", bundle.sharedSupportPath)
5359
#endif
5460

5561
XCTAssertNil(bundle.path(forAuxiliaryExecutable: "no_such_file"))
62+
#if !DARWIN_COMPATIBILITY_TESTS
5663
XCTAssertNil(bundle.appStoreReceiptURL)
64+
#endif
5765
}
5866

5967
func test_resources() {
60-
let bundle = Bundle.main
61-
68+
let bundle = testBundle()
69+
6270
// bad resources
6371
XCTAssertNil(bundle.url(forResource: nil, withExtension: nil, subdirectory: nil))
6472
XCTAssertNil(bundle.url(forResource: "", withExtension: "", subdirectory: nil))
@@ -77,7 +85,7 @@ class TestBundle : XCTestCase {
7785
}
7886

7987
func test_infoPlist() {
80-
let bundle = Bundle.main
88+
let bundle = testBundle()
8189

8290
// bundleIdentifier
8391
XCTAssertEqual("org.swift.TestFoundation", bundle.bundleIdentifier)
@@ -93,8 +101,8 @@ class TestBundle : XCTestCase {
93101
}
94102

95103
func test_localizations() {
96-
let bundle = Bundle.main
97-
104+
let bundle = testBundle()
105+
98106
XCTAssertEqual(["en"], bundle.localizations)
99107
XCTAssertEqual(["en"], bundle.preferredLocalizations)
100108
XCTAssertEqual(["en"], Bundle.preferredLocalizations(from: ["en", "pl", "es"]))
@@ -158,13 +166,13 @@ class TestBundle : XCTestCase {
158166
}
159167

160168
func test_bundleLoad(){
161-
let bundle = Bundle.main
169+
let bundle = testBundle()
162170
let _ = bundle.load()
163171
XCTAssertTrue(bundle.isLoaded)
164172
}
165173

166174
func test_bundleLoadWithError(){
167-
let bundleValid = Bundle.main
175+
let bundleValid = testBundle()
168176
//test valid load using loadAndReturnError
169177
do{
170178
try bundleValid.loadAndReturnError()
@@ -184,7 +192,7 @@ class TestBundle : XCTestCase {
184192
}
185193

186194
func test_bundlePreflight(){
187-
let bundleValid = Bundle.main
195+
let bundleValid = testBundle()
188196
do{
189197
try bundleValid.preflight()
190198
}catch{

TestFoundation/TestHTTPCookieStorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class TestHTTPCookieStorage: XCTestCase {
256256
storage.setCookie(testCookie)
257257
XCTAssertEqual(storage.cookies!.count, 1)
258258
var destPath: String
259-
let bundlePath = Bundle.main.bundlePath
259+
let bundlePath = testBundle().bundlePath
260260
var bundleName = "/" + bundlePath.components(separatedBy: "/").last!
261261
if let range = bundleName.range(of: ".", options: String.CompareOptions.backwards, range: nil, locale: nil) {
262262
bundleName = String(bundleName[..<range.lowerBound])

TestFoundation/TestNSData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ class TestNSData: XCTestCase {
517517
}
518518

519519
func test_writeToURLOptions() {
520-
let saveData = try! Data(contentsOf: Bundle.main.url(forResource: "Test", withExtension: "plist")!)
520+
let saveData = try! Data(contentsOf: testBundle().url(forResource: "Test", withExtension: "plist")!)
521521
let savePath = URL(fileURLWithPath: NSTemporaryDirectory() + "Test1.plist")
522522
do {
523523
try saveData.write(to: savePath, options: .atomic)

TestFoundation/main.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ import SwiftXCTest
2222
#endif
2323

2424

25-
internal func testBundle() -> Bundle {
26-
return Bundle.main
27-
}
28-
2925
// ignore SIGPIPE which is sent when writing to closed file descriptors.
3026
_ = signal(SIGPIPE, SIG_IGN)
3127

0 commit comments

Comments
 (0)