Skip to content

Commit 6966a42

Browse files
committed
Auto merge of #8404 - camsteffen:rm-ui-test, r=flip1995
Factor out ui_test suite changelog: none
2 parents caeebd6 + 88fd090 commit 6966a42

File tree

5 files changed

+134
-149
lines changed

5 files changed

+134
-149
lines changed

clippy_utils/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ fn with_test_item_names<'tcx>(tcx: TyCtxt<'tcx>, module: LocalDefId, f: impl Fn(
21162116

21172117
/// Checks if the function containing the given `HirId` is a `#[test]` function
21182118
///
2119-
/// Note: If you use this function, please add a `#[test]` case in `tests/ui_test`.
2119+
/// Note: Add `// compile-flags: --test` to UI tests with a `#[test]` function
21202120
pub fn is_in_test_function(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
21212121
with_test_item_names(tcx, tcx.parent_module(id), |names| {
21222122
tcx.hir()
@@ -2139,7 +2139,7 @@ pub fn is_in_test_function(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
21392139
/// Checks whether item either has `test` attribute applied, or
21402140
/// is a module with `test` in its name.
21412141
///
2142-
/// Note: If you use this function, please add a `#[test]` case in `tests/ui_test`.
2142+
/// Note: Add `// compile-flags: --test` to UI tests with a `#[test]` function
21432143
pub fn is_test_module_or_function(tcx: TyCtxt<'_>, item: &Item<'_>) -> bool {
21442144
is_in_test_function(tcx, item.hir_id())
21452145
|| matches!(item.kind, ItemKind::Mod(..))

tests/compile-test.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,6 @@ fn run_ui() {
165165
compiletest::run_tests(&config);
166166
}
167167

168-
fn run_ui_test() {
169-
let mut config = base_config("ui_test");
170-
let _g = VarGuard::set("CARGO_MANIFEST_DIR", fs::canonicalize("tests").unwrap());
171-
let rustcflags = config.target_rustcflags.get_or_insert_with(Default::default);
172-
rustcflags.push_str(" --test");
173-
compiletest::run_tests(&config);
174-
}
175-
176168
fn run_internal_tests() {
177169
// only run internal tests with the internal-tests feature
178170
if !RUN_INTERNAL_TESTS {
@@ -328,7 +320,6 @@ fn run_ui_cargo() {
328320
fn compile_test() {
329321
set_var("CLIPPY_DISABLE_DOCS_LINKS", "true");
330322
run_ui();
331-
run_ui_test();
332323
run_ui_toml();
333324
run_ui_cargo();
334325
run_internal_tests();

tests/ui/eq_op.rs

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,56 @@
1-
// does not test any rustfixable lints
2-
3-
#[rustfmt::skip]
4-
#[warn(clippy::eq_op)]
5-
#[allow(clippy::identity_op, clippy::double_parens)]
6-
#[allow(clippy::no_effect, unused_variables, clippy::unnecessary_operation, clippy::short_circuit_statement)]
7-
#[allow(clippy::nonminimal_bool)]
8-
#[allow(unused)]
9-
#[allow(clippy::unnecessary_cast)]
1+
// compile-flags: --test
2+
3+
#![warn(clippy::eq_op)]
4+
#![allow(clippy::double_parens, clippy::identity_op, clippy::nonminimal_bool)]
5+
106
fn main() {
117
// simple values and comparisons
12-
1 == 1;
13-
"no" == "no";
8+
let _ = 1 == 1;
9+
let _ = "no" == "no";
1410
// even though I agree that no means no ;-)
15-
false != false;
16-
1.5 < 1.5;
17-
1u64 >= 1u64;
11+
let _ = false != false;
12+
let _ = 1.5 < 1.5;
13+
let _ = 1u64 >= 1u64;
1814

1915
// casts, methods, parentheses
20-
(1 as u64) & (1 as u64);
21-
1 ^ ((((((1))))));
16+
let _ = (1u32 as u64) & (1u32 as u64);
17+
#[rustfmt::skip]
18+
{
19+
let _ = 1 ^ ((((((1))))));
20+
};
2221

2322
// unary and binary operators
24-
(-(2) < -(2));
25-
((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
26-
(1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
23+
let _ = (-(2) < -(2));
24+
let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
25+
let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
2726

2827
// various other things
29-
([1] != [1]);
30-
((1, 2) != (1, 2));
31-
vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros
28+
let _ = ([1] != [1]);
29+
let _ = ((1, 2) != (1, 2));
30+
let _ = vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros
3231

3332
// const folding
34-
1 + 1 == 2;
35-
1 - 1 == 0;
33+
let _ = 1 + 1 == 2;
34+
let _ = 1 - 1 == 0;
3635

37-
1 - 1;
38-
1 / 1;
39-
true && true;
40-
41-
true || true;
36+
let _ = 1 - 1;
37+
let _ = 1 / 1;
38+
let _ = true && true;
4239

40+
let _ = true || true;
4341

4442
let a: u32 = 0;
4543
let b: u32 = 0;
4644

47-
a == b && b == a;
48-
a != b && b != a;
49-
a < b && b > a;
50-
a <= b && b >= a;
45+
let _ = a == b && b == a;
46+
let _ = a != b && b != a;
47+
let _ = a < b && b > a;
48+
let _ = a <= b && b >= a;
5149

5250
let mut a = vec![1];
53-
a == a;
54-
2*a.len() == 2*a.len(); // ok, functions
55-
a.pop() == a.pop(); // ok, functions
51+
let _ = a == a;
52+
let _ = 2 * a.len() == 2 * a.len(); // ok, functions
53+
let _ = a.pop() == a.pop(); // ok, functions
5654

5755
check_ignore_macro();
5856

@@ -63,15 +61,14 @@ fn main() {
6361
const D: u32 = A / A;
6462
}
6563

66-
#[rustfmt::skip]
6764
macro_rules! check_if_named_foo {
68-
($expression:expr) => (
65+
($expression:expr) => {
6966
if stringify!($expression) == "foo" {
7067
println!("foo!");
7168
} else {
7269
println!("not foo.");
7370
}
74-
)
71+
};
7572
}
7673

7774
macro_rules! bool_macro {
@@ -80,11 +77,10 @@ macro_rules! bool_macro {
8077
};
8178
}
8279

83-
#[allow(clippy::short_circuit_statement)]
8480
fn check_ignore_macro() {
8581
check_if_named_foo!(foo);
8682
// checks if the lint ignores macros with `!` operator
87-
!bool_macro!(1) && !bool_macro!("");
83+
let _ = !bool_macro!(1) && !bool_macro!("");
8884
}
8985

9086
struct Nested {
@@ -95,3 +91,18 @@ fn check_nested(n1: &Nested, n2: &Nested) -> bool {
9591
// `n2.inner.0.0` mistyped as `n1.inner.0.0`
9692
(n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0
9793
}
94+
95+
#[test]
96+
fn eq_op_shouldnt_trigger_in_tests() {
97+
let a = 1;
98+
let result = a + 1 == 1 + a;
99+
assert!(result);
100+
}
101+
102+
#[test]
103+
fn eq_op_macros_shouldnt_trigger_in_tests() {
104+
let a = 1;
105+
let b = 2;
106+
assert_eq!(a, a);
107+
assert_eq!(a + b, b + a);
108+
}

0 commit comments

Comments
 (0)