Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert #127 #130

Merged
merged 1 commit into from
Sep 11, 2024
Merged
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
39 changes: 7 additions & 32 deletions Sources/IssueReporting/Internal/SwiftTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,17 @@ func _withKnownIssue(
await withKnownIssue(message, isIntermittent, fileID, filePath, line, column, body)
}
@usableFromInline
func _currentTestData() -> (id: AnyHashable, isParameterized: Bool)? {
guard let function = function(for: "$s25IssueReportingTestSupport08_currentC4DataypyF")
func _currentTestID() -> AnyHashable? {
guard let function = function(for: "$s25IssueReportingTestSupport08_currentC2IDypyF")
else {
#if DEBUG
guard let id = Test.current?.id, let isParameterized = Test.Case.current?.isParameterized
else { return nil }
return (id, isParameterized)
return Test.current?.id
#else
return nil
#endif
}

return (function as! @Sendable () -> (id: AnyHashable, isParameterized: Bool)?)()
return (function as! @Sendable () -> AnyHashable?)()
}

#if DEBUG
Expand Down Expand Up @@ -354,8 +352,8 @@ func _currentTestData() -> (id: AnyHashable, isParameterized: Bool)? {
}
}

private struct Test: @unchecked Sendable {
fileprivate static var current: Self? {
struct Test: @unchecked Sendable {
static var current: Self? {
guard
let current = unsafeBitCast(
symbol: "$s7Testing4TestV7currentACSgvgZ",
Expand All @@ -366,30 +364,7 @@ func _currentTestData() -> (id: AnyHashable, isParameterized: Bool)? {
return current()
}

fileprivate struct Case {
static var current: Self? {
guard
let current = unsafeBitCast(
symbol: "$s7Testing4TestV4CaseV7currentAESgvgZ",
in: "Testing",
to: (@convention(thin) () -> Test.Case?).self
)
else { return nil }
return current()
}

private var arguments: [Argument]
private var body: @Sendable () async throws -> Void

fileprivate var isParameterized: Bool {
!arguments.isEmpty
}

private struct Argument: Sendable {
var value: any Sendable
var parameter: Parameter
}
}
struct Case {}
private var name: String
private var displayName: String?
private var traits: [any Trait]
Expand Down
17 changes: 4 additions & 13 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 {
/// If executed outside of a test process, this will return `nil`.
public static var current: Self? {
guard isTesting else { return nil }
if case let (id, isParameterized)? = _currentTestData() {
return .swiftTesting(Testing(id: id, isParameterized: isParameterized))
if let currentTestID = _currentTestID() {
return .swiftTesting(Testing(id: currentTestID))
} else {
return .xcTest
}
Expand All @@ -42,11 +42,7 @@ public enum TestContext: Equatable {

public struct Test: Equatable, Hashable, Identifiable, Sendable {
public let id: ID
public let `case`: Test.Case

public struct Case: Equatable, Hashable, Sendable {
public let isParameterized: Bool
}
public struct ID: Equatable, Hashable, @unchecked Sendable {
fileprivate let rawValue: AnyHashable
}
Expand Down Expand Up @@ -77,12 +73,7 @@ public enum TestContext: Equatable {
}

extension TestContext.Testing {
fileprivate init(id: AnyHashable, isParameterized: Bool) {
self.init(
test: Test(
id: Test.ID(rawValue: id),
case: Test.Case(isParameterized: isParameterized)
)
)
fileprivate init(id: AnyHashable) {
self.init(test: Test(id: Test.ID(rawValue: id)))
}
}
8 changes: 3 additions & 5 deletions Sources/IssueReportingTestSupport/SwiftTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,11 @@ private func __withKnownIssueAsync(
#endif
}

public func _currentTestData() -> Any { __currentTestData }
public func _currentTestID() -> Any { __currentTestID }
@Sendable
private func __currentTestData() -> (id: AnyHashable, isParameterized: Bool)? {
private func __currentTestID() -> AnyHashable? {
#if canImport(Testing)
guard let id = Test.current?.id, let isParameterized = Test.Case.current?.isParameterized
else { return nil }
return (id, isParameterized)
return Test.current?.id
#else
return nil
#endif
Expand Down
Loading