Add tests

Also rename the test files for the unused_macros lint to avoid confusion.
The test files now follow a <lint_name><-maybe-decl>.rs scheme.
This commit is contained in:
est31 2022-04-17 15:54:04 +02:00
parent 5646e9a172
commit d76a9394ba
8 changed files with 195 additions and 43 deletions

View File

@ -0,0 +1,49 @@
#![feature(decl_macro)]
#![deny(unused_macro_rules)]
// To make sure we are not hitting this
#![deny(unused_macros)]
// Most simple case
macro num {
(one) => { 1 },
(two) => { 2 }, //~ ERROR: 2nd rule of macro
(three) => { 3 },
(four) => { 4 }, //~ ERROR: 4th rule of macro
}
const _NUM: u8 = num!(one) + num!(three);
// Check that allowing the lint works
#[allow(unused_macro_rules)]
macro num_allowed {
(one) => { 1 },
(two) => { 2 },
(three) => { 3 },
(four) => { 4 },
}
const _NUM_ALLOWED: u8 = num_allowed!(one) + num_allowed!(three);
// Check that macro calls inside the macro trigger as usage
macro num_rec {
(one) => { 1 },
(two) => {
num_rec!(one) + num_rec!(one)
},
(three) => { //~ ERROR: 3rd rule of macro
num_rec!(one) + num_rec!(two)
},
(four) => {
num_rec!(two) + num_rec!(two)
},
}
const _NUM_RECURSIVE: u8 = num_rec!(four);
// No error if the macro is public
pub macro num_public {
(one) => { 1 },
(two) => { 2 },
(three) => { 3 },
(four) => { 4 },
}
const _NUM_PUBLIC: u8 = num_public!(one) + num_public!(three);
fn main() {}

View File

