Skip to content

Commit

Permalink
0.43.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Mar 12, 2024
1 parent 0087c2b commit 459b1d3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ import PackageDescription
let package = Package(
name: "SomeProject",
dependencies: [
.package(url: "https://github.com/dankinsoid/swift-api-client.git", from: "0.42.0")
.package(url: "https://github.com/dankinsoid/swift-api-client.git", from: "0.43.0")
],
targets: [
.target(
Expand Down
41 changes: 39 additions & 2 deletions Sources/SwiftAPIClient/APIClientConfigs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,42 @@ public func valueFor<Value>(
#endif
}

private let _XCTIsTesting: Bool = ProcessInfo.processInfo.environment.keys.contains("XCTestBundlePath")
private let _isPreview: Bool = ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
public let _isPreview: Bool = ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"

#if !os(WASI)
public let _XCTIsTesting: Bool = {
ProcessInfo.processInfo.environment.keys.contains("XCTestBundlePath")
|| ProcessInfo.processInfo.environment.keys.contains("XCTestConfigurationFilePath")
|| ProcessInfo.processInfo.environment.keys.contains("XCTestSessionIdentifier")
|| (ProcessInfo.processInfo.arguments.first
.flatMap(URL.init(fileURLWithPath:))
.map { $0.lastPathComponent == "xctest" || $0.pathExtension == "xctest" }
?? false)
|| XCTCurrentTestCase != nil
}()
#else
public let _XCTIsTesting = false
#endif

#if canImport(ObjectiveC)
private var XCTCurrentTestCase: AnyObject? {
guard
let XCTestObservationCenter = NSClassFromString("XCTestObservationCenter"),
let XCTestObservationCenter = XCTestObservationCenter as Any as? NSObjectProtocol,
let shared = XCTestObservationCenter.perform(Selector(("sharedTestObservationCenter")))?
.takeUnretainedValue(),
let observers = shared.perform(Selector(("observers")))?
.takeUnretainedValue() as? [AnyObject],
let observer =
observers
.first(where: { NSStringFromClass(type(of: $0)) == "XCTestMisuseObserver" }),
let currentTestCase = observer.perform(Selector(("currentTestCase")))?
.takeUnretainedValue()
else { return nil }
return currentTestCase
}
#else
private var XCTCurrentTestCase: AnyObject? {
nil
}
#endif

0 comments on commit 459b1d3

Please sign in to comment.