Test discovery on Linux

You can file that as a bug. (bugs.swift.org) At the very least it should refuse --configuration release --enable-test-discovery immediately with a clear explanation, before wasting time attempting the impossible. However, simply removing @testable would not solve the problem unless you also made the tests themselves public, so actually making such usage possible would be a lot more complex.

I've been able to work it around using the -enable-testing flag when compiling the test target.

Here's how it looks in my Package.swift:

.testTarget(name: "MyPackageTests",
            dependencies: ["MyPackage"],
            swiftSettings: [.unsafeFlags(["-enable-testing"])])

Note that the usage of unsafeFlags here is OK, since it's a test target.

2 Likes

That is a clever way to make the build succeed. To minimize interference, you may as well add .when(configuration: .release).

But if you are just going to apply debug flags anyway, it kind of defeats the point of specifying --configuration release in the first place. So I’m not sure what the advantage is, unless some outside tool is forcefully applying the release flag to your package and you need to work around it.

1 Like

Thanks, I'll try that as a temporary measure. The primary use case for me is testing performance, which needs --configuration release for an accurate benchmark. I'll file a bug later today.

Hello! For what it’s worth, I think I found a new bug in the test discovery on Linux. Here is my bug report [SR-12711] Test Discovery Fails When Test Target Contains Non-Alphanum Chars · Issue #55156 · apple/swift · GitHub.