diff --git a/Tests/SwiftyChronoTests/ChronoJSXCTestCase.swift b/Tests/SwiftyChronoTests/ChronoJSXCTestCase.swift index 8f04cd5..f6efc25 100644 --- a/Tests/SwiftyChronoTests/ChronoJSXCTestCase.swift +++ b/Tests/SwiftyChronoTests/ChronoJSXCTestCase.swift @@ -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() diff --git a/Tests/SwiftyChronoTests/JS/de/TestDE.swift b/Tests/SwiftyChronoTests/JS/de/TestDE.swift index 87c1a0f..157653c 100644 --- a/Tests/SwiftyChronoTests/JS/de/TestDE.swift +++ b/Tests/SwiftyChronoTests/JS/de/TestDE.swift @@ -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) } } diff --git a/Tests/SwiftyChronoTests/JS/en/TestEN.swift b/Tests/SwiftyChronoTests/JS/en/TestEN.swift index 8bc305e..0125221 100644 --- a/Tests/SwiftyChronoTests/JS/en/TestEN.swift +++ b/Tests/SwiftyChronoTests/JS/en/TestEN.swift @@ -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) } } diff --git a/Tests/SwiftyChronoTests/JS/es/TestES.swift b/Tests/SwiftyChronoTests/JS/es/TestES.swift index 46a3c33..b09ce9a 100644 --- a/Tests/SwiftyChronoTests/JS/es/TestES.swift +++ b/Tests/SwiftyChronoTests/JS/es/TestES.swift @@ -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) } } diff --git a/Tests/SwiftyChronoTests/JS/fr/TestFR.swift b/Tests/SwiftyChronoTests/JS/fr/TestFR.swift index e76ba1a..0622ec8 100644 --- a/Tests/SwiftyChronoTests/JS/fr/TestFR.swift +++ b/Tests/SwiftyChronoTests/JS/fr/TestFR.swift @@ -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) } } diff --git a/Tests/SwiftyChronoTests/JS/jp/TestJP.swift b/Tests/SwiftyChronoTests/JS/jp/TestJP.swift index c173255..2e26f23 100644 --- a/Tests/SwiftyChronoTests/JS/jp/TestJP.swift +++ b/Tests/SwiftyChronoTests/JS/jp/TestJP.swift @@ -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) } } diff --git a/Tests/SwiftyChronoTests/JS/zh_hans/TestZHHans.swift b/Tests/SwiftyChronoTests/JS/zh_hans/TestZHHans.swift index bef248d..bf0fdc2 100644 --- a/Tests/SwiftyChronoTests/JS/zh_hans/TestZHHans.swift +++ b/Tests/SwiftyChronoTests/JS/zh_hans/TestZHHans.swift @@ -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) } } diff --git a/Tests/SwiftyChronoTests/JS/zh_hant/testZHHant.swift b/Tests/SwiftyChronoTests/JS/zh_hant/testZHHant.swift index c5b6a6c..f69329d 100644 --- a/Tests/SwiftyChronoTests/JS/zh_hant/testZHHant.swift +++ b/Tests/SwiftyChronoTests/JS/zh_hant/testZHHant.swift @@ -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) } }