From 6cbc73b93a46b752e910e73d68f47fc4768f6a93 Mon Sep 17 00:00:00 2001 From: Gemma Barlow Date: Mon, 23 Sep 2024 12:47:43 -0400 Subject: [PATCH] Address build issues occurring when building with Library Evolution support, 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 --- .github/workflows/ci.yml | 2 +- Sources/IssueReporting/ReportIssue.swift | 74 ++++++------ .../IssueReporting/WithExpectedIssue.swift | 105 ++++++++++-------- 3 files changed, 98 insertions(+), 83 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6833bd6..1b02572 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/Sources/IssueReporting/ReportIssue.swift b/Sources/IssueReporting/ReportIssue.swift index f92646e..3a2af15 100644 --- a/Sources/IssueReporting/ReportIssue.swift +++ b/Sources/IssueReporting/ReportIssue.swift @@ -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 } @@ -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 } } @@ -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 } @@ -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 } } diff --git a/Sources/IssueReporting/WithExpectedIssue.swift b/Sources/IssueReporting/WithExpectedIssue.swift index 91345ae..1e5b4f7 100644 --- a/Sources/IssueReporting/WithExpectedIssue.swift +++ b/Sources/IssueReporting/WithExpectedIssue.swift @@ -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) { @@ -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 @@ -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) { @@ -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 + } }