Skip to content

fix: make XCTest import conditional#129

Open
JP-Ellis wants to merge 1 commit intosurpher:feat/v2.0.0from
JP-Ellis:fix/xctest-conditional-import
Open

fix: make XCTest import conditional#129
JP-Ellis wants to merge 1 commit intosurpher:feat/v2.0.0from
JP-Ellis:fix/xctest-conditional-import

Conversation

@JP-Ellis
Copy link

@JP-Ellis JP-Ellis commented Mar 20, 2026

📝 Summary of Changes

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.

⚠️ Items of Note

🧐🗒 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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant