test: add cfg_not_test tests
This commit is contained in:
parent
2c09ac3d39
commit
dd37441a64
32
tests/ui/cfg_not_test.rs
Normal file
32
tests/ui/cfg_not_test.rs
Normal file
@ -0,0 +1,32 @@
|
||||
#![allow(unused)]
|
||||
#![warn(clippy::cfg_not_test)]
|
||||
|
||||
fn important_check() {}
|
||||
|
||||
fn main() {
|
||||
// Statement
|
||||
#[cfg(not(test))]
|
||||
let answer = 42;
|
||||
|
||||
// Expression
|
||||
#[cfg(not(test))]
|
||||
important_check();
|
||||
|
||||
// Make sure only not(test) are checked, not other attributes
|
||||
#[cfg(not(foo))]
|
||||
important_check();
|
||||
}
|
||||
|
||||
#[cfg(not(not(test)))]
|
||||
struct CfgNotTest;
|
||||
|
||||
// Deeply nested `not(test)`
|
||||
#[cfg(not(test))]
|
||||
fn foo() {}
|
||||
#[cfg(all(debug_assertions, not(test)))]
|
||||
fn bar() {}
|
||||
#[cfg(not(any(not(debug_assertions), test)))]
|
||||
fn baz() {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {}
|
45
tests/ui/cfg_not_test.stderr
Normal file
45
tests/ui/cfg_not_test.stderr
Normal file
@ -0,0 +1,45 @@
|
||||
error: code is excluded from test builds
|
||||
--> tests/ui/cfg_not_test.rs:8:5
|
||||
|
|
||||
LL | #[cfg(not(test))]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider not excluding any code from test builds
|
||||
= note: this could increase code coverage despite not actually being tested
|
||||
= note: `-D clippy::cfg-not-test` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::cfg_not_test)]`
|
||||
|
||||
error: code is excluded from test builds
|
||||
--> tests/ui/cfg_not_test.rs:12:5
|
||||
|
|
||||
LL | #[cfg(not(test))]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider not excluding any code from test builds
|
||||
|
||||
error: code is excluded from test builds
|
||||
--> tests/ui/cfg_not_test.rs:24:1
|
||||
|
|
||||
LL | #[cfg(not(test))]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider not excluding any code from test builds
|
||||
|
||||
error: code is excluded from test builds
|
||||
--> tests/ui/cfg_not_test.rs:26:1
|
||||
|
|
||||
LL | #[cfg(all(debug_assertions, not(test)))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider not excluding any code from test builds
|
||||
|
||||
error: code is excluded from test builds
|
||||
--> tests/ui/cfg_not_test.rs:28:1
|
||||
|
|
||||
LL | #[cfg(not(any(not(debug_assertions), test)))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider not excluding any code from test builds
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user