fix: make XCTest import conditional#129
Open
JP-Ellis wants to merge 1 commit intosurpher:feat/v2.0.0from
Open
Conversation
Wrap `import XCTest` in `ErrorReporter.swift` with `#if canImport(XCTest)` so PactSwift compiles with the standalone Swift toolchain (e.g. mise-managed swift.org builds) where XCTest is not available without Xcode's SDK. - On Apple platforms with Xcode: XCTest path unchanged, `XCTFail` used as before. - Without XCTest (standalone toolchain, Linux): `preconditionFailure` fallback. `ProviderVerifier.swift` had a superfluous `import XCTest` that was unused at the call site (all XCTest usage is in `ErrorReporter`) — removed. Signed-off-by: JP-Ellis <josh@jpellis.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Summary of Changes
Wrap
import XCTestinErrorReporter.swiftwith#if canImport(XCTest)so PactSwift compiles with the standalone Swift toolchain (e.g. mise-managed swift.org builds) where XCTest is not available without Xcode's SDK.XCTFailused as before.preconditionFailurefallback.ProviderVerifier.swifthad a superfluousimport XCTestthat was unused at the call site (all XCTest usage is inErrorReporter) — removed.🧐🗒 Reviewer Notes
I ran into this issue while trying to code up an example using the v2 feature branch, trying to run it against Swift 6 managed by mise to try and have a cross-platform example, using the Swift Testing framework.
I will be honest, I am not an expert with Swift, and the changes in this PR were suggested by an LLM; however, I this did resolve the issue with the example and the change itself does seem quite sensible.
💁 Example
The examples repo is not yet public, but I fully intend to make it public once it has been through a couple of rounds of review. I'll let you know!
🔨 How To Test
This is where my Swift knowledge fails me 😅 I have tested this change using a locally patched package with a full example, but I'm not sure how best to add test coverage for this specifically within this repo. Feel free to point me in the right direction if you need me to add some unit tests specifically for this.