Skip to content

Commit f7aad5b

Browse files
authored
fix: enable running tests from package.swift (#274)
1 parent df65e7b commit f7aad5b

File tree

6 files changed

+44
-26
lines changed

6 files changed

+44
-26
lines changed

Amplitude-Swift.xcodeproj/project.pbxproj

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247
OBJ_82 /* AmplitudeSwift.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = AmplitudeSwift.podspec; sourceTree = "<group>"; };
248248
OBJ_9 /* Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
249249
"amplitude-swift::Amplitude-Swift::Product" /* AmplitudeSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AmplitudeSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
250-
"amplitude-swift::Amplitude-SwiftTests::Product" /* Amplitude_SwiftTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; name = Amplitude_SwiftTests.xctest; path = "Amplitude-SwiftTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
250+
"amplitude-swift::Amplitude-SwiftTests::Product" /* Amplitude-SwiftTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = "Amplitude-SwiftTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
251251
/* End PBXFileReference section */
252252

253253
/* Begin PBXFrameworksBuildPhase section */
@@ -550,7 +550,7 @@
550550
isa = PBXGroup;
551551
children = (
552552
"amplitude-swift::Amplitude-Swift::Product" /* AmplitudeSwift.framework */,
553-
"amplitude-swift::Amplitude-SwiftTests::Product" /* Amplitude_SwiftTests.xctest */,
553+
"amplitude-swift::Amplitude-SwiftTests::Product" /* Amplitude-SwiftTests.xctest */,
554554
);
555555
name = Products;
556556
sourceTree = BUILT_PRODUCTS_DIR;
@@ -595,7 +595,7 @@
595595
);
596596
name = "Amplitude-SwiftTests";
597597
productName = Amplitude_SwiftTests;
598-
productReference = "amplitude-swift::Amplitude-SwiftTests::Product" /* Amplitude_SwiftTests.xctest */;
598+
productReference = "amplitude-swift::Amplitude-SwiftTests::Product" /* Amplitude-SwiftTests.xctest */;
599599
productType = "com.apple.product-type.bundle.unit-test";
600600
};
601601
/* End PBXNativeTarget section */
@@ -828,17 +828,12 @@
828828
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
829829
DYLIB_INSTALL_NAME_BASE = "@rpath";
830830
GCC_OPTIMIZATION_LEVEL = s;
831-
GCC_PREPROCESSOR_DEFINITIONS = (
832-
"$(inherited)",
833-
"SWIFT_PACKAGE=1",
834-
);
835831
MACOSX_DEPLOYMENT_TARGET = 10.10;
836832
OTHER_SWIFT_FLAGS = "$(inherited) -DXcode";
837833
PRODUCT_NAME = "$(TARGET_NAME)";
838834
SDKROOT = macosx;
839835
SUPPORTED_PLATFORMS = "$(AVAILABLE_PLATFORMS)";
840836
SUPPORTS_MACCATALYST = YES;
841-
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) SWIFT_PACKAGE";
842837
SWIFT_COMPILATION_MODE = wholemodule;
843838
SWIFT_OPTIMIZATION_LEVEL = "-O";
844839
USE_HEADERMAP = NO;
@@ -929,7 +924,6 @@
929924
GCC_OPTIMIZATION_LEVEL = 0;
930925
GCC_PREPROCESSOR_DEFINITIONS = (
931926
"$(inherited)",
932-
"SWIFT_PACKAGE=1",
933927
"DEBUG=1",
934928
);
935929
MACOSX_DEPLOYMENT_TARGET = 10.10;
@@ -939,7 +933,6 @@
939933
SDKROOT = macosx;
940934
SUPPORTED_PLATFORMS = "$(AVAILABLE_PLATFORMS)";
941935
SUPPORTS_MACCATALYST = YES;
942-
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) SWIFT_PACKAGE DEBUG";
943936
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
944937
USE_HEADERMAP = NO;
945938
};
@@ -997,6 +990,10 @@
997990
"$(inherited)",
998991
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
999992
);
993+
GCC_PREPROCESSOR_DEFINITIONS = (
994+
"$(inherited)",
995+
"DEBUG=1",
996+
);
1000997
HEADER_SEARCH_PATHS = "$(inherited)";
1001998
INFOPLIST_FILE = "Amplitude-Swift.xcodeproj/Amplitude_SwiftTests_Info.plist";
1002999
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
@@ -1028,6 +1025,10 @@
10281025
"$(inherited)",
10291026
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
10301027
);
1028+
GCC_PREPROCESSOR_DEFINITIONS = (
1029+
"$(inherited)",
1030+
"DEBUG=1",
1031+
);
10311032
HEADER_SEARCH_PATHS = "$(inherited)";
10321033
INFOPLIST_FILE = "Amplitude-Swift.xcodeproj/Amplitude_SwiftTests_Info.plist";
10331034
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
@@ -1091,7 +1092,6 @@
10911092
GCC_OPTIMIZATION_LEVEL = 0;
10921093
GCC_PREPROCESSOR_DEFINITIONS = (
10931094
"$(inherited)",
1094-
"SWIFT_PACKAGE=1",
10951095
"DEBUG=1",
10961096
);
10971097
MACOSX_DEPLOYMENT_TARGET = 10.10;
@@ -1101,7 +1101,6 @@
11011101
SDKROOT = macosx;
11021102
SUPPORTED_PLATFORMS = "$(AVAILABLE_PLATFORMS)";
11031103
SUPPORTS_MACCATALYST = YES;
1104-
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) SWIFT_PACKAGE DEBUG";
11051104
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
11061105
USE_HEADERMAP = NO;
11071106
};
@@ -1116,17 +1115,12 @@
11161115
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
11171116
DYLIB_INSTALL_NAME_BASE = "@rpath";
11181117
GCC_OPTIMIZATION_LEVEL = s;
1119-
GCC_PREPROCESSOR_DEFINITIONS = (
1120-
"$(inherited)",
1121-
"SWIFT_PACKAGE=1",
1122-
);
11231118
MACOSX_DEPLOYMENT_TARGET = 10.10;
11241119
OTHER_SWIFT_FLAGS = "$(inherited) -DXcode";
11251120
PRODUCT_NAME = "$(TARGET_NAME)";
11261121
SDKROOT = macosx;
11271122
SUPPORTED_PLATFORMS = "$(AVAILABLE_PLATFORMS)";
11281123
SUPPORTS_MACCATALYST = YES;
1129-
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) SWIFT_PACKAGE";
11301124
SWIFT_COMPILATION_MODE = wholemodule;
11311125
SWIFT_OPTIMIZATION_LEVEL = "-O";
11321126
USE_HEADERMAP = NO;
@@ -1257,7 +1251,7 @@
12571251
repositoryURL = "https://github.com/amplitude/analytics-connector-ios";
12581252
requirement = {
12591253
kind = upToNextMajorVersion;
1260-
minimumVersion = 1.2.3;
1254+
minimumVersion = 1.3.0;
12611255
};
12621256
};
12631257
/* End XCRemoteSwiftPackageReference section */

