From 29dc72dd107a75ddc22da6b51ea96d0f9067b59f Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Fri, 8 Jul 2022 10:16:28 +0900 Subject: [PATCH] add `#[test]` to functions in test modules --- .../ui/imports/unused-imports-in-test-mode.rs | 54 ++++++---- .../unused-imports-in-test-mode.stderr | 74 ++----------- .../imports/unused-imports-in-test-module.rs | 53 ++++++--- .../unused-imports-in-test-module.stderr | 102 +++--------------- 4 files changed, 97 insertions(+), 186 deletions(-) diff --git a/src/test/ui/imports/unused-imports-in-test-mode.rs b/src/test/ui/imports/unused-imports-in-test-mode.rs index ed0bb65b3aa91..039f59a8838a1 100644 --- a/src/test/ui/imports/unused-imports-in-test-mode.rs +++ b/src/test/ui/imports/unused-imports-in-test-mode.rs @@ -8,76 +8,94 @@ fn a() {} fn b() {} mod test { - use super::a; //~ ERROR unused import: `super::a` + use super::a; + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; //~ ERROR unused import: `crate::b` } } mod tests { - use super::a; //~ ERROR unused import: `super::a` + use super::a; + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; //~ ERROR unused import: `crate::b` } } mod test_a { - use super::a; //~ ERROR unused import: `super::a` + use super::a; + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; //~ ERROR unused import: `crate::b` } } mod a_test { - use super::a; //~ ERROR unused import: `super::a` + use super::a; + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; //~ ERROR unused import: `crate::b` } } mod tests_a { - use super::a; //~ ERROR unused import: `super::a` + use super::a; + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; //~ ERROR unused import: `crate::b` } } mod a_tests { - use super::a; //~ ERROR unused import: `super::a` + use super::a; + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; //~ ERROR unused import: `crate::b` } } mod fastest_search { - use super::a; //~ ERROR unused import: `super::a` + use super::a; + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; //~ ERROR unused import: `crate::b` } } #[cfg(test)] mod test_has_attr { - use super::a; //~ ERROR unused import: `super::a` + use super::a; + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; //~ ERROR unused import: `crate::b` } } mod test_has_no_attr { #[cfg(test)] - use super::a; //~ ERROR unused import: `super::a` + use super::a; + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; //~ ERROR unused import: `crate::b` } } diff --git a/src/test/ui/imports/unused-imports-in-test-mode.stderr b/src/test/ui/imports/unused-imports-in-test-mode.stderr index 1847abd64b4f2..c5faaa11450cb 100644 --- a/src/test/ui/imports/unused-imports-in-test-mode.stderr +++ b/src/test/ui/imports/unused-imports-in-test-mode.stderr @@ -10,113 +10,59 @@ note: the lint level is defined here LL | #![deny(unused_imports)] | ^^^^^^^^^^^^^^ -error: unused import: `super::a` - --> $DIR/unused-imports-in-test-mode.rs:11:9 - | -LL | use super::a; - | ^^^^^^^^ - error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-mode.rs:14:13 + --> $DIR/unused-imports-in-test-mode.rs:16:13 | LL | use crate::b; | ^^^^^^^^ -error: unused import: `super::a` - --> $DIR/unused-imports-in-test-mode.rs:19:9 - | -LL | use super::a; - | ^^^^^^^^ - error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-mode.rs:22:13 + --> $DIR/unused-imports-in-test-mode.rs:26:13 | LL | use crate::b; | ^^^^^^^^ -error: unused import: `super::a` - --> $DIR/unused-imports-in-test-mode.rs:27:9 - | -LL | use super::a; - | ^^^^^^^^ - error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-mode.rs:30:13 + --> $DIR/unused-imports-in-test-mode.rs:36:13 | LL | use crate::b; | ^^^^^^^^ -error: unused import: `super::a` - --> $DIR/unused-imports-in-test-mode.rs:35:9 - | -LL | use super::a; - | ^^^^^^^^ - error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-mode.rs:38:13 + --> $DIR/unused-imports-in-test-mode.rs:46:13 | LL | use crate::b; | ^^^^^^^^ -error: unused import: `super::a` - --> $DIR/unused-imports-in-test-mode.rs:43:9 - | -LL | use super::a; - | ^^^^^^^^ - error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-mode.rs:46:13 + --> $DIR/unused-imports-in-test-mode.rs:56:13 | LL | use crate::b; | ^^^^^^^^ -error: unused import: `super::a` - --> $DIR/unused-imports-in-test-mode.rs:51:9 - | -LL | use super::a; - | ^^^^^^^^ - error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-mode.rs:54:13 + --> $DIR/unused-imports-in-test-mode.rs:66:13 | LL | use crate::b; | ^^^^^^^^ -error: unused import: `super::a` - --> $DIR/unused-imports-in-test-mode.rs:59:9 - | -LL | use super::a; - | ^^^^^^^^ - error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-mode.rs:62:13 + --> $DIR/unused-imports-in-test-mode.rs:76:13 | LL | use crate::b; | ^^^^^^^^ -error: unused import: `super::a` - --> $DIR/unused-imports-in-test-mode.rs:68:9 - | -LL | use super::a; - | ^^^^^^^^ - error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-mode.rs:71:13 + --> $DIR/unused-imports-in-test-mode.rs:87:13 | LL | use crate::b; | ^^^^^^^^ -error: unused import: `super::a` - --> $DIR/unused-imports-in-test-mode.rs:77:9 - | -LL | use super::a; - | ^^^^^^^^ - error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-mode.rs:80:13 + --> $DIR/unused-imports-in-test-mode.rs:98:13 | LL | use crate::b; | ^^^^^^^^ -error: aborting due to 19 previous errors +error: aborting due to 10 previous errors diff --git a/src/test/ui/imports/unused-imports-in-test-module.rs b/src/test/ui/imports/unused-imports-in-test-module.rs index b003b99b6cff0..7849c3fcd4835 100644 --- a/src/test/ui/imports/unused-imports-in-test-module.rs +++ b/src/test/ui/imports/unused-imports-in-test-module.rs @@ -6,58 +6,83 @@ fn a() {} fn b() {} mod test { - use super::a; //~ ERROR unused import: `super::a` + use super::a; //~ ERROR unused import: `super::a` + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; } } mod tests { - use super::a; //~ ERROR unused import: `super::a` + use super::a; //~ ERROR unused import: `super::a` + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; } } mod test_a { - use super::a; //~ ERROR unused import: `super::a` + use super::a; //~ ERROR unused import: `super::a` + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; } } mod a_test { - use super::a; //~ ERROR unused import: `super::a` + use super::a; //~ ERROR unused import: `super::a` + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; } } mod tests_a { - use super::a; //~ ERROR unused import: `super::a` + use super::a; //~ ERROR unused import: `super::a` + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; } } mod a_tests { - use super::a; //~ ERROR unused import: `super::a` + use super::a; //~ ERROR unused import: `super::a` + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; } } mod fastest_search { - use super::a; //~ ERROR unused import: `super::a` + use super::a; //~ ERROR unused import: `super::a` + #[test] fn foo() { - use crate::b; //~ ERROR unused import: `crate::b` + a(); + use crate::b; + } +} + +#[cfg(test)] +mod test_has_attr { + use super::a; + + #[test] + fn foo() { + a(); + use crate::b; } } diff --git a/src/test/ui/imports/unused-imports-in-test-module.stderr b/src/test/ui/imports/unused-imports-in-test-module.stderr index 2efea5b3609e1..1598368eb32cc 100644 --- a/src/test/ui/imports/unused-imports-in-test-module.stderr +++ b/src/test/ui/imports/unused-imports-in-test-module.stderr @@ -22,149 +22,71 @@ help: consider adding a `#[cfg(test)]` to the containing module LL | mod test { | ^^^^^^^^ -error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-module.rs:12:13 - | -LL | use crate::b; - | ^^^^^^^^ - | -help: consider adding a `#[cfg(test)]` to the containing module - --> $DIR/unused-imports-in-test-module.rs:8:1 - | -LL | mod test { - | ^^^^^^^^ - error: unused import: `super::a` - --> $DIR/unused-imports-in-test-module.rs:17:9 + --> $DIR/unused-imports-in-test-module.rs:19:9 | LL | use super::a; | ^^^^^^^^ | help: consider adding a `#[cfg(test)]` to the containing module - --> $DIR/unused-imports-in-test-module.rs:16:1 - | -LL | mod tests { - | ^^^^^^^^^ - -error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-module.rs:20:13 - | -LL | use crate::b; - | ^^^^^^^^ - | -help: consider adding a `#[cfg(test)]` to the containing module - --> $DIR/unused-imports-in-test-module.rs:16:1 + --> $DIR/unused-imports-in-test-module.rs:18:1 | LL | mod tests { | ^^^^^^^^^ error: unused import: `super::a` - --> $DIR/unused-imports-in-test-module.rs:25:9 + --> $DIR/unused-imports-in-test-module.rs:29:9 | LL | use super::a; | ^^^^^^^^ | help: consider adding a `#[cfg(test)]` to the containing module - --> $DIR/unused-imports-in-test-module.rs:24:1 - | -LL | mod test_a { - | ^^^^^^^^^^ - -error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-module.rs:28:13 - | -LL | use crate::b; - | ^^^^^^^^ - | -help: consider adding a `#[cfg(test)]` to the containing module - --> $DIR/unused-imports-in-test-module.rs:24:1 + --> $DIR/unused-imports-in-test-module.rs:28:1 | LL | mod test_a { | ^^^^^^^^^^ error: unused import: `super::a` - --> $DIR/unused-imports-in-test-module.rs:33:9 + --> $DIR/unused-imports-in-test-module.rs:39:9 | LL | use super::a; | ^^^^^^^^ | help: consider adding a `#[cfg(test)]` to the containing module - --> $DIR/unused-imports-in-test-module.rs:32:1 - | -LL | mod a_test { - | ^^^^^^^^^^ - -error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-module.rs:36:13 - | -LL | use crate::b; - | ^^^^^^^^ - | -help: consider adding a `#[cfg(test)]` to the containing module - --> $DIR/unused-imports-in-test-module.rs:32:1 + --> $DIR/unused-imports-in-test-module.rs:38:1 | LL | mod a_test { | ^^^^^^^^^^ error: unused import: `super::a` - --> $DIR/unused-imports-in-test-module.rs:41:9 + --> $DIR/unused-imports-in-test-module.rs:49:9 | LL | use super::a; | ^^^^^^^^ | help: consider adding a `#[cfg(test)]` to the containing module - --> $DIR/unused-imports-in-test-module.rs:40:1 - | -LL | mod tests_a { - | ^^^^^^^^^^^ - -error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-module.rs:44:13 - | -LL | use crate::b; - | ^^^^^^^^ - | -help: consider adding a `#[cfg(test)]` to the containing module - --> $DIR/unused-imports-in-test-module.rs:40:1 + --> $DIR/unused-imports-in-test-module.rs:48:1 | LL | mod tests_a { | ^^^^^^^^^^^ error: unused import: `super::a` - --> $DIR/unused-imports-in-test-module.rs:49:9 + --> $DIR/unused-imports-in-test-module.rs:59:9 | LL | use super::a; | ^^^^^^^^ | help: consider adding a `#[cfg(test)]` to the containing module - --> $DIR/unused-imports-in-test-module.rs:48:1 - | -LL | mod a_tests { - | ^^^^^^^^^^^ - -error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-module.rs:52:13 - | -LL | use crate::b; - | ^^^^^^^^ - | -help: consider adding a `#[cfg(test)]` to the containing module - --> $DIR/unused-imports-in-test-module.rs:48:1 + --> $DIR/unused-imports-in-test-module.rs:58:1 | LL | mod a_tests { | ^^^^^^^^^^^ error: unused import: `super::a` - --> $DIR/unused-imports-in-test-module.rs:57:9 + --> $DIR/unused-imports-in-test-module.rs:69:9 | LL | use super::a; | ^^^^^^^^ -error: unused import: `crate::b` - --> $DIR/unused-imports-in-test-module.rs:60:13 - | -LL | use crate::b; - | ^^^^^^^^ - -error: aborting due to 15 previous errors +error: aborting due to 8 previous errors