Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
matrix:
xcode: ['26.5']
config: ['debug', 'release']
traits: ['', 'CasePaths', 'CustomDump', 'IdentifiedCollections']
traits: ['', 'CasePaths', 'CustomDump', 'IdentifiedCollections', 'IssueReporting']
runs-on: macos-26
steps:
- uses: actions/checkout@v4
Expand All @@ -35,7 +35,7 @@ jobs:
matrix:
swift:
- '6.3'
traits: ['', 'CasePaths', 'CustomDump', 'IdentifiedCollections']
traits: ['', 'CasePaths', 'CustomDump', 'IdentifiedCollections', 'IssueReporting']
runs-on: ubuntu-latest
container: swift:${{ matrix.swift }}
steps:
Expand Down
13 changes: 12 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ let package = Package(
name: "IdentifiedCollections",
description: "Derive Shared elements from Shared collections using IdentifiedCollections"
),
.trait(
name: "IssueReporting",
description: "Improve test coverage by raising runtime warnings as test failures"
),
],
dependencies: [
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "1.0.0"),
Expand Down Expand Up @@ -71,7 +75,13 @@ let package = Package(
traits: ["IdentifiedCollections"]
)
),
.product(name: "IssueReporting", package: "xctest-dynamic-overlay"),
.product(
name: "IssueReporting",
package: "xctest-dynamic-overlay",
condition: .when(
traits: ["IssueReporting"]
)
),
.product(name: "PerceptionCore", package: "swift-perception"),
],
resources: [
Expand Down Expand Up @@ -116,6 +126,7 @@ package.traits.insert(
: [
"CustomDump",
"IdentifiedCollections",
"IssueReporting",
]
)
)
Expand Down
1 change: 1 addition & 0 deletions Package@swift-5.9.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ for target in package.targets {
target.swiftSettings?.append(contentsOf: [
.define("CustomDump"),
.define("IdentifiedCollections"),
.define("IssueReporting"),
])
}
1 change: 1 addition & 0 deletions Package@swift-6.0.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ for target in package.targets {
target.swiftSettings?.append(contentsOf: [
.define("CustomDump"),
.define("IdentifiedCollections"),
.define("IssueReporting"),
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ImmutableWeakCaptures"),
.enableUpcomingFeature("InferIsolatedConformances"),
Expand Down
1 change: 0 additions & 1 deletion Sources/Sharing/Internal/Reference.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Dependencies
import Foundation
import IssueReporting
public import PerceptionCore

#if canImport(Combine)
Expand Down
1 change: 0 additions & 1 deletion Sources/Sharing/Internal/SharedChangeTracker.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
public import Dependencies
import Foundation
public import IssueReporting

@_spi(SharedChangeTracking)
public struct SharedChangeTracker: Hashable, Sendable {
Expand Down
1 change: 0 additions & 1 deletion Sources/Sharing/SharedContinuations.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import IssueReporting

/// A mechanism to communicate with a shared key's external system, synchronously or asynchronously.
///
Expand Down
1 change: 0 additions & 1 deletion Sources/Sharing/SharedKeys/AppStorageKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import ConcurrencyExtras
public import Dependencies
@preconcurrency public import Foundation
import IssueReporting

#if canImport(AppKit)
import AppKit
Expand Down
1 change: 0 additions & 1 deletion Sources/Sharing/SharedReader.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import IssueReporting
public import Observation
public import PerceptionCore

Expand Down
1 change: 0 additions & 1 deletion Sources/Sharing/Traits/IdentifiedCollections.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#if IdentifiedCollections
public import IdentifiedCollections
import IssueReporting

extension RangeReplaceableCollection {
/// Creates an collection of shared elements from a shared collection.
Expand Down
151 changes: 151 additions & 0 deletions Sources/Sharing/Traits/IssueReporting.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#if IssueReporting
public import IssueReporting

@_transparent
func reportIssue(
_ message: @autoclosure () -> String? = nil,
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column
) {
IssueReporting.reportIssue(
message(),
fileID: fileID,
filePath: filePath,
line: line,
column: column
)
}

@_transparent
func reportIssue(
_ error: any Error,
_ message: @autoclosure () -> String? = nil,
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column
) {
IssueReporting.reportIssue(
error,
message(),
fileID: fileID,
filePath: filePath,
line: line,
column: column
)
}
#else
#if canImport(os)
public import os
public import Foundation
#else
@preconcurrency import Foundation
#endif

#if canImport(os)
@_transparent
#endif
public func reportIssue(
_ message: @autoclosure () -> String? = nil,
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column
) {
runtimeWarn(
message(),
fileID: fileID,
line: line,
)
}

#if canImport(os)
@_transparent
#endif
func reportIssue(
_ error: any Error,
_ message: @autoclosure () -> String? = nil,
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column
) {
runtimeWarn(
"Caught error: \(error)\(message().map { ": \($0)" } ?? "")",
fileID: fileID,
line: line,
)
}

#if canImport(os)
@_transparent
@inlinable
#endif
func runtimeWarn(
_ message: @autoclosure () -> String?,
fileID: StaticString,
line: UInt
) {
var message = message() ?? ""
if message.isEmpty {
message = "Issue reported"
}
#if canImport(os)
guard ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] != "1"
else {
print("🟣 \(fileID):\(line): \(message)")
return
}
let moduleName = String(
Substring("\(fileID)".utf8.prefix(while: { $0 != UTF8.CodeUnit(ascii: "/") }))
)
os_log(
.fault,
dso: dso,
log: OSLog(subsystem: "com.apple.runtime-issues", category: moduleName),
"%@",
"\(isTesting ? "\(fileID):\(line): " : "")\(message)"
)
#else
fputs("\(message)\n", stderr)
#endif
}

@usableFromInline nonisolated(unsafe) let dso: UnsafeRawPointer = {
#if canImport(os)
let count = _dyld_image_count()
for i in 0..<count {
if let name = _dyld_get_image_name(i) {
let swiftString = String(cString: name)
if swiftString.hasSuffix("/SwiftUI") {
if let header = _dyld_get_image_header(i) {
return UnsafeRawPointer(header)
}
}
}
}
#endif
return #dsohandle
}()

@usableFromInline let isTesting = ProcessInfo.processInfo.isTesting

extension ProcessInfo {
fileprivate var isTesting: Bool {
if environment.keys.contains("XCTestBundlePath") { return true }
if environment.keys.contains("XCTestBundleInjectPath") { return true }
if environment.keys.contains("XCTestConfigurationFilePath") { return true }
if environment.keys.contains("XCTestSessionIdentifier") { return true }

return arguments.contains { argument in
let path = URL(fileURLWithPath: argument)
return path.lastPathComponent == "swiftpm-testing-helper"
|| argument == "--testing-library"
|| path.lastPathComponent == "xctest"
|| path.pathExtension == "xctest"
}
}
}
#endif
Loading
Loading