[PITCH] Enable Test Discovery by Default

I wonder if we could add an annotation to the top of LinuxMain.swift - something like:

// swift-package-is-discovery-warning

And when SPM sees that, it’ll know that LinuxMain is just a dummy file for back-compat purposes, and that it should still use test discovery rather than compiling LinuxMain.

1 Like

Can we at least silence the warning? grpc-swift gets this nasty combination of outcomes:

root@368b93eb7b6d:/code# swift test --enable-test-discovery
warning: '--enable-test-discovery' option is deprecated; tests are automatically discovered on all platforms
root@368b93eb7b6d:/code# swift test
[4/4] Build complete!
grpc_swiftPackageTests/LinuxMain.swift:16: Fatal error: Use --enable-test-discovery to run tests on Linux

If SwiftPM is going to insist to invoke the LinuxMain.swift, then it shouldn't get mad if --enable-test-discovery is passed to circumvent the behaviour. In that mode of operation the flag isn't deprecated: it has a clear, proactive behaviour that users genuinely want.

2 Likes

Why are you keeping a LinuxMain.swift if it isn't supposed to be used? To tell users on older SwiftPM versions about the test discovery flag?

Yes, the failure mode on older SwiftPM versions is very difficult to diagnose without it.

1 Like

Remember that on Swift 5.3, today, if you run a Swift project that does not have a LinuxMain.swift file then nonsense like this happens:

root@f755702b5820:/code# swift run micro-function 8080
error: missing LinuxMain.swift file in the Tests directory

This of course is very unpleasant, and there were only two options: either pass --enable-test-discovery (a weird thing to have to pass to run) or add a do-nothing LinuxMain.swift file that told users what to do.

That makes sense, we hadn't thought about this case when designing the behavior. It makes sense to me to omit the warning if there is an existing LinuxMain.swift.

how about refine when --enable-test-discovery deprecation warning is emmited by tomerd · Pull Request #3390 · apple/swift-package-manager · GitHub?

2 Likes

Seems like a solid improvement, thanks!