Skip to content

Commit

Permalink
Allow unit-testing in SPM builds
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnEstropia committed Aug 16, 2022
1 parent da4ac19 commit 7f4cfaf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
13 changes: 12 additions & 1 deletion CoreStoreTests/BaseTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ import XCTest
@testable
import CoreStore

#if !SWIFT_PACKAGE

extension Bundle {

static var module: Bundle {
return Bundle(for: BaseTestCase.self)
}
}

#endif


// MARK: - BaseTestCase

Expand All @@ -40,7 +51,7 @@ class BaseTestCase: XCTestCase {

let stack = DataStack(
xcodeModelName: "Model",
bundle: Bundle(for: Self.self)
bundle: Bundle.module
)
do {

Expand Down
2 changes: 1 addition & 1 deletion CoreStoreTests/ErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ final class ErrorTests: XCTestCase {
let schemaHistory = SchemaHistory(
XcodeDataModelSchema.from(
modelName: "Model",
bundle: Bundle(for: Self.self)
bundle: Bundle.module
)
)
let version = "1.0.0"
Expand Down
18 changes: 9 additions & 9 deletions CoreStoreTests/SetupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SetupTests: BaseTestDataTestCase {
let schemaHistory = SchemaHistory(
XcodeDataModelSchema.from(
modelName: "Model",
bundle: Bundle(for: Self.self)
bundle: Bundle.module
)
)
let stack = DataStack(schemaHistory: schemaHistory)
Expand All @@ -68,7 +68,7 @@ class SetupTests: BaseTestDataTestCase {

DataStack(
xcodeModelName: "Model",
bundle: Bundle(for: Self.self),
bundle: Bundle.module,
migrationChain: migrationChain
)
}
Expand All @@ -82,7 +82,7 @@ class SetupTests: BaseTestDataTestCase {

let stack = DataStack(
xcodeModelName: "Model",
bundle: Bundle(for: Self.self)
bundle: Bundle.module
)
do {

Expand Down Expand Up @@ -137,7 +137,7 @@ class SetupTests: BaseTestDataTestCase {

let stack = DataStack(
xcodeModelName: "Model",
bundle: Bundle(for: Self.self)
bundle: Bundle.module
)
do {

Expand Down Expand Up @@ -205,7 +205,7 @@ class SetupTests: BaseTestDataTestCase {

let stack = DataStack(
xcodeModelName: "Model",
bundle: Bundle(for: Self.self)
bundle: Bundle.module
)
try! stack.addStorageAndWait(sqliteStore)
self.prepareTestDataForStack(stack)
Expand All @@ -224,7 +224,7 @@ class SetupTests: BaseTestDataTestCase {
let metadata = try createStore()
let stack = DataStack(
xcodeModelName: "Model",
bundle: Bundle(for: Self.self)
bundle: Bundle.module
)
try sqliteStore.cs_eraseStorageAndWait(
metadata: metadata,
Expand Down Expand Up @@ -257,7 +257,7 @@ class SetupTests: BaseTestDataTestCase {

let stack = DataStack(
xcodeModelName: "Model",
bundle: Bundle(for: Self.self)
bundle: Bundle.module
)
do {

Expand Down Expand Up @@ -325,7 +325,7 @@ class SetupTests: BaseTestDataTestCase {

let stack = DataStack(
xcodeModelName: "Model",
bundle: Bundle(for: Self.self)
bundle: Bundle.module
)
try! stack.addStorageAndWait(
SQLiteStore.legacy(
Expand All @@ -351,7 +351,7 @@ class SetupTests: BaseTestDataTestCase {
let metadata = try createStore()
let stack = DataStack(
xcodeModelName: "Model",
bundle: Bundle(for: Self.self)
bundle: Bundle.module
)
try sqliteStore.cs_eraseStorageAndWait(
metadata: metadata,
Expand Down
6 changes: 3 additions & 3 deletions CoreStoreTests/StorageInterfaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ final class StorageInterfaceTests: XCTestCase {
.appendingPathExtension("db")
let mappingProvider = XcodeSchemaMappingProvider(
from: "V1", to: "V2",
mappingModelBundle: Bundle(for: Self.self)
mappingModelBundle: Bundle.module
)

let store = SQLiteStore(
Expand Down Expand Up @@ -131,7 +131,7 @@ final class StorageInterfaceTests: XCTestCase {
let fileName = UUID().uuidString + ".db"
let mappingProvider = XcodeSchemaMappingProvider(
from: "V1", to: "V2",
mappingModelBundle: Bundle(for: Self.self)
mappingModelBundle: Bundle.module
)
let store = SQLiteStore(
fileName: fileName,
Expand Down Expand Up @@ -197,7 +197,7 @@ final class StorageInterfaceTests: XCTestCase {
let fileName = UUID().uuidString + ".db"
let mappingProvider = XcodeSchemaMappingProvider(
from: "V1", to: "V2",
mappingModelBundle: Bundle(for: Self.self)
mappingModelBundle: Bundle.module
)
let store = SQLiteStore.legacy(
fileName: fileName,
Expand Down
7 changes: 5 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5
// swift-tools-version:5.7
//
// Package.swift
// CoreStore
Expand Down Expand Up @@ -45,7 +45,10 @@ let package = Package(
.testTarget(
name: "CoreStoreTests",
dependencies: ["CoreStore"],
path: "CoreStoreTests"
path: "CoreStoreTests",
resources: [
.process("Model.xcdatamodeld")
]
)
],
swiftLanguageVersions: [.v5]
Expand Down

0 comments on commit 7f4cfaf

Please sign in to comment.