Skip to content

Commit

Permalink
Address build issues occurring when building with Library Evolution s…
Browse files Browse the repository at this point in the history
…upport, Xcode 16 (#133)

* Address build issues in Library Evolution mode

Address build issues seen building for library evolution mode, Xcode 16 - i.e. `make build-for-library-evolution`.

* Update ci.yml

---------

Co-authored-by: Stephen Celis <[email protected]>
  • Loading branch information
gemmakbarlow and stephencelis authored Sep 23, 2024
1 parent b22b6ae commit 6cbc73b
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_15.4.app
run: sudo xcode-select -s /Applications/Xcode_16.0.app
- name: Run tests
run: make build-for-library-evolution

Expand Down
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
}
}

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
}
}

0 comments on commit 6cbc73b

Please sign in to comment.