Skip to content

Replace Bundle.main with testBundle() for consistency. #1326

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
Nov 19, 2017
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
32 changes: 20 additions & 12 deletions TestFoundation/TestBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//



#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
Expand All @@ -18,6 +17,9 @@
#endif


internal func testBundle() -> Bundle {
return Bundle.main
}

class TestBundle : XCTestCase {

Expand All @@ -36,29 +38,35 @@ class TestBundle : XCTestCase {
}

func test_paths() {
let bundle = Bundle.main
let bundle = testBundle()

// bundlePath
XCTAssert(!bundle.bundlePath.isEmpty)
XCTAssertEqual(bundle.bundleURL.path, bundle.bundlePath)
let path = bundle.bundlePath

// etc
#if os(OSX)
XCTAssertEqual("\(path)/Contents/Resources", bundle.resourcePath)
#if DARWIN_COMPATIBILITY_TESTS
XCTAssertEqual("\(path)/Contents/MacOS/DarwinCompatibilityTests", bundle.executablePath)
#else
XCTAssertEqual("\(path)/Contents/MacOS/TestFoundation", bundle.executablePath)
#endif
XCTAssertEqual("\(path)/Contents/Frameworks", bundle.privateFrameworksPath)
XCTAssertEqual("\(path)/Contents/SharedFrameworks", bundle.sharedFrameworksPath)
XCTAssertEqual("\(path)/Contents/SharedSupport", bundle.sharedSupportPath)
#endif

XCTAssertNil(bundle.path(forAuxiliaryExecutable: "no_such_file"))
#if !DARWIN_COMPATIBILITY_TESTS
XCTAssertNil(bundle.appStoreReceiptURL)
#endif
}

func test_resources() {
let bundle = Bundle.main
let bundle = testBundle()

// bad resources
XCTAssertNil(bundle.url(forResource: nil, withExtension: nil, subdirectory: nil))
XCTAssertNil(bundle.url(forResource: "", withExtension: "", subdirectory: nil))
Expand All @@ -77,7 +85,7 @@ class TestBundle : XCTestCase {
}

func test_infoPlist() {
let bundle = Bundle.main
let bundle = testBundle()

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

func test_localizations() {
let bundle = Bundle.main
let bundle = testBundle()

XCTAssertEqual(["en"], bundle.localizations)
XCTAssertEqual(["en"], bundle.preferredLocalizations)
XCTAssertEqual(["en"], Bundle.preferredLocalizations(from: ["en", "pl", "es"]))
Expand Down Expand Up @@ -158,13 +166,13 @@ class TestBundle : XCTestCase {
}

func test_bundleLoad(){
let bundle = Bundle.main
let bundle = testBundle()
let _ = bundle.load()
XCTAssertTrue(bundle.isLoaded)
}

func test_bundleLoadWithError(){
let bundleValid = Bundle.main
let bundleValid = testBundle()
//test valid load using loadAndReturnError
do{
try bundleValid.loadAndReturnError()
Expand All @@ -184,7 +192,7 @@ class TestBundle : XCTestCase {
}

func test_bundlePreflight(){
let bundleValid = Bundle.main
let bundleValid = testBundle()
do{
try bundleValid.preflight()
}catch{
Expand Down
2 changes: 1 addition & 1 deletion TestFoundation/TestHTTPCookieStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class TestHTTPCookieStorage: XCTestCase {
storage.setCookie(testCookie)
XCTAssertEqual(storage.cookies!.count, 1)
var destPath: String
let bundlePath = Bundle.main.bundlePath
let bundlePath = testBundle().bundlePath
var bundleName = "/" + bundlePath.components(separatedBy: "/").last!
if let range = bundleName.range(of: ".", options: String.CompareOptions.backwards, range: nil, locale: nil) {
bundleName = String(bundleName[..<range.lowerBound])
Expand Down
2 changes: 1 addition & 1 deletion TestFoundation/TestNSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class TestNSData: XCTestCase {
}

func test_writeToURLOptions() {
let saveData = try! Data(contentsOf: Bundle.main.url(forResource: "Test", withExtension: "plist")!)
let saveData = try! Data(contentsOf: testBundle().url(forResource: "Test", withExtension: "plist")!)
let savePath = URL(fileURLWithPath: NSTemporaryDirectory() + "Test1.plist")
do {
try saveData.write(to: savePath, options: .atomic)
Expand Down
4 changes: 0 additions & 4 deletions TestFoundation/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import SwiftXCTest
#endif


internal func testBundle() -> Bundle {
return Bundle.main
}

// ignore SIGPIPE which is sent when writing to closed file descriptors.
_ = signal(SIGPIPE, SIG_IGN)

Expand Down