-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: add proc-macro capabilities to QL tests
#19800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
aibaars
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM , thanks!
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.