Search code examples
swiftxcodexctestswift-package-manager

Test SPM Package using optimization flag


I'm trying to test my swift package which relies on CryptoKit (SHA256 hash is very slow using debug config), and I would like to run the tests using optimization flags.

Using Xcode 11.4 Beta and macOS Catalina 10.15.3 (19D76). From the terminal, calling

swift test -c release

results in error:

error: module 'MyCoolPackage' was not compiled for testing
@testable import MyCoolPackage

So apparently I cannot use optimization flag by using the config named release (but we can can use -c release for the swift run command).

Without create a .xcodeproj file, can I run test with optimization?

Sure, I can generate a project file, but I don't want to do that... Can we run tests without the project file?


Solution

  • The magic terminal command is: swift test -Xswiftc -O