Skip to content

Commit c49faf4

Browse files
bsneedBrandon Sneed
andauthored
minor fixes (#43)
* Reworked how isUnitTesting is used/works. * Updated to use Sovran 1.0.2 * Fixed a nitpick about TRUE vs. YES in objc. Co-authored-by: Brandon Sneed <[email protected]>
1 parent e35f7f1 commit c49faf4

File tree

6 files changed

+31
-15
lines changed

6 files changed

+31
-15
lines changed

Examples/apps/ObjCExample/ObjCExample/AppDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ @implementation AppDelegate
1919
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
2020
// Override point for customization after application launch.
2121
SEGConfiguration *config = [[SEGConfiguration alloc] initWithWriteKey:@"WRITE_KEY"];
22-
config.trackApplicationLifecycleEvents = TRUE;
22+
config.trackApplicationLifecycleEvents = YES;
2323

2424
SEGAnalytics *analytics = [[SEGAnalytics alloc] initWithConfiguration: config];
2525

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let package = Package(
2323
.package(
2424
name: "Sovran",
2525
url: "https://github.com/segmentio/Sovran-Swift.git",
26-
from: "1.0.1"
26+
from: "1.0.2"
2727
)
2828
],
2929
targets: [

Segment.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@
853853
repositoryURL = "[email protected]:segmentio/Sovran-Swift.git";
854854
requirement = {
855855
kind = upToNextMajorVersion;
856-
minimumVersion = 1.0.0;
856+
minimumVersion = 1.0.2;
857857
};
858858
};
859859
/* End XCRemoteSwiftPackageReference section */

Segment.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/Segment/Settings.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ extension Analytics {
104104
}
105105

106106
internal func checkSettings() {
107+
#if DEBUG
107108
if isUnitTesting {
108109
// we don't really wanna wait for this network call during tests...
109110
// but we should make it work similarly.
@@ -116,6 +117,7 @@ extension Analytics {
116117
}
117118
return
118119
}
120+
#endif
119121

120122
let writeKey = self.configuration.values.writeKey
121123
let httpClient = HTTPClient(analytics: self, cdnHost: configuration.values.cdnHost)

Sources/Segment/Utilities/Utils.swift

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,29 @@
77

88
import Foundation
99

10+
/// Inquire as to whether we are within a Unit Testing environment.
11+
#if DEBUG
1012
internal var isUnitTesting: Bool = {
11-
let env = ProcessInfo.processInfo.environment
12-
let value = (env["XCTestConfigurationFilePath"] != nil)
13-
return value
13+
// this will work on apple platforms, but fail on linux.
14+
if NSClassFromString("XCTestCase") != nil {
15+
return true
16+
}
17+
// this will work on linux and apple platforms, but not in anything with a UI
18+
// because XCTest doesn't come into the call stack till much later.
19+
let matches = Thread.callStackSymbols.filter { line in
20+
return line.contains("XCTest") || line.contains("xctest")
21+
}
22+
if matches.count > 0 {
23+
return true
24+
}
25+
// this will work on CircleCI to correctly detect test running.
26+
if ProcessInfo.processInfo.environment["CIRCLE_WORKFLOW_WORKSPACE_ID"] != nil {
27+
return true
28+
}
29+
// couldn't see anything that indicated we were testing.
30+
return false
1431
}()
32+
#endif
1533

1634
internal var isAppExtension: Bool = {
1735
if Bundle.main.bundlePath.hasSuffix(".appex") {
@@ -21,11 +39,7 @@ internal var isAppExtension: Bool = {
2139
}()
2240

2341
internal func exceptionFailure(_ message: String) {
24-
if isUnitTesting {
25-
assertionFailure(message)
26-
} else {
27-
#if DEBUG
28-
assertionFailure(message)
29-
#endif
30-
}
42+
#if DEBUG
43+
assertionFailure(message)
44+
#endif
3145
}

0 commit comments

Comments
 (0)