Package.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ let package = Package(
3030
.product(name: "AnalyticsConnector", package: "analytics-connector-ios")
3131
],
3232
path: "Sources/Amplitude",
33-
exclude: ["../../Examples/", "../../Tests/"],
3433
resources: [.copy("PrivacyInfo.xcprivacy")]
3534
),
3635
.testTarget(
3736
name: "Amplitude-SwiftTests",
38-
dependencies: ["AmplitudeSwift"],
39-
path: "Tests/AmplitudeTests"
40-
),
37+
dependencies: [
38+
.target(name: "AmplitudeSwift"),
39+
],
40+
path: "Tests/AmplitudeTests",
41+
resources: [
42+
.process("Migration/legacy_v3.sqlite"),
43+
.process("Migration/legacy_v4.sqlite"),
44+
])
4145
]
4246
)

Package@swift-5.9.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ let package = Package(
3131
.product(name: "AnalyticsConnector", package: "analytics-connector-ios")
3232
],
3333
path: "Sources/Amplitude",
34-
exclude: ["../../Examples/", "../../Tests/"],
3534
resources: [.copy("PrivacyInfo.xcprivacy")]
3635
),
3736
.testTarget(
3837
name: "Amplitude-SwiftTests",
39-
dependencies: ["AmplitudeSwift"],
40-
path: "Tests/AmplitudeTests"
41-
),
38+
dependencies: [
39+
.target(name: "AmplitudeSwift"),
40+
],
41+
path: "Tests/AmplitudeTests",
42+
resources: [
43+
.process("Migration/legacy_v3.sqlite"),
44+
.process("Migration/legacy_v4.sqlite"),
45+
])
4246
]
4347
)

