From ebdb9af2f79111af58b223c5c159be4086c020d6 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Wed, 6 Jul 2022 14:15:22 -0400 Subject: [PATCH 1/2] Improve _XCTIsTesting --- Sources/XCTestDynamicOverlay/XCTIsTesting.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sources/XCTestDynamicOverlay/XCTIsTesting.swift b/Sources/XCTestDynamicOverlay/XCTIsTesting.swift index c777b8ac..1c4931ae 100644 --- a/Sources/XCTestDynamicOverlay/XCTIsTesting.swift +++ b/Sources/XCTestDynamicOverlay/XCTIsTesting.swift @@ -1,9 +1,8 @@ import Foundation public let _XCTIsTesting: Bool = { - guard let path = ProcessInfo.processInfo.arguments.first - else { return false } - - let url = URL(fileURLWithPath: path) - return url.lastPathComponent == "xctest" || url.pathExtension == "xctest" + ProcessInfo.processInfo.arguments.first + .flatMap(URL.init(fileURLWithPath:)) + .map { $0.lastPathComponent == "xctest" || $0.pathExtension == "xctest" } + ?? ProcessInfo.processInfo.environment.keys.contains("XCTestSessionIdentifier") }() From 63136238e6e49b6ff25cf5d53dbd4e645ed43ae5 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Wed, 6 Jul 2022 14:19:47 -0400 Subject: [PATCH 2/2] wip --- Sources/XCTestDynamicOverlay/XCTIsTesting.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sources/XCTestDynamicOverlay/XCTIsTesting.swift b/Sources/XCTestDynamicOverlay/XCTIsTesting.swift index 1c4931ae..86a0df2e 100644 --- a/Sources/XCTestDynamicOverlay/XCTIsTesting.swift +++ b/Sources/XCTestDynamicOverlay/XCTIsTesting.swift @@ -1,8 +1,9 @@ import Foundation public let _XCTIsTesting: Bool = { - ProcessInfo.processInfo.arguments.first - .flatMap(URL.init(fileURLWithPath:)) - .map { $0.lastPathComponent == "xctest" || $0.pathExtension == "xctest" } - ?? ProcessInfo.processInfo.environment.keys.contains("XCTestSessionIdentifier") + ProcessInfo.processInfo.environment.keys.contains("XCTestSessionIdentifier") + || ProcessInfo.processInfo.arguments.first + .flatMap(URL.init(fileURLWithPath:)) + .map { $0.lastPathComponent == "xctest" || $0.pathExtension == "xctest" } + ?? false }()