You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add experimental flag which allows providing a custom test entry point file while still performing test discovery (#5709)
Add experimental flag which allows providing a custom test entry point file while still performing test discovery
There are situations where a user may wish to customize the entry point file used to run tests on non-Apple platforms via `swift test`. For example, to run custom code before invoking the `XCTMain(...)` function. But including a custom `XCTMain.swift` file (or its former name, `LinuxMain.swift`) causes `swift test` to solely rely on that file to run tests, and more importantly, it causes SwiftPM to skip automatic test discovery, so you end up needing to list all the tests to run in that file. Passing `--enable-test-discovery` explicitly does the opposite: it performs test discovery, synthesizes its own test entry point file, and ignores any custom entry point file present in the package.
This PR adds a way to both provide a custom test entry point file and still perform test discovery, allowing the entry point to reference the automatically-discovered tests and pass them to `XCTMain(...)`. It enables this behavior when passing a new, experimental flag `--experimental-test-entry-point-path <file>`.
rdar://97940043
@@ -155,24 +155,76 @@ final class TestDiscoveryCommand: CustomLLBuildCommand {
155
155
156
156
stream <<<"import XCTest"<<<"\n\n"
157
157
158
-
stream <<<"@main"<<<"\n"
159
158
stream <<<"@available(*, deprecated, message: \"Not actually deprecated. Marked as deprecated to allow inclusion of deprecated tests (which test deprecated functionality) without warnings\")"<<<"\n"
throwInternalError("main file output (\(LLBuildManifest.TestEntryPointTool.mainFileName)) not found")
208
+
}
209
+
210
+
// Write the main file.
211
+
letstream=tryLocalFileOutputByteStream(mainFile)
212
+
213
+
stream <<<"import XCTest"<<<"\n"
214
+
fordiscoveryModuleNamein discoveryModuleNames {
215
+
stream <<<"import \(discoveryModuleName)"<<<"\n"
216
+
}
217
+
stream <<<"\n"
218
+
219
+
stream <<<"@main"<<<"\n"
220
+
stream <<<"@available(*, deprecated, message: \"Not actually deprecated. Marked as deprecated to allow inclusion of deprecated tests (which test deprecated functionality) without warnings\")"<<<"\n"
0 commit comments