Tests/AmplitudeTests/AmplitudeTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,11 @@ final class AmplitudeTests: XCTestCase {
692692

693693
func testRemnantDataNotMigratedInNonSandboxedApps() throws {
694694
let instanceName = "legacy_v3_\(UUID().uuidString)".lowercased()
695+
#if SWIFT_PACKAGE
696+
let bundle = Bundle.module
697+
#else
695698
let bundle = Bundle(for: type(of: self))
699+
#endif
696700
let legacyDbUrl = bundle.url(forResource: "legacy_v3", withExtension: "sqlite")
697701
let dbUrl = LegacyDatabaseStorage.getDatabasePath(instanceName)
698702
let fileManager = FileManager.default
@@ -733,7 +737,11 @@ final class AmplitudeTests: XCTestCase {
733737
#if os(macOS)
734738
func testRemnantDataNotMigratedInSandboxedMacApps() throws {
735739
let instanceName = "legacy_v3_\(UUID().uuidString)".lowercased()
740+
#if SWIFT_PACKAGE
741+
let bundle = Bundle.module
742+
#else
736743
let bundle = Bundle(for: type(of: self))
744+
#endif
737745
let legacyDbUrl = bundle.url(forResource: "legacy_v3", withExtension: "sqlite")
738746
let dbUrl = LegacyDatabaseStorage.getDatabasePath(instanceName)
739747
let fileManager = FileManager.default

Tests/AmplitudeTests/Migration/LegacyDatabaseStorageTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ final class LegacyDatabaseStorageTests: XCTestCase {
66
var storage: LegacyDatabaseStorage?
77

88
override func setUpWithError() throws {
9+
#if SWIFT_PACKAGE
10+
let bundle = Bundle.module
11+
#else
912
let bundle = Bundle(for: type(of: self))
13+
#endif
1014
let legacyDbUrl = bundle.url(forResource: "legacy_v4", withExtension: "sqlite")
1115
let tempDirectory = NSTemporaryDirectory()
1216
let tempDbName = UUID().uuidString

Tests/AmplitudeTests/Migration/RemnantDataMigrationTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ final class RemnantDataMigrationTests: XCTestCase {
2424
private func checkLegacyDataMigration(_ legacyDbName: String, _ dbVersion: Int, _ migrateLegacyData: Bool = true) throws {
2525
let instanceName = "legacy_v\(dbVersion)_\(migrateLegacyData)_\(UUID().uuidString)".lowercased()
2626

27+
#if SWIFT_PACKAGE
28+
let bundle = Bundle.module
29+
#else
2730
let bundle = Bundle(for: type(of: self))
31+
#endif
2832
let legacyDbUrl = bundle.url(forResource: legacyDbName, withExtension: "sqlite")
2933
let dbUrl = LegacyDatabaseStorage.getDatabasePath(instanceName)
3034
let fileManager = FileManager.default

0 commit comments

Comments
 (0)