Skip to content

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

Merged
merged 9 commits into from
Jun 18, 2025

Conversation

redsun82
Copy link
Contributor

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.

The path resolution inconsistency might have to do with using a .. path for the crate sources, might be worth investigating in a follow-up.

@Copilot Copilot AI review requested due to automatic review settings June 17, 2025 14:53
@redsun82 redsun82 requested review from a team as code owners June 17, 2025 14:53
@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jun 17, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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 TestCargoManifest in qltest.rs.
  • Add proc_macro.rs, new test code (macro_expansion.rs, call.rs), and updated QL tests/expected outputs under extractor-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.
@redsun82 redsun82 force-pushed the redsun82/rust-qltest-proc-macro branch from ba24cc6 to 299fe2e Compare June 17, 2025 14:58
Copy link
Contributor

@aibaars aibaars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM , thanks!

@redsun82 redsun82 merged commit ddc065b into main Jun 18, 2025
31 of 32 checks passed
@redsun82 redsun82 deleted the redsun82/rust-qltest-proc-macro branch June 18, 2025 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants