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

Address build issues occurring when building with Library Evolution support, Xcode 16 #133

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
74 changes: 41 additions & 33 deletions Sources/IssueReporting/ReportIssue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,7 @@ public func reportIssue(
line: UInt = #line,
column: UInt = #column
) {
switch TestContext.current {
case .swiftTesting:
_recordIssue(
message: message(),
fileID: "\(IssueContext.current?.fileID ?? fileID)",
filePath: "\(IssueContext.current?.filePath ?? filePath)",
line: Int(IssueContext.current?.line ?? line),
column: Int(IssueContext.current?.column ?? column)
)
case .xcTest:
_XCTFail(
message().withAppHostWarningIfNeeded() ?? "",
file: IssueContext.current?.filePath ?? filePath,
line: IssueContext.current?.line ?? line
)
case nil:
guard let context = TestContext.current else {
guard !isTesting else { return }
if let observer = FailureObserver.current {
observer.withLock { $0 += 1 }
Expand All @@ -73,6 +58,25 @@ public func reportIssue(
)
}
}
return
}

switch context {
case .swiftTesting:
_recordIssue(
message: message(),
fileID: "\(IssueContext.current?.fileID ?? fileID)",
filePath: "\(IssueContext.current?.filePath ?? filePath)",
line: Int(IssueContext.current?.line ?? line),
column: Int(IssueContext.current?.column ?? column)
)
case .xcTest:
_XCTFail(
message().withAppHostWarningIfNeeded() ?? "",
file: IssueContext.current?.filePath ?? filePath,
line: IssueContext.current?.line ?? line
)
@unknown default: break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's worth reporting issues from this branch? From a practical perspective I can't see this unknown branch ever hitting, though, so this should be OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely went back-and-forth about combining this with the nil branch case somehow. I ultimately came to the same conclusion you did; unlikely to fire in practice.

}
}

Expand All @@ -97,23 +101,7 @@ public func reportIssue(
line: UInt = #line,
column: UInt = #column
) {
switch TestContext.current {
case .swiftTesting:
_recordError(
error: error,
message: message(),
fileID: "\(IssueContext.current?.fileID ?? fileID)",
filePath: "\(IssueContext.current?.filePath ?? filePath)",
line: Int(IssueContext.current?.line ?? line),
column: Int(IssueContext.current?.column ?? column)
)
case .xcTest:
_XCTFail(
"Caught error: \(error)\(message().map { ": \($0)" } ?? "")".withAppHostWarningIfNeeded(),
file: IssueContext.current?.filePath ?? filePath,
line: IssueContext.current?.line ?? line
)
case nil:
guard let context = TestContext.current else {
guard !isTesting else { return }
if let observer = FailureObserver.current {
observer.withLock { $0 += 1 }
Expand All @@ -139,5 +127,25 @@ public func reportIssue(
)
}
}
return
}

switch context {
case .swiftTesting:
_recordError(
error: error,
message: message(),
fileID: "\(IssueContext.current?.fileID ?? fileID)",
filePath: "\(IssueContext.current?.filePath ?? filePath)",
line: Int(IssueContext.current?.line ?? line),
column: Int(IssueContext.current?.column ?? column)
)
case .xcTest:
_XCTFail(
"Caught error: \(error)\(message().map { ": \($0)" } ?? "")".withAppHostWarningIfNeeded(),
file: IssueContext.current?.filePath ?? filePath,
line: IssueContext.current?.line ?? line
)
@unknown default: break
}
}
105 changes: 56 additions & 49 deletions Sources/IssueReporting/WithExpectedIssue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,7 @@ public func withExpectedIssue(
column: UInt = #column,
_ body: () throws -> Void
) {
switch TestContext.current {
case .swiftTesting:
_withKnownIssue(
message,
isIntermittent: isIntermittent,
fileID: fileID.description,
filePath: filePath.description,
line: Int(line),
column: Int(column),
body
)
case .xcTest:
_XCTExpectFailure(
message.withAppHostWarningIfNeeded(),
strict: !isIntermittent,
file: filePath,
line: line
) {
do {
try body()
} catch {
reportIssue(error, fileID: fileID, filePath: filePath, line: line, column: column)
}
}
case nil:
guard let context = TestContext.current else {
guard !isTesting else { return }
let observer = FailureObserver()
FailureObserver.$current.withValue(observer) {
Expand Down Expand Up @@ -107,6 +83,33 @@ public func withExpectedIssue(
}
return
}

switch context {
case .swiftTesting:
_withKnownIssue(
message,
isIntermittent: isIntermittent,
fileID: fileID.description,
filePath: filePath.description,
line: Int(line),
column: Int(column),
body
)
case .xcTest:
_XCTExpectFailure(
message.withAppHostWarningIfNeeded(),
strict: !isIntermittent,
file: filePath,
line: line
) {
do {
try body()
} catch {
reportIssue(error, fileID: fileID, filePath: filePath, line: line, column: column)
}
}
@unknown default: break
}
}

/// Invoke an asynchronous function that has an issue that is expected to occur during its
Expand Down Expand Up @@ -137,31 +140,8 @@ public func withExpectedIssue(
column: UInt = #column,
_ body: () async throws -> Void
) async {
switch TestContext.current {
case .swiftTesting:
await _withKnownIssue(
message,
isIntermittent: isIntermittent,
fileID: fileID.description,
filePath: filePath.description,
line: Int(line),
column: Int(column),
body
)
case .xcTest:
reportIssue(
"""
Asynchronously expecting failures is unavailable in XCTest.

Omit this test from your XCTest suite, or consider using Swift Testing, instead.
""",
fileID: fileID,
filePath: filePath,
line: line,
column: column
)
try? await body()
case nil:
guard let context = TestContext.current else {
guard !isTesting else { return }
let observer = FailureObserver()
await FailureObserver.$current.withValue(observer) {
Expand Down Expand Up @@ -193,4 +173,31 @@ public func withExpectedIssue(
}
return
}

switch context {
case .swiftTesting:
await _withKnownIssue(
message,
isIntermittent: isIntermittent,
fileID: fileID.description,
filePath: filePath.description,
line: Int(line),
column: Int(column),
body
)
case .xcTest:
reportIssue(
"""
Asynchronously expecting failures is unavailable in XCTest.

Omit this test from your XCTest suite, or consider using Swift Testing, instead.
""",
fileID: fileID,
filePath: filePath,
line: line,
column: column
)
try? await body()
@unknown default: break
}
}