-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Support more items in #[tests]
module
#441
Conversation
"function requires `#[init]` or `#[test]` attribute", | ||
)); | ||
untouched_tokens.push(Box::new(f)); | ||
continue; |
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.
This might paint us into a corner, since it means we can't add other attributes in the future
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.
I thought about this case as well.
Keeping the attribute requirement for functions, but allowing everything else is ok?
With the other code change, it would mean, that we can't add any attribute to other items in the future as well, right?
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.
We can't add a newer attribute in a backwards-compatible way under the assumption that every new attribute(-name) is already used / introduced by another crate.
Do I understand that correctly?
What about namespacing? Every attribute from defmt-test lives under defmt_test::init
or defmt_test::test
and we generate a use defmt_test::test
implicitly. Would this be possible or even useful?
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.
We can't add a newer attribute in a backwards-compatible way under the assumption that every new attribute(-name) is already used / introduced by another crate.
Yeah that's correct. It wouldn't be too hard to avoid builtin attributes, but you can use arbitrary procedural macros too, which might define their own stuff.
Every attribute from defmt-test lives under
defmt_test::init
ordefmt_test::test
and we generate ause defmt_test::test
implicitly.
There's no name resolution inside the test module, so we can't insert a use
, but namespacing does sound like a possible solution for attributes we add later (unfortunately requiring the user to write out a rather long path).
Item::Union(t) => untouched_tokens.push(Box::new(t)), | ||
Item::Use(t) => untouched_tokens.push(Box::new(t)), | ||
Item::Verbatim(t) => { | ||
untouched_tokens.push(Box::new(t)); |
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.
I think you could use a wildcard match here and accumulate syn::Item
s instead of Box<dyn ToTokens>
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.
Haha, this is a much simpler solution. 😀
Was underestimating the cleverness of the quote!
macro.
Hi @Sh3Rm4n, Thank you for submitting the PR! Can you please quickly describe how your solution solves the issue :) |
This allows every item to be defined inside the `#[tests]` module, e.g. `struct`s `const`s etc. except for function.
This looks like a good start to me but I'll let @jonas-schievink sent this to bors. I think we could support (auxiliary) functions in a new patch version and still have some degree of extensibility by reserving some attribute names, e.g. |
It looks like as written this will reject bare bors r+ |
Build succeeded: |
This allows every item to be defined inside the
#[tests]
module,e.g.
struct
sconst
s etc. except for function.Closes #416