1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
#![allow(dead_code)]
#![warn(clippy::redundant_test_prefix)]
fn main() {
// Normal function, no redundant prefix.
}
fn f1() {
// Normal function, no redundant prefix.
}
fn test_f2() {
// Has prefix, but no `#[test]` attribute, ignore.
}
#[test]
fn f3() {
//~^ redundant_test_prefix
// Has prefix, has `#[test]` attribute. Not within a `#[cfg(test)]`.
// No collision with other functions, should emit warning.
}
#[cfg(test)]
#[test]
fn f4() {
//~^ redundant_test_prefix
// Has prefix, has `#[test]` attribute, within a `#[cfg(test)]`.
// No collision with other functions, should emit warning.
}
mod m1 {
pub fn f5() {}
}
#[cfg(test)]
#[test]
fn f6() {
//~^ redundant_test_prefix
use m1::f5;
f5();
// Has prefix, has `#[test]` attribute, within a `#[cfg(test)]`.
// No collision, has function call, but it will not result in recursion.
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn foo() {
//~^ redundant_test_prefix
}
#[test]
fn foo_with_call() {
//~^ redundant_test_prefix
main();
}
#[test]
fn f1() {
//~^ redundant_test_prefix
}
#[test]
fn f2() {
//~^ redundant_test_prefix
}
#[test]
fn f3() {
//~^ redundant_test_prefix
}
#[test]
fn f4() {
//~^ redundant_test_prefix
}
#[test]
fn f5() {
//~^ redundant_test_prefix
}
#[test]
fn f6() {
//~^ redundant_test_prefix
}
}
mod tests_no_annotations {
use super::*;
#[test]
fn foo() {
//~^ redundant_test_prefix
}
#[test]
fn foo_with_call() {
//~^ redundant_test_prefix
main();
}
#[test]
fn f1() {
//~^ redundant_test_prefix
}
#[test]
fn f2() {
//~^ redundant_test_prefix
}
#[test]
fn f3() {
//~^ redundant_test_prefix
}
#[test]
fn f4() {
//~^ redundant_test_prefix
}
#[test]
fn f5() {
//~^ redundant_test_prefix
}
#[test]
fn f6() {
//~^ redundant_test_prefix
}
}
// This test is inspired by real test in `clippy_utils/src/sugg.rs`.
// The `is_in_test_function()` checks whether any identifier within a given node's parents is
// marked with `#[test]` attribute. Thus flagging false positives when nested functions are
// prefixed with `test_`. Therefore `is_test_function()` has been defined in `clippy_utils`,
// allowing to select only functions that are immediately marked with `#[test]` annotation.
//
// This test case ensures that for such nested functions no error is emitted.
#[test]
fn not_op() {
fn test_not(foo: bool) {
assert!(foo);
}
// Use helper function
test_not(true);
test_not(false);
}
|