Make test discovery on by default

Swift 5.1 introduced test discovery to allow tests to be discovered on Linux. This works great but also means that if you use swift build having deleted the LinuxMain.swift it will fail to build without the --enable-test-discovery flag.

Can we make --enable-test-discovery on by default going forward?

1 Like

swift build shouldn’t fail if LinuxMain.swift is absent. That sounds like a bug. But yeah I think we can make test discovery on by default. Maybe we should emit a warning if there’s a LinuxMain.swift file present unless the flag is explicitly passed.

3 Likes

Doesn't swift build also build the test executable as well, so it needs either the test discovery flag or LinuxMain.swift?

+1 to making --enable-test-discovery on by default.

No, swift build only builds non test targets by default.

It has been finding everything flawlessly for me so far.

I can confirm this. It is the build plan assembly that fails, not compilation. The exact message reads:

error: missing LinuxMain.swift file in the Tests directory

In particular, this is where the error fires.

A completely empty file named LinuxMain.swift is sufficient to suppress the error. None of the XCTestManifests.swift files are necessary.

I might propose that, for the moment, rather than having an empty LinuxMain.swift it might be better to have one that contains an explanatory fatalError. That will ensure both that users who forget to use —enable-test-discovery will get a helpful message and that accidentally configuring a CI tool that forgets to pass this flag won’t lead to a quiet success.

4 Likes

Yes, please. +1.

Terms of Service

Privacy Policy

Cookie Policy