-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Description
If a trait is disabled by default, there’s currently no way to enable it for testing within its package. It would be useful to be able to enable traits on a target from the manifest; otherwise, the only way to use them is by running swift test --enable-all-traits or swift test --traits Foo, which can be a bit awkward.
Expected behavior
Be able to do something like
.testTarget(
name: "PackageTests",
dependencies: [
"Package"
],
swiftSettings: [.enable(traits: ["Trait"])]
),Actual behavior
Tests using a trait, hidden by a #if Trait condition, are not run.
We can use swiftSettings: [.define("Trait")] however that enables the trait only in the test target and leads to compile errors because code in the sources (used by the test target) is still hidden by the #if condition and is therefore not compiled.
Steps to reproduce
No response
Swift Package Manager version/commit hash
No response
Swift & OS version (output of swift --version && uname -a)
Apple Swift version 6.1 (swift-6.1-RELEASE)
Target: arm64-apple-macosx16.0
Darwin Pauls-MacBook-Air.local 25.1.0 Darwin Kernel Version 25.1.0: Mon Oct 20 19:34:03 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T8112 arm64