Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 11 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ let package = Package(
],
targets: [
.target(
name: "IssueReporting"
name: "IssueReportingPackageSupport"
),
.target(
name: "IssueReporting",
dependencies: [
"IssueReportingPackageSupport"
]
),
.testTarget(
name: "IssueReportingTests",
Expand All @@ -32,7 +38,10 @@ let package = Package(
]
),
.target(
name: "IssueReportingTestSupport"
name: "IssueReportingTestSupport",
dependencies: [
"IssueReportingPackageSupport"
]
),
.target(
name: "XCTestDynamicOverlay",
Expand Down
13 changes: 11 additions & 2 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ let package = Package(
],
targets: [
.target(
name: "IssueReporting"
name: "IssueReportingPackageSupport"
),
.target(
name: "IssueReporting",
dependencies: [
"IssueReportingPackageSupport",
]
),
.testTarget(
name: "IssueReportingTests",
Expand All @@ -31,7 +37,10 @@ let package = Package(
]
),
.target(
name: "IssueReportingTestSupport"
name: "IssueReportingTestSupport",
dependencies: [
"IssueReportingPackageSupport",
]
),
.target(
name: "XCTestDynamicOverlay",
Expand Down
11 changes: 6 additions & 5 deletions Sources/IssueReporting/Internal/SwiftTesting.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import IssueReportingPackageSupport

#if canImport(WinSDK)
import WinSDK
Expand Down Expand Up @@ -313,17 +314,17 @@ func _withKnownIssue(
#endif

@usableFromInline
func _currentTestID() -> AnyHashable? {
guard let function = function(for: "$s25IssueReportingTestSupport08_currentC2IDypyF")
func _currentTest() -> _Test? {
guard let function = function(for: "$s25IssueReportingTestSupport08_currentC0ypyF")
else {
#if DEBUG
return Test.current?.id
return Test.current.map { _Test(id: $0.id, traits: $0.traits) }
#else
return nil
#endif
}

return (function as! @Sendable () -> AnyHashable?)()
return unsafeBitCast(function, to: (@Sendable () -> _Test?).self)()
}

#if DEBUG
Expand Down Expand Up @@ -446,7 +447,7 @@ func _currentTestID() -> AnyHashable? {
struct Case {}
private var name: String
private var displayName: String?
private var traits: [any Trait]
fileprivate var traits: [any Trait]
private var sourceLocation: SourceLocation
private var containingTypeInfo: TypeInfo?
private var xcTestCompatibleSelector: __XCTestCompatibleSelector?
Expand Down
17 changes: 13 additions & 4 deletions Sources/IssueReporting/TestContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public enum TestContext: Equatable, Sendable {
/// If executed outside of a test process, this will return `nil`.
public static var current: Self? {
guard isTesting else { return nil }
if let currentTestID = _currentTestID() {
return .swiftTesting(Testing(id: currentTestID))
if let currentTest = _currentTest() {
return .swiftTesting(Testing(id: currentTest.id, traits: currentTest.traits))
} else {
return .xcTest
}
Expand All @@ -42,10 +42,19 @@ public enum TestContext: Equatable, Sendable {

public struct Test: Equatable, Hashable, Identifiable, Sendable {
public let id: ID
public let traits: [any Sendable]

public struct ID: Equatable, Hashable, @unchecked Sendable {
public let rawValue: AnyHashable
}

public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.id == rhs.id
}

public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
}

Expand Down Expand Up @@ -73,7 +82,7 @@ public enum TestContext: Equatable, Sendable {
}

extension TestContext.Testing {
fileprivate init(id: AnyHashable) {
self.init(test: Test(id: Test.ID(rawValue: id)))
fileprivate init(id: AnyHashable, traits: [any Sendable]) {
self.init(test: Test(id: Test.ID(rawValue: id), traits: traits))
}
}
14 changes: 14 additions & 0 deletions Sources/IssueReportingPackageSupport/_Test.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@usableFromInline
package struct _Test {
@usableFromInline
package let id: AnyHashable

@usableFromInline
package let traits: [any Sendable]

@usableFromInline
package init(id: AnyHashable, traits: [any Sendable]) {
self.id = id
self.traits = traits
}
}
8 changes: 5 additions & 3 deletions Sources/IssueReportingTestSupport/SwiftTesting.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import IssueReportingPackageSupport

#if canImport(Testing)
import Testing
#endif
Expand Down Expand Up @@ -134,11 +136,11 @@ private func __withKnownIssueAsync(
}
#endif

public func _currentTestID() -> Any { __currentTestID }
public func _currentTest() -> Any { __currentTest }
@Sendable
private func __currentTestID() -> AnyHashable? {
private func __currentTest() -> _Test? {
#if canImport(Testing)
return Test.current?.id
return Test.current.map { _Test(id: $0.id, traits: $0.traits) }
#else
return nil
#endif
Expand Down
Loading