Skip to content

Commit

Permalink
fix: update issue reporting library
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahKamara committed Oct 24, 2024
1 parent 6e99619 commit dcb3b4a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 99 deletions.
18 changes: 9 additions & 9 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
"version" : "1.0.0"
}
},
{
"identity" : "swift-issue-reporting",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-issue-reporting",
"state" : {
"revision" : "770f990d3e4eececb57ac04a6076e22f8c97daeb",
"version" : "1.4.2"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
Expand All @@ -44,15 +53,6 @@
"branch" : "main",
"revision" : "cc7414718464f58d3391195afeb4d48fb98d8818"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "b13b1d1a8e787a5ffc71ac19dcaf52183ab27ba2",
"version" : "1.1.1"
}
}
],
"version" : 2
Expand Down
9 changes: 3 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,18 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/noahkamara/swift-xctesting", branch: "main"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.1.1")
.package(url: "https://github.com/pointfreeco/swift-issue-reporting", from: "1.2.2")
],
targets: [
.target(
name: "CompoundPredicate",
dependencies: [
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay")
.product(name: "IssueReporting", package: "swift-issue-reporting")
]
),
.testTarget(
name: "CompoundPredicateTests",
dependencies: [
"CompoundPredicate",
.product(name: "XCTesting", package: "swift-xctesting")
]
dependencies: ["CompoundPredicate"]
// linkerSettings: [
// .unsafeFlags([
// "-Xlinker", "-sectcreate",
Expand Down
3 changes: 2 additions & 1 deletion Sources/CompoundPredicate/Predicate+combining.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import IssueReporting

fileprivate extension StandardPredicateExpression<Bool> {
///
Expand All @@ -22,7 +23,7 @@ fileprivate extension StandardPredicateExpression<Bool> {
if let replacingExpr = self as? any VariableReplacing<Output> {
return replacingExpr.replacing(variable, with: replacement) as! Self
} else {
runtimeWarn("""
reportIssue("""
\(Self.self) is not a supported Predicate.
Check that this expression and any child-expressions conform to `VariableReplacing`
Expand Down
84 changes: 1 addition & 83 deletions Sources/CompoundPredicate/RuntimeWarnings.swift
Original file line number Diff line number Diff line change
@@ -1,86 +1,4 @@


import Foundation

public extension Notification.Name {
static let foundationExtensionsRuntimeWarning: Self = .init(
rawValue: "FoundationExtensions.runtimeWarning"
)
}

@_transparent
@inlinable
@inline(__always)
func runtimeWarn(
_ message: @autoclosure () -> String,
category: String? = "FoundationExtensions",
notificationName: Notification.Name? = .foundationExtensionsRuntimeWarning
) {
#if DEBUG
let message = message()
notificationName.map { notificationName in
NotificationCenter.default.post(
name: notificationName,
object: nil,
userInfo: ["message": message]
)
}

let category = category ?? "Runtime Warning"

if _XCTIsTesting {
XCTFail(message)
} else {
#if canImport(os)
os_log(
.fault,
dso: dso,
log: OSLog(subsystem: "com.apple.runtime-issues", category: category),
"%@",
message
)
#else
fputs("\(formatter.string(from: Date())) [\(category)] \(message)\n", stderr)
#endif
}
#endif
}

#if DEBUG

import XCTestDynamicOverlay

#if canImport(os)
import os

// NB: Xcode runtime warnings offer a much better experience than traditional assertions and
// breakpoints, but Apple provides no means of creating custom runtime warnings ourselves.
// To work around this, we hook into SwiftUI's runtime issue delivery mechanism, instead.
//
// Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc
@usableFromInline
let dso = { () -> UnsafeMutableRawPointer in
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 UnsafeMutableRawPointer(mutating: UnsafeRawPointer(header))
}
}
}
}
return UnsafeMutableRawPointer(mutating: #dsohandle)
}()
#else
import Foundation

@usableFromInline
let formatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:MM:SS.sssZ"
return formatter
}()
#endif
#endif
import IssueReporting

0 comments on commit dcb3b4a

Please sign in to comment.