From 985683b4f37914e6c4034a4d292d969b99be0402 Mon Sep 17 00:00:00 2001 From: Brandon Sneed Date: Wed, 18 Aug 2021 14:48:36 -0700 Subject: [PATCH 1/3] Reworked how isUnitTesting is used/works. --- Sources/Segment/Settings.swift | 2 ++ Sources/Segment/Utilities/Utils.swift | 34 +++++++++++++++++++-------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Sources/Segment/Settings.swift b/Sources/Segment/Settings.swift index 1eb754ce..31c7b2c4 100644 --- a/Sources/Segment/Settings.swift +++ b/Sources/Segment/Settings.swift @@ -104,6 +104,7 @@ extension Analytics { } internal func checkSettings() { + #if DEBUG if isUnitTesting { // we don't really wanna wait for this network call during tests... // but we should make it work similarly. @@ -116,6 +117,7 @@ extension Analytics { } return } + #endif let writeKey = self.configuration.values.writeKey let httpClient = HTTPClient(analytics: self, cdnHost: configuration.values.cdnHost) diff --git a/Sources/Segment/Utilities/Utils.swift b/Sources/Segment/Utilities/Utils.swift index c44a91a1..8367eaad 100644 --- a/Sources/Segment/Utilities/Utils.swift +++ b/Sources/Segment/Utilities/Utils.swift @@ -7,11 +7,29 @@ import Foundation +/// Inquire as to whether we are within a Unit Testing environment. +#if DEBUG internal var isUnitTesting: Bool = { - let env = ProcessInfo.processInfo.environment - let value = (env["XCTestConfigurationFilePath"] != nil) - return value + // this will work on apple platforms, but fail on linux. + if NSClassFromString("XCTestCase") != nil { + return true + } + // this will work on linux and apple platforms, but not in anything with a UI + // because XCTest doesn't come into the call stack till much later. + let matches = Thread.callStackSymbols.filter { line in + return line.contains("XCTest") || line.contains("xctest") + } + if matches.count > 0 { + return true + } + // this will work on CircleCI to correctly detect test running. + if ProcessInfo.processInfo.environment["CIRCLE_WORKFLOW_WORKSPACE_ID"] != nil { + return true + } + // couldn't see anything that indicated we were testing. + return false }() +#endif internal var isAppExtension: Bool = { if Bundle.main.bundlePath.hasSuffix(".appex") { @@ -21,11 +39,7 @@ internal var isAppExtension: Bool = { }() internal func exceptionFailure(_ message: String) { - if isUnitTesting { - assertionFailure(message) - } else { - #if DEBUG - assertionFailure(message) - #endif - } + #if DEBUG + assertionFailure(message) + #endif } From 5322ac4b719b77fe8fac6b12a2936fa3ee179e1e Mon Sep 17 00:00:00 2001 From: Brandon Sneed Date: Wed, 18 Aug 2021 14:48:49 -0700 Subject: [PATCH 2/3] Updated to use Sovran 1.0.2 --- Package.swift | 2 +- Segment.xcodeproj/project.pbxproj | 2 +- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index 497f65cb..abe05d19 100644 --- a/Package.swift +++ b/Package.swift @@ -23,7 +23,7 @@ let package = Package( .package( name: "Sovran", url: "https://github.com/segmentio/Sovran-Swift.git", - from: "1.0.1" + from: "1.0.2" ) ], targets: [ diff --git a/Segment.xcodeproj/project.pbxproj b/Segment.xcodeproj/project.pbxproj index 53a19fc4..980d71b6 100644 --- a/Segment.xcodeproj/project.pbxproj +++ b/Segment.xcodeproj/project.pbxproj @@ -853,7 +853,7 @@ repositoryURL = "git@github.com:segmentio/Sovran-Swift.git"; requirement = { kind = upToNextMajorVersion; - minimumVersion = 1.0.0; + minimumVersion = 1.0.2; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/Segment.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Segment.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 88927f70..4e9f23ef 100644 --- a/Segment.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Segment.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "git@github.com:segmentio/Sovran-Swift.git", "state": { "branch": null, - "revision": "8eab95bb85b4816b25b32e7d2af2c88b358b04df", - "version": "1.0.1" + "revision": "be79aad4393d36959f422c2b40566b84ee1170f7", + "version": "1.0.2" } } ] From 4a45ca1d98065e87f667a50fd09a27b307cac969 Mon Sep 17 00:00:00 2001 From: Brandon Sneed Date: Wed, 18 Aug 2021 14:49:08 -0700 Subject: [PATCH 3/3] Fixed a nitpick about TRUE vs. YES in objc. --- Examples/apps/ObjCExample/ObjCExample/AppDelegate.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/apps/ObjCExample/ObjCExample/AppDelegate.m b/Examples/apps/ObjCExample/ObjCExample/AppDelegate.m index 3ea3371b..4188dc37 100644 --- a/Examples/apps/ObjCExample/ObjCExample/AppDelegate.m +++ b/Examples/apps/ObjCExample/ObjCExample/AppDelegate.m @@ -19,7 +19,7 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. SEGConfiguration *config = [[SEGConfiguration alloc] initWithWriteKey:@"WRITE_KEY"]; - config.trackApplicationLifecycleEvents = TRUE; + config.trackApplicationLifecycleEvents = YES; SEGAnalytics *analytics = [[SEGAnalytics alloc] initWithConfiguration: config];