Skip to content

Add discover_xctests to swift_test for Swift Testing-only targets - #1980

Closed
andyf-canva wants to merge 1 commit into
bazelbuild:mainfrom
andyf-canva:swift-test-discover-xctests
Closed

andyf-canva wants to merge 1 commit into
bazelbuild:mainfrom
andyf-canva:swift-test-discover-xctests

Conversation

@andyf-canva

@andyf-canva andyf-canva commented Oct 27, 2026 •

Copy link
Copy Markdown

On non-Apple platforms, swift_test with discover_tests = True always extracts symbol graphs for the owner module and its direct deps so the test discoverer can find XCTest-style classes and methods, even when the target only contains Swift Testing @Test functions, which are discovered at run time. Besides being unneeded work, the extraction can fail outright: swift-symbolgraph-extract cannot currently load a module compiled with -cxx-interoperability-mode=default against libstdc++ on Linux (cannot load underlying module for 'CxxStdlib', fix proposed in swiftlang/swift#93696), so any Swift Testing target that depends on such a module fails to build even though swiftc compiles it. The only workaround today is discover_tests = False and a hand-written main that calls into Swift Testing.

Add a discover_xctests attribute to swift_test (default True, so existing targets are unchanged). When it is False and discover_tests is True, the rule skips the owner symbol graph extraction and dep symbol graph collection, passes a new --swift-testing-only flag to the test discoverer with no symbol graph inputs or --module-outputs, and the generated runner keeps the same @main shape but omits the XCTestRunner.run(__allDiscoveredXCTests()) block. The attribute has no effect when discover_tests = False.

Adds passing and failing Swift Testing-only fixtures and shell tests next to the existing Swift Testing ones, and regenerates doc/rules.md. Verified on Linux (Swift 6.4, remote execution) with three Swift Testing-only targets that depend on a C++-interop module: with discover_xctests = False the symbol graph actions disappear from the build and all three pass.

`swift_test` with `discover_tests = True` always extracts symbol graphs on
non-Apple platforms so the test discoverer can find XCTest-style tests,
even when a target contains only Swift Testing `@Test` functions. Swift
Testing discovers its tests at run time, so for those targets the
extraction is wasted work. It can also fail outright: a module compiled
with `-cxx-interoperability-mode=default` against libstdc++ cannot be
loaded by `swift-symbolgraph-extract` on Linux, so the whole test target
fails to build.

Add a `discover_xctests` attribute (default `True`). Setting it to `False`
skips the owner symbol graph extraction, passes a new
`--swift-testing-only` flag to the test discoverer, and generates a runner
that only runs Swift Testing tests. The attribute has no effect when
`discover_tests` is `False`.

Add passing and failing Swift Testing-only fixtures and shell tests, and
regenerate `doc/rules.md`.
@google-cla

google-cla Bot commented Oct 27, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant