Skip to content

Commit 046aba2

Browse files
authored
Make _XCTIsTesting check a bit more robust (#21)
* Improve _XCTIsTesting * wip
1 parent fa6e1d2 commit 046aba2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import Foundation
22

33
public let _XCTIsTesting: Bool = {
4-
guard let path = ProcessInfo.processInfo.arguments.first
5-
else { return false }
6-
7-
let url = URL(fileURLWithPath: path)
8-
return url.lastPathComponent == "xctest" || url.pathExtension == "xctest"
4+
ProcessInfo.processInfo.environment.keys.contains("XCTestSessionIdentifier")
5+
|| ProcessInfo.processInfo.arguments.first
6+
.flatMap(URL.init(fileURLWithPath:))
7+
.map { $0.lastPathComponent == "xctest" || $0.pathExtension == "xctest" }
8+
?? false
99
}()

0 commit comments

Comments
 (0)