Skip to content

unified: Always run corpus tests - #22248

Draft
tausbn wants to merge 2 commits into
mainfrom
tausbn/unified-always-run-corpus-tests
Draft

unified: Always run corpus tests#22248
tausbn wants to merge 2 commits into
mainfrom
tausbn/unified-always-run-corpus-tests

Conversation

@tausbn

@tausbn tausbn commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Changes our test setup so that the corpus tests are always run. In addition to this, it (hopefully) fixes the build so that both locally built swift-syntax-parser binaries and ones built using Bazel (if there isn't a local Swift toolchain) can be used.

tausbn and others added 2 commits July 29, 2026 11:58
The corpus tests skipped themselves when the `swift-syntax-parse` binary
could not be launched. That was meant to keep the suite usable without a
Swift toolchain, but it hid far more than it helped: a skip still
reports `test result: ok`, and the message explaining why only appears
under `cargo test -- --nocapture`. `scripts/update-corpus.sh` never set
the variable that locates the parser, so the documented way to
regenerate the corpus silently exercised nothing at all.

Drop the guard, so a missing parser fails loudly, and make the parser
easy to find so that failing is rare:

- Resolve the parser one directory above the running executable as well
  as beside it. Test binaries live in `target/<profile>/deps/`, so the
  existing sibling lookup could never find
  `target/<profile>/swift-syntax-parse` and `cargo test` always fell
  through to `PATH`.
- Report a missing binary with the command that builds it, rather than a
  bare `No such file or directory`.
- Build the parser in `scripts/update-corpus.sh`, so regenerating the
  corpus works from a clean checkout.

`cargo test` in `extractor` still needs the parser built first, since
the extractor deliberately does not depend on the crate that provides it
-- that is what keeps the Swift toolchain off the build path for the
other languages. `AGENTS.md` now says so.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Now that the corpus tests no longer skip themselves, running them
requires a `swift-syntax-parse` binary — and so far the only way to get
one was `cargo build`, which needs Swift installed locally. Bazel
already builds the same binary against a hermetic swift.org toolchain,
so offer that instead and make it the default.

The wrapper script locates its Swift runtime libraries beside itself, so
it only works in the flattened layout the extractor pack uses; under
`bazel-bin`, and in the runfiles tree, the libraries are in a different
directory and it fails to start. Add a `pkg_install` target that stages
that layout into a directory, and `scripts/build-parser.sh` to run it
and print the resulting path:

    export
CODEQL_EXTRACTOR_UNIFIED_SWIFT_SYNTAX_PARSE=$(scripts/build-parser.sh)

`--cargo` selects the previous behaviour, which is quicker to iterate on
when a local toolchain is available. Both pin swift-syntax 603.0.2, so
either parser produces the same trees.

`scripts/update-corpus.sh` now goes through the script and forwards its
arguments, so regenerating the corpus needs only Bazel. The staging
directory sits under `unified/target`, which is already ignored.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant