Skip to content

Commit a12ce50

Browse files
author
Ignacio Bonafonte
committed
Also warn if DATADOG_CLIENT_TOKEN or SRCROOT are not properly set
1 parent 9532975 commit a12ce50

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Sources/DatadogSDKTesting/FrameworkLoadHandler.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class FrameworkLoadHandler: NSObject {
1616

1717
internal static func installTestObserver() {
1818
/// Only initialize test observer if user configured so and is running tests
19-
guard let enabled = DDEnvironmentValues.getEnvVariable("DD_TEST_RUNNER") as NSString? else {
19+
guard let enabled = environment["DD_TEST_RUNNER"] as NSString? else {
2020
print("[DatadogSDKTesting] Library loaded but not active, DD_TEST_RUNNER is missing")
2121
return
2222
}
@@ -29,6 +29,13 @@ public class FrameworkLoadHandler: NSObject {
2929
let isInTestMode = environment["XCInjectBundleInto"] != nil ||
3030
environment["XCTestConfigurationFilePath"] != nil
3131
if isInTestMode {
32+
guard environment["DATADOG_CLIENT_TOKEN"] != nil else {
33+
print("[DatadogSDKTesting] DATADOG_CLIENT_TOKEN missing.")
34+
return
35+
}
36+
if environment["SRCROOT"] == nil {
37+
print("[DatadogSDKTesting] SRCROOT is not properly set")
38+
}
3239
print("[DatadogSDKTesting] Library loaded and active. Instrumenting tests.")
3340
DDTestMonitor.instance = DDTestMonitor()
3441
DDTestMonitor.instance?.startInstrumenting()

Tests/DatadogSDKTesting/FrameworkLoadHandlerTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class FrameworkLoadHandlerTests: XCTestCase {
3636

3737
func testWhenTestRunnerIsConfiguredAndIsInTestingMode_ItIsInitialised() {
3838
testEnvironment["DD_TEST_RUNNER"] = "1"
39+
testEnvironment["DATADOG_CLIENT_TOKEN"] = "fakeToken"
3940
testEnvironment["DD_DISABLE_STDERR_INSTRUMENTATION"] = "1"
4041
testEnvironment["XCTestConfigurationFilePath"] = "/Users/user/Library/tmp/xx.xctestconfiguration"
4142
setEnvVariables()
@@ -47,6 +48,7 @@ class FrameworkLoadHandlerTests: XCTestCase {
4748

4849
func testWhenTestRunnerIsConfiguredAndIsInOtherTestingMode_ItIsInitialised() {
4950
testEnvironment["DD_TEST_RUNNER"] = "1"
51+
testEnvironment["DATADOG_CLIENT_TOKEN"] = "fakeToken"
5052
testEnvironment["DD_DISABLE_STDERR_INSTRUMENTATION"] = "1"
5153
testEnvironment["XCInjectBundleInto"] = "/Users/user/Library/tmp/xx.xctestconfiguration"
5254
setEnvVariables()
@@ -56,6 +58,17 @@ class FrameworkLoadHandlerTests: XCTestCase {
5658
XCTAssertNotNil(DDTestMonitor.instance)
5759
}
5860

61+
func testWhenTestRunnerIsConfiguredAndIsInTestingModeButNoToken_ItIsNotInitialised() {
62+
testEnvironment["DD_TEST_RUNNER"] = "1"
63+
testEnvironment["DD_DISABLE_STDERR_INSTRUMENTATION"] = "1"
64+
testEnvironment["XCTestConfigurationFilePath"] = "/Users/user/Library/tmp/xx.xctestconfiguration"
65+
setEnvVariables()
66+
67+
FrameworkLoadHandler.handleLoad()
68+
69+
XCTAssertNil(DDTestMonitor.instance)
70+
}
71+
5972
func testWhenTestRunnerIsNotConfigured_ItIsNotInitialised() {
6073
testEnvironment["XCInjectBundleInto"] = "/Users/user/Library/tmp/xx.xctestconfiguration"
6174
setEnvVariables()

0 commit comments

Comments
 (0)