I have a SwiftPM test target that I want to build, but to run it in a special way (with a WebAssembly runtime). Unfortunately,
swift test always attempts to run the tests after building.
To elaborate, I have
.testTarget(name: "Tests") in my
Package.swift . What
swift test does is that it creates a test bundle for the whole package. It then attempts to run it (with either
xctest runner on macOS or directly on Linux) and fails because the WebAssembly bundle can only be run with a WebAssembly runtime. I've tried to build tests separately without running, but
swift build --target Tests doesn't build the test bundle for me.
I don't think there is a clean workaround to get the test bundle built without a failing
swift test invocation. I currently see multiple potential solutions:
- Adding a new
swift test, which will produce a test bundle, but won't run it, so a user later can do whatever they want with the bundle (feed it to a WASI runtime in our case).
- Adding a new
swift test, which takes a runtime command as an argument. This one is more intrusive and complicated, and the test runner itself could also take arguments (e.g. if it's a browser runtime, we need to pass some additional arguments to launch a browser properly).
- A separate flag for
swift buildthat builds a package test bundle without running it. Just another variation of option 1, but shifts the end-user interface from
Overall I'm inclined towards option 1, and hoping to prepare a PR if there are no objections, but maybe I'm missing anything? Any thoughts or suggestions? Thanks!