Skip to content

Commit 30a0037

Browse files
committed
fix: Remove missing import
1 parent c5c0d36 commit 30a0037

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

Sources/FoundationExtensions/General/RuntimeWarnings.swift

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@preconcurrency import Foundation
2-
import IssueReporting
32

43
extension Notification.Name {
54
@available(*, deprecated, message: "Use IssueReporting module from https://github.com/pointfreeco/swift-issue-reporting")
@@ -84,3 +83,48 @@ let formatter: DateFormatter = {
8483
}()
8584
#endif
8685
#endif
86+
87+
#if os(WASI)
88+
public let isTesting = false
89+
#else
90+
import Foundation
91+
92+
/// Whether or not the current process is running tests.
93+
///
94+
/// You can use this information to prevent application code from running when hosting tests. For
95+
/// example, you can wrap your app entry point:
96+
///
97+
/// ```swift
98+
/// import IssueReporting
99+
///
100+
/// @main
101+
/// struct MyApp: App {
102+
/// var body: some Scene {
103+
/// WindowGroup {
104+
/// if !isTesting {
105+
/// MyRootView()
106+
/// }
107+
/// }
108+
/// }
109+
/// }
110+
///
111+
/// To detect if the current task is running inside a test, use ``TestContext/current``, instead.
112+
public let isTesting = ProcessInfo.processInfo.isTesting
113+
114+
extension ProcessInfo {
115+
fileprivate var isTesting: Bool {
116+
if environment.keys.contains("XCTestBundlePath") { return true }
117+
if environment.keys.contains("XCTestBundleInjectPath") { return true }
118+
if environment.keys.contains("XCTestConfigurationFilePath") { return true }
119+
if environment.keys.contains("XCTestSessionIdentifier") { return true }
120+
121+
return arguments.contains { argument in
122+
let path = URL(fileURLWithPath: argument)
123+
return path.lastPathComponent == "swiftpm-testing-helper"
124+
|| argument == "--testing-library"
125+
|| path.lastPathComponent == "xctest"
126+
|| path.pathExtension == "xctest"
127+
}
128+
}
129+
}
130+
#endif

0 commit comments

Comments
 (0)