@ -0,0 +1,26 @@
error: 4th rule of macro `num` is never used
--> $DIR/unused-macro-rules-decl.rs:11:5
|
LL | (four) => { 4 },
| ^^^^^^
|
note: the lint level is defined here
--> $DIR/unused-macro-rules-decl.rs:2:9
|
LL | #![deny(unused_macro_rules)]
| ^^^^^^^^^^^^^^^^^^
error: 2nd rule of macro `num` is never used
--> $DIR/unused-macro-rules-decl.rs:9:5
|
LL | (two) => { 2 },
| ^^^^^
error: 3rd rule of macro `num_rec` is never used
--> $DIR/unused-macro-rules-decl.rs:31:5
|
LL | (three) => {
| ^^^^^^^
error: aborting due to 3 previous errors

View File

@ -1,29 +1,47 @@
#![deny(unused_macro_rules)]
// To make sure we are not hitting this
#![deny(unused_macros)]
// Most simple case
macro_rules! unused { //~ ERROR: unused macro definition
() => {};
macro_rules! num {
(one) => { 1 };
(two) => { 2 }; //~ ERROR: 2nd rule of macro
(three) => { 3 };
(four) => { 4 }; //~ ERROR: 4th rule of macro
}
const _NUM: u8 = num!(one) + num!(three);
// Test macros created by macros
macro_rules! create_macro {
() => {
macro_rules! m { //~ ERROR: unused macro definition
() => {};
}
// Check that allowing the lint works
#[allow(unused_macro_rules)]
macro_rules! num_allowed {
(one) => { 1 };
(two) => { 2 };
(three) => { 3 };
(four) => { 4 };
}
const _NUM_ALLOWED: u8 = num_allowed!(one) + num_allowed!(three);
// Check that macro calls inside the macro trigger as usage
macro_rules! num_rec {
(one) => { 1 };
(two) => {
num_rec!(one) + num_rec!(one)
};
(three) => { //~ ERROR: 3rd rule of macro
num_rec!(one) + num_rec!(two)
};
(four) => { num_rec!(two) + num_rec!(two) };
}
create_macro!();
const _NUM_RECURSIVE: u8 = num_rec!(four);
#[allow(unused_macros)]
mod bar {
// Test that putting the #[deny] close to the macro's definition
// works.
#[deny(unused_macros)]
macro_rules! unused { //~ ERROR: unused macro definition
() => {};
}
// No error if the macro is being exported
#[macro_export]
macro_rules! num_exported {
(one) => { 1 };
(two) => { 2 };
(three) => { 3 };
(four) => { 4 };
}
const _NUM_EXPORTED: u8 = num_exported!(one) + num_exported!(three);
fn main() {}

View File

@ -1,32 +1,26 @@
error: unused macro definition: `unused`
--> $DIR/unused-macro-rules.rs:4:14
error: 4th rule of macro `num` is never used
--> $DIR/unused-macro-rules.rs:10:5
|
LL | macro_rules! unused {
| ^^^^^^
LL | (four) => { 4 };
| ^^^^^^
|
note: the lint level is defined here
--> $DIR/unused-macro-rules.rs:1:9
|
LL | #![deny(unused_macros)]
| ^^^^^^^^^^^^^
LL | #![deny(unused_macro_rules)]
| ^^^^^^^^^^^^^^^^^^
error: unused macro definition: `m`
--> $DIR/unused-macro-rules.rs:11:22
error: 2nd rule of macro `num` is never used
--> $DIR/unused-macro-rules.rs:8:5
|
LL | macro_rules! m {
| ^
LL | (two) => { 2 };
| ^^^^^
error: unused macro definition: `unused`
--> $DIR/unused-macro-rules.rs:24:18
error: 3rd rule of macro `num_rec` is never used
--> $DIR/unused-macro-rules.rs:30:5
|
LL | macro_rules! unused {
| ^^^^^^
|
note: the lint level is defined here
--> $DIR/unused-macro-rules.rs:23:12
|
LL | #[deny(unused_macros)]
| ^^^^^^^^^^^^^
LL | (three) => {
| ^^^^^^^
error: aborting due to 3 previous errors

View File

@ -1,5 +1,7 @@
#![feature(decl_macro)]
#![deny(unused_macros)]
// To make sure we are not hitting this
#![deny(unused_macro_rules)]
// Most simple case
macro unused { //~ ERROR: unused macro definition

View File

@ -1,29 +1,29 @@
error: unused macro definition: `unused`
--> $DIR/unused-macro.rs:5:7
--> $DIR/unused-macros-decl.rs:7:7
|
LL | macro unused {
| ^^^^^^
|
note: the lint level is defined here
--> $DIR/unused-macro.rs:2:9
--> $DIR/unused-macros-decl.rs:2:9
|
LL | #![deny(unused_macros)]
| ^^^^^^^^^^^^^
error: unused macro definition: `unused`
--> $DIR/unused-macro.rs:15:11
--> $DIR/unused-macros-decl.rs:17:11
|
LL | macro unused {
| ^^^^^^
|
note: the lint level is defined here
--> $DIR/unused-macro.rs:14:12
--> $DIR/unused-macros-decl.rs:16:12
|
LL | #[deny(unused_macros)]
| ^^^^^^^^^^^^^
error: unused macro definition: `unused`
--> $DIR/unused-macro.rs:21:22
--> $DIR/unused-macros-decl.rs:23:22
|
LL | pub(crate) macro unused {
| ^^^^^^

View File

@ -0,0 +1,31 @@
#![deny(unused_macros)]
// To make sure we are not hitting this
#![deny(unused_macro_rules)]
// Most simple case
macro_rules! unused { //~ ERROR: unused macro definition
() => {};
}
// Test macros created by macros
macro_rules! create_macro {
() => {
macro_rules! m { //~ ERROR: unused macro definition
() => {};
}
};
}
create_macro!();
#[allow(unused_macros)]
mod bar {
// Test that putting the #[deny] close to the macro's definition
// works.
#[deny(unused_macros)]
macro_rules! unused { //~ ERROR: unused macro definition
() => {};
}
}
fn main() {}

View File

@ -0,0 +1,32 @@
error: unused macro definition: `unused`
--> $DIR/unused-macros.rs:6:14
|
LL | macro_rules! unused {
| ^^^^^^
|
note: the lint level is defined here
--> $DIR/unused-macros.rs:1:9
|
LL | #![deny(unused_macros)]
| ^^^^^^^^^^^^^
error: unused macro definition: `m`
--> $DIR/unused-macros.rs:13:22
|
LL | macro_rules! m {
| ^
error: unused macro definition: `unused`
--> $DIR/unused-macros.rs:26:18
|
LL | macro_rules! unused {
| ^^^^^^
|
note: the lint level is defined here
--> $DIR/unused-macros.rs:25:12
|
LL | #[deny(unused_macros)]
| ^^^^^^^^^^^^^
error: aborting due to 3 previous errors