File tree 1 file changed +23
-3
lines changed
Modules/Sources/BuildSettingsKit
1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -6,14 +6,34 @@ enum BuildSettingsEnvironment {
6
6
7
7
static let current : BuildSettingsEnvironment = {
8
8
#if DEBUG
9
- let environment = ProcessInfo . processInfo. environment
10
- if environment [ " XCODE_RUNNING_FOR_PREVIEWS " ] == " 1 " {
9
+ let processInfo = ProcessInfo . processInfo
10
+ if processInfo . isXcodePreview {
11
11
return . preview
12
12
}
13
- if NSClassFromString ( " XCTestCase " ) != nil {
13
+ if processInfo . isTesting {
14
14
fatalError ( " BuildSettings are unavailable when running unit tests. Make sure to inject the values manually in system under test. " )
15
15
}
16
16
#endif
17
17
return . live
18
18
} ( )
19
19
}
20
+
21
+ private extension ProcessInfo {
22
+ var isXcodePreview : Bool {
23
+ environment [ " XCODE_RUNNING_FOR_PREVIEWS " ] == " 1 "
24
+ }
25
+
26
+ var isTesting : Bool {
27
+ if environment. keys. contains ( " XCTestBundlePath " ) { return true }
28
+ if environment. keys. contains ( " XCTestConfigurationFilePath " ) { return true }
29
+ if environment. keys. contains ( " XCTestSessionIdentifier " ) { return true }
30
+
31
+ return arguments. contains { argument in
32
+ let path = URL ( fileURLWithPath: argument)
33
+ return path. lastPathComponent == " swiftpm-testing-helper "
34
+ || argument == " --testing-library "
35
+ || path. lastPathComponent == " xctest "
36
+ || path. pathExtension == " xctest "
37
+ }
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments