-
Notifications
You must be signed in to change notification settings - Fork 346
Test procmacros #4372
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
Test procmacros #4372
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 adds comprehensive unit tests for the procedural macros in esp-hal-procmacros, verifying both successful code expansion and error handling for various edge cases. The tests check that attribute macros like #[ram], #[handler], #[rtos_main], #[doc_replace], #[entry], and #[builder_lite] generate correct code and emit appropriate compile errors for invalid inputs.
Key changes:
- Added test modules to each procmacro implementation file with extensive test coverage
- Refactored internal functions to accept
proc_macro2::TokenStreaminstead ofproc_macro::TokenStreamfor testability - Added
unwrap_or_compile_error!macro to standardize error handling - Modified doc comment code examples to use
ignoreinstead ofno_run
Reviewed Changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| xtask/src/lib.rs | Added test configuration for esp-hal-procmacros package with required feature flags |
| esp-hal-procmacros/Cargo.toml | Excluded testdata directory from package |
| esp-hal-procmacros/src/lib.rs | Added unwrap_or_compile_error! macro, updated public API to convert between TokenStream types, changed doc examples to ignore |
| esp-hal-procmacros/src/rtos_main.rs | Refactored to use proc_macro2::TokenStream, added 8 test cases for various scenarios |
| esp-hal-procmacros/src/ram.rs | Refactored to use proc_macro2::TokenStream, added 19 test cases covering different ram placement options |
| esp-hal-procmacros/src/lp_core.rs | Refactored to use proc_macro2::TokenStream, added filesystem abstraction for testing, added 5 test cases |
| esp-hal-procmacros/src/interrupt.rs | Refactored to use proc_macro2::TokenStream, added 7 test cases for interrupt handler validation |
| esp-hal-procmacros/src/doc_replace.rs | Refactored to use proc_macro2::TokenStream, added 8 test cases for doc replacement scenarios |
| esp-hal-procmacros/src/builder.rs | Refactored to use proc_macro2::TokenStream, added 6 test cases for BuilderLite derive macro |
| esp-hal-procmacros/src/blocking.rs | Refactored to use proc_macro2::TokenStream, added 3 test cases for blocking main validation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
cargo xtask fmt-packagescommand to ensure that all changed code is formatted correctly.CHANGELOG.mdin the proper section.Extra:
Pull Request Details 📖
Description
This covers at least the check of the expansion of our attribute macros as asked for in #4343
For the "and can compile under certain conditions, i.e when building the stable hal etc." part, I'd say our hil-tests/examples cover the important macros (blocking,builder,doc_replace,interrupt,rtos_main) - not so much ram and lp_core.
I think the coverage here is quite ok (while not perfect) - for some macros like
ramI'm not sure if we could even get every check triggering since some seem redundant but that needs more investigation.(
alert.rsis not really unit-testable but we usually see it working every day :) )(
lp_core.rsis missing a few fail-tests - given the overall state of the lp-core support I guess it's ok for now)Might close #4343
skip-changelogsince it's not user-visible.Testing
CI