Rust: add proc-macro capabilities to QL tests#19800
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR extends QL tests with procedural macro support by generating a separate proc_macro crate for test macros and migrating the macro-expansion extractor tests to use this new setup. It introduces a Mustache-based template for Cargo manifest generation and updates the extractor harness accordingly.
- Replace custom Cargo manifest code with a Mustache template and
TestCargoManifestinqltest.rs. - Add
proc_macro.rs, new test code (macro_expansion.rs,call.rs), and updated QL tests/expected outputs underextractor-tests/macro-expansion. - Remove legacy underscore-named tests and integration Python test, update Bazel build files to include the Mustache template.
Reviewed Changes
Copilot reviewed 27 out of 33 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| rust/ql/test/extractor-tests/macro_expansion/test.ql | Removed old underscore-named QL test |
| rust/ql/test/extractor-tests/macro_expansion/*.expected, options.yml, macro_expansion.rs | Removed legacy extractor tests |
| rust/ql/test/extractor-tests/macro-expansion/test.ql | Added new QL test with Diagnostics import and warnings predicate |
| rust/ql/test/extractor-tests/macro-expansion/test.expected | New expected output for macro-expansion test |
| rust/ql/test/extractor-tests/macro-expansion/proc_macro.rs | Added procedural macro definitions (add_one, erase) |
| rust/ql/test/extractor-tests/macro-expansion/macro_expansion.rs | New Rust code exercising attribute and function-like macros |
| rust/ql/test/extractor-tests/macro-expansion/call.rs | Test harness calls expanded functions |
| rust/ql/test/extractor-tests/macro-expansion/CONSISTENCY/PathResolutionConsistency.expected | Added path-resolution consistency test |
| rust/ql/test/.gitignore | Ignore generated .proc_macro/ and .lib/ directories |
| rust/ql/integration-tests/macro-expansion/* | Removed old Python integration test and expected outputs |
| rust/extractor/src/qltest_cargo.mustache | New Mustache template for Cargo.toml generation |
| rust/extractor/src/qltest.rs | Introduce TestCargoManifest and replace manifest logic |
| rust/extractor/Cargo.toml | Added mustache = "0.9.0" dependency |
| rust/extractor/BUILD.bazel | Include Mustache template in build inputs |
| misc/bazel/3rdparty/tree_sitter_extractors_deps/defs.bzl | Add mustache to Bazel external dependencies |
This adds the possibility to add a special `proc_macro.rs` source file to QL tests, which will be generated into a `proc_macro` crate the usual `lib` crate depends on. This allow to define procedural macros in QL tests, and is here used to move the `macro-expansion` integration test to be a language test instead. As the generated manifests involved were starting to get a bit complex, they are now generated from a `mustache` template.
ba24cc6 to
299fe2e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds the possibility to add a special
proc_macro.rssource file to QL tests, which will be generated into aproc_macrocrate the usuallibcrate depends on.This allow to define procedural macros in QL tests, and is here used to move the
macro-expansionintegration test to be a language test instead.As the generated manifests involved were starting to get a bit complex, they are now generated from a
mustachetemplate.The path resolution inconsistency might have to do with using a
..path for the crate sources, might be worth investigating in a follow-up.