Skip to content
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

Fallback to disk for loading test resources when bundle does not exist #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions Tests/SwiftyChronoTests/ChronoJSXCTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ public class ChronoJSXCTestCase: XCTestCase, ChronoJSTestable {
jsContext.evaluateScript(script)
}

public func resourcePath(testCasePath: String = #file, name: String, type: String) -> String {
if let bundle = Bundle(identifier: "io.quire.lib.SwiftyChrono"), let path = bundle.path(forResource: name, ofType: type) {
return path
} else {
// bundle does not exist (expect that if you regenerated SwiftyChrono.xcodeproj with SPM)
// assume resource is in the same folder than the test case source file
let folder = testCasePath.components(separatedBy: "/").dropLast().joined(separator: "/")
return "\(folder)/\(name).\(type)"
}
}

override public func setUp() {
super.setUp()

Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftyChronoTests/JS/de/TestDE.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TestDE: ChronoJSXCTestCase {
Chrono.sixMinutesFixBefore1900 = true

for fileName in files {
let js = try! String(contentsOfFile: Bundle(identifier: "io.quire.lib.SwiftyChrono")!.path(forResource: fileName, ofType: "js")!)
let js = try! String(contentsOfFile: resourcePath(name: fileName, type: "js"))
evalJS(js, fileName: fileName)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftyChronoTests/JS/en/TestEN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestEN: ChronoJSXCTestCase {
Chrono.preferredLanguage = .english

for fileName in files {
let js = try! String(contentsOfFile: Bundle(identifier: "io.quire.lib.SwiftyChrono")!.path(forResource: fileName, ofType: "js")!)
let js = try! String(contentsOfFile: resourcePath(name: fileName, type: "js"))
evalJS(js, fileName: fileName)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftyChronoTests/JS/es/TestES.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TestES: ChronoJSXCTestCase {
Chrono.sixMinutesFixBefore1900 = true

for fileName in files {
let js = try! String(contentsOfFile: Bundle(identifier: "io.quire.lib.SwiftyChrono")!.path(forResource: fileName, ofType: "js")!)
let js = try! String(contentsOfFile: resourcePath(name: fileName, type: "js"))
evalJS(js, fileName: fileName)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftyChronoTests/JS/fr/TestFR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TestFR: ChronoJSXCTestCase {
Chrono.sixMinutesFixBefore1900 = true

for fileName in files {
let js = try! String(contentsOfFile: Bundle(identifier: "io.quire.lib.SwiftyChrono")!.path(forResource: fileName, ofType: "js")!)
let js = try! String(contentsOfFile: resourcePath(name: fileName, type: "js"))
evalJS(js, fileName: fileName)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftyChronoTests/JS/jp/TestJP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TestJP: ChronoJSXCTestCase {
Chrono.sixMinutesFixBefore1900 = true

for fileName in files {
let js = try! String(contentsOfFile: Bundle(identifier: "io.quire.lib.SwiftyChrono")!.path(forResource: fileName, ofType: "js")!)
let js = try! String(contentsOfFile: resourcePath(name: fileName, type: "js"))
evalJS(js, fileName: fileName)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftyChronoTests/JS/zh_hans/TestZHHans.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TestZHHans: ChronoJSXCTestCase {
Chrono.sixMinutesFixBefore1900 = true

for fileName in files {
let js = try! String(contentsOfFile: Bundle(identifier: "io.quire.lib.SwiftyChrono")!.path(forResource: fileName, ofType: "js")!)
let js = try! String(contentsOfFile: resourcePath(name: fileName, type: "js"))
evalJS(js, fileName: fileName)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftyChronoTests/JS/zh_hant/testZHHant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TestZHHant: ChronoJSXCTestCase {
Chrono.sixMinutesFixBefore1900 = true

for fileName in files {
let js = try! String(contentsOfFile: Bundle(identifier: "io.quire.lib.SwiftyChrono")!.path(forResource: fileName, ofType: "js")!)
let js = try! String(contentsOfFile: resourcePath(name: fileName, type: "js"))
evalJS(js, fileName: fileName)
}
}
Expand Down