I am writing my first program in Swift just to check it out. I downloaded following release without Xcode from Swift.org - Not Found
% swift --version
Apple Swift version 5.7.2 (swift-5.7.2-RELEASE)
I created a scaffold project using the command line but when I try to run tests I get this error:
% swift test
error: XCTest not available
How can I fix this? I tried searching online but could not find any solution.
PS: I don't want to install Xcode
Install Xcode. Toolchains aren't meant to be used without it. You might be able to get away with just the command line tools instead, but I doubt it.
This is a known issues because the Swift toolchain doesn't include the Objective-C runtime which is what's used on macOS for testing - [SR-15020] swift test fails on macOS without Xcode · Issue #4396 · apple/swift-package-manager · GitHub
As an FYI it's a long term goal of the SSWG to be able to build Swift projects on macOS with just the toolchain and no' Xcode, e.g. using VSCode
Thanks Tim. Is there any way to test without XCTest? perhaps another test framework?
Unfortunately not, no. At least not without writing a new subcommand to call instead of
swift test or forking Swift and changing the way
swift test works
And what does it mean if I have Xcode installed but I'm still getting that message?
Make sure Homebrew hasn't screwed up the Swift installation by running
sudo xcode-select -s /Applications/Xcode.app (or wherever you have Xcode installed). Homebrew has a habit of overriding the command line tools with whatever it needs which can cause issues like this
Thanks; I am learning to loathe Homebrew more each day.
I have to say that in about 10 years of using MacPorts first and for about 6-7 of those years of using Homebrew (created a portable config / setup that goes on every of the team’s machines including the CI build agents which run macOS, now bare metal IaaS on Flow.Swiss) I have never seen it mess with the command line tools path which does not mean it cannot happen, maybe we avoided it. I can add it to the list of things to be on the lookout for, but not something I can complain about Homebrew. It definitely helped us automate our setup more.
Why do you hate homebrew (I know hate is a strong word :))? I have much more of an issue with either the lack of access to some command line tools or having an older version than needed because of licensing constraints on macOS… for a lot of things this helps with an environment that is closer to upstream and easier to get help with as a result.
It's perhaps a very personal thing that nobody else runs into, but the course of this issue pretty much sums it up.
Oh no worries, they were a bit rude… it is weird why you are not seeing the shellenv bit in the installer script output.
It seems like something is missing from the Intel homebrew setup…
I have not checked that in a while as we saved that step in the brew installed setup phase: