mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 23:20:39 +00:00
e65ad6f5d0
Add utility macros to help with writing tests. Adds two utility macros to help with testing: * `external` expands to it's argument tokens, but makes them appear to come from an external macro. Helps make tests for `in_external_macro` much more readable. * `inline_macros` is an attribute macro which allows the use of a pseudo `inline!` macro which expands to it's argument tokens, but makes them appear to be from a crate-local macro expansion. This removes the need to write `macro_rules` boilerplate when testing how lints interact with macros. --- `external`'s usage is simple. `external!(struct Foo { x: u32});` will make the struct appear as though it came from an external macro. Individual tokens can be escaped if needed. `external!($x + 0 / 10)` will make everything except `x` appear as though it came from an external macro. Can also use `$literal` and `$(tokens...)` as well. --- `inline_macros` is more complicated due to compiler constraints. Given: ```rust #[inline_macros] fn foo() { inline!(5 + 5 / 10); } ``` `inline!(5 + 5 / 10)` will be replace with a call to a generated macro which expands to the contained tokens. Tokens can be escaped by prefixing them with `$`: ```rust #[inline_macros] fn foo() { let x = 5; inline!($x + 5 / $10); } ``` This will pass `x` as an `ident` argument and `10` as a `literal` argument. Token sequences can also be passed with `$(...)`: ```rust #[inline_macros] fn foo() { let mut x = 5; inline!(if $(x >= 5) { $x = 5; }); } ``` This will pass `x >= 5` as `tt` arguments, and `x` as an `ident` argument. --- Not 100% sure `inline_macros` is actually worth having. It does make the tests a little easier to read once you're used to it and it becomes more useful once there are multiple macro tests. The verbosity of declaring single use macros starts to hurt at that point. changelog: None |
||
---|---|---|
.. | ||
test_utils | ||
ui | ||
ui-cargo | ||
ui-internal | ||
ui-toml | ||
workspace_test | ||
check-fmt.rs | ||
clippy.toml | ||
compile-test.rs | ||
dogfood.rs | ||
integration.rs | ||
lint_message_convention.rs | ||
missing-test-files.rs | ||
versioncheck.rs | ||
workspace.rs |