1
Fork 0

Auto merge of #8404 - camsteffen:rm-ui-test, r=flip1995

Factor out ui_test suite

changelog: none
This commit is contained in:
bors 2022-02-09 09:09:58 +00:00
commit 6966a42c1a
5 changed files with 133 additions and 148 deletions

View file

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

View file

@ -165,14 +165,6 @@ fn run_ui() {
compiletest::run_tests(&config); compiletest::run_tests(&config);
} }
fn run_ui_test() {
let mut config = base_config("ui_test");
let _g = VarGuard::set("CARGO_MANIFEST_DIR", fs::canonicalize("tests").unwrap());
let rustcflags = config.target_rustcflags.get_or_insert_with(Default::default);
rustcflags.push_str(" --test");
compiletest::run_tests(&config);
}
fn run_internal_tests() { fn run_internal_tests() {
// only run internal tests with the internal-tests feature // only run internal tests with the internal-tests feature
if !RUN_INTERNAL_TESTS { if !RUN_INTERNAL_TESTS {
@ -328,7 +320,6 @@ fn run_ui_cargo() {
fn compile_test() { fn compile_test() {
set_var("CLIPPY_DISABLE_DOCS_LINKS", "true"); set_var("CLIPPY_DISABLE_DOCS_LINKS", "true");
run_ui(); run_ui();
run_ui_test();
run_ui_toml(); run_ui_toml();
run_ui_cargo(); run_ui_cargo();
run_internal_tests(); run_internal_tests();

View file

@ -1,58 +1,56 @@
// does not test any rustfixable lints // compile-flags: --test
#![warn(clippy::eq_op)]
#![allow(clippy::double_parens, clippy::identity_op, clippy::nonminimal_bool)]
#[rustfmt::skip]
#[warn(clippy::eq_op)]
#[allow(clippy::identity_op, clippy::double_parens)]
#[allow(clippy::no_effect, unused_variables, clippy::unnecessary_operation, clippy::short_circuit_statement)]
#[allow(clippy::nonminimal_bool)]
#[allow(unused)]
#[allow(clippy::unnecessary_cast)]
fn main() { fn main() {
// simple values and comparisons // simple values and comparisons
1 == 1; let _ = 1 == 1;
"no" == "no"; let _ = "no" == "no";
// even though I agree that no means no ;-) // even though I agree that no means no ;-)
false != false; let _ = false != false;
1.5 < 1.5; let _ = 1.5 < 1.5;
1u64 >= 1u64; let _ = 1u64 >= 1u64;
// casts, methods, parentheses // casts, methods, parentheses
(1 as u64) & (1 as u64); let _ = (1u32 as u64) & (1u32 as u64);
1 ^ ((((((1)))))); #[rustfmt::skip]
{
let _ = 1 ^ ((((((1))))));
};
// unary and binary operators // unary and binary operators
(-(2) < -(2)); let _ = (-(2) < -(2));
((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
(1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
// various other things // various other things
([1] != [1]); let _ = ([1] != [1]);
((1, 2) != (1, 2)); let _ = ((1, 2) != (1, 2));
vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros let _ = vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros
// const folding // const folding
1 + 1 == 2; let _ = 1 + 1 == 2;
1 - 1 == 0; let _ = 1 - 1 == 0;
1 - 1; let _ = 1 - 1;
1 / 1; let _ = 1 / 1;
true && true; let _ = true && true;
true || true;
let _ = true || true;
let a: u32 = 0; let a: u32 = 0;
let b: u32 = 0; let b: u32 = 0;
a == b && b == a; let _ = a == b && b == a;
a != b && b != a; let _ = a != b && b != a;
a < b && b > a; let _ = a < b && b > a;
a <= b && b >= a; let _ = a <= b && b >= a;
let mut a = vec![1]; let mut a = vec![1];
a == a; let _ = a == a;
2*a.len() == 2*a.len(); // ok, functions let _ = 2 * a.len() == 2 * a.len(); // ok, functions
a.pop() == a.pop(); // ok, functions let _ = a.pop() == a.pop(); // ok, functions
check_ignore_macro(); check_ignore_macro();
@ -63,15 +61,14 @@ fn main() {
const D: u32 = A / A; const D: u32 = A / A;
} }
#[rustfmt::skip]
macro_rules! check_if_named_foo { macro_rules! check_if_named_foo {
($expression:expr) => ( ($expression:expr) => {
if stringify!($expression) == "foo" { if stringify!($expression) == "foo" {
println!("foo!"); println!("foo!");
} else { } else {
println!("not foo."); println!("not foo.");
} }
) };
} }
macro_rules! bool_macro { macro_rules! bool_macro {
@ -80,11 +77,10 @@ macro_rules! bool_macro {
}; };
} }
#[allow(clippy::short_circuit_statement)]
fn check_ignore_macro() { fn check_ignore_macro() {
check_if_named_foo!(foo); check_if_named_foo!(foo);
// checks if the lint ignores macros with `!` operator // checks if the lint ignores macros with `!` operator
!bool_macro!(1) && !bool_macro!(""); let _ = !bool_macro!(1) && !bool_macro!("");
} }
struct Nested { struct Nested {
@ -95,3 +91,18 @@ fn check_nested(n1: &Nested, n2: &Nested) -> bool {
// `n2.inner.0.0` mistyped as `n1.inner.0.0` // `n2.inner.0.0` mistyped as `n1.inner.0.0`
(n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0 (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0
} }
#[test]
fn eq_op_shouldnt_trigger_in_tests() {
let a = 1;
let result = a + 1 == 1 + a;
assert!(result);
}
#[test]
fn eq_op_macros_shouldnt_trigger_in_tests() {
let a = 1;
let b = 2;
assert_eq!(a, a);
assert_eq!(a + b, b + a);
}

View file

@ -1,174 +1,172 @@
error: equal expressions as operands to `==` error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:12:5 --> $DIR/eq_op.rs:8:13
| |
LL | 1 == 1; LL | let _ = 1 == 1;
| ^^^^^^ | ^^^^^^
| |
= note: `-D clippy::eq-op` implied by `-D warnings` = note: `-D clippy::eq-op` implied by `-D warnings`
error: equal expressions as operands to `==` error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:13:5 --> $DIR/eq_op.rs:9:13
| |
LL | "no" == "no"; LL | let _ = "no" == "no";
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: equal expressions as operands to `!=` error: equal expressions as operands to `!=`
--> $DIR/eq_op.rs:15:5 --> $DIR/eq_op.rs:11:13
| |
LL | false != false; LL | let _ = false != false;
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
error: equal expressions as operands to `<` error: equal expressions as operands to `<`
--> $DIR/eq_op.rs:16:5 --> $DIR/eq_op.rs:12:13
| |
LL | 1.5 < 1.5; LL | let _ = 1.5 < 1.5;
| ^^^^^^^^^ | ^^^^^^^^^
error: equal expressions as operands to `>=` error: equal expressions as operands to `>=`
--> $DIR/eq_op.rs:17:5 --> $DIR/eq_op.rs:13:13
| |
LL | 1u64 >= 1u64; LL | let _ = 1u64 >= 1u64;
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: equal expressions as operands to `&` error: equal expressions as operands to `&`
--> $DIR/eq_op.rs:20:5 --> $DIR/eq_op.rs:16:13
| |
LL | (1 as u64) & (1 as u64); LL | let _ = (1u32 as u64) & (1u32 as u64);
| ^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `^` error: equal expressions as operands to `^`
--> $DIR/eq_op.rs:21:5 --> $DIR/eq_op.rs:19:17
| |
LL | 1 ^ ((((((1)))))); LL | let _ = 1 ^ ((((((1))))));
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `<` error: equal expressions as operands to `<`
--> $DIR/eq_op.rs:24:5 --> $DIR/eq_op.rs:23:13
| |
LL | (-(2) < -(2)); LL | let _ = (-(2) < -(2));
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: equal expressions as operands to `==` error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:25:5 --> $DIR/eq_op.rs:24:13
| |
LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `&` error: equal expressions as operands to `&`
--> $DIR/eq_op.rs:25:6 --> $DIR/eq_op.rs:24:14
| |
LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `&` error: equal expressions as operands to `&`
--> $DIR/eq_op.rs:25:27 --> $DIR/eq_op.rs:24:35
| |
LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `==` error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:26:5 --> $DIR/eq_op.rs:25:13
| |
LL | (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; LL | let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `!=` error: equal expressions as operands to `!=`
--> $DIR/eq_op.rs:29:5 --> $DIR/eq_op.rs:28:13
| |
LL | ([1] != [1]); LL | let _ = ([1] != [1]);
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: equal expressions as operands to `!=` error: equal expressions as operands to `!=`
--> $DIR/eq_op.rs:30:5 --> $DIR/eq_op.rs:29:13
| |
LL | ((1, 2) != (1, 2)); LL | let _ = ((1, 2) != (1, 2));
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `==` error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:34:5 --> $DIR/eq_op.rs:33:13
| |
LL | 1 + 1 == 2; LL | let _ = 1 + 1 == 2;
| ^^^^^^^^^^ | ^^^^^^^^^^
error: equal expressions as operands to `==` error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:35:5 --> $DIR/eq_op.rs:34:13
| |
LL | 1 - 1 == 0; LL | let _ = 1 - 1 == 0;
| ^^^^^^^^^^ | ^^^^^^^^^^
error: equal expressions as operands to `-` error: equal expressions as operands to `-`
--> $DIR/eq_op.rs:35:5 --> $DIR/eq_op.rs:34:13
| |
LL | 1 - 1 == 0; LL | let _ = 1 - 1 == 0;
| ^^^^^ | ^^^^^
error: equal expressions as operands to `-` error: equal expressions as operands to `-`
--> $DIR/eq_op.rs:37:5 --> $DIR/eq_op.rs:36:13
| |
LL | 1 - 1; LL | let _ = 1 - 1;
| ^^^^^ | ^^^^^
error: equal expressions as operands to `/` error: equal expressions as operands to `/`
--> $DIR/eq_op.rs:38:5 --> $DIR/eq_op.rs:37:13
| |
LL | 1 / 1; LL | let _ = 1 / 1;
| ^^^^^ | ^^^^^
error: equal expressions as operands to `&&` error: equal expressions as operands to `&&`
--> $DIR/eq_op.rs:39:5 --> $DIR/eq_op.rs:38:13
| |
LL | true && true; LL | let _ = true && true;
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: equal expressions as operands to `||` error: equal expressions as operands to `||`
--> $DIR/eq_op.rs:41:5 --> $DIR/eq_op.rs:40:13
| |
LL | true || true; LL | let _ = true || true;
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: equal expressions as operands to `&&` error: equal expressions as operands to `&&`
--> $DIR/eq_op.rs:47:5 --> $DIR/eq_op.rs:45:13
| |
LL | a == b && b == a; LL | let _ = a == b && b == a;
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
error: equal expressions as operands to `&&` error: equal expressions as operands to `&&`
--> $DIR/eq_op.rs:48:5 --> $DIR/eq_op.rs:46:13
| |
LL | a != b && b != a; LL | let _ = a != b && b != a;
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
error: equal expressions as operands to `&&` error: equal expressions as operands to `&&`
--> $DIR/eq_op.rs:49:5 --> $DIR/eq_op.rs:47:13
| |
LL | a < b && b > a; LL | let _ = a < b && b > a;
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
error: equal expressions as operands to `&&` error: equal expressions as operands to `&&`
--> $DIR/eq_op.rs:50:5 --> $DIR/eq_op.rs:48:13
| |
LL | a <= b && b >= a; LL | let _ = a <= b && b >= a;
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
error: equal expressions as operands to `==` error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:53:5 --> $DIR/eq_op.rs:51:13
| |
LL | a == a; LL | let _ = a == a;
| ^^^^^^ | ^^^^^^
error: equal expressions as operands to `/` error: equal expressions as operands to `/`
--> $DIR/eq_op.rs:63:20 --> $DIR/eq_op.rs:61:20
| |
LL | const D: u32 = A / A; LL | const D: u32 = A / A;
| ^^^^^ | ^^^^^
error: equal expressions as operands to `==` error: equal expressions as operands to `==`
--> $DIR/eq_op.rs:96:5 --> $DIR/eq_op.rs:92:5
| |
LL | (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0 LL | (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[deny(clippy::eq_op)]` on by default
error: aborting due to 28 previous errors error: aborting due to 28 previous errors

View file

@ -1,15 +0,0 @@
#[warn(clippy::eq_op)]
#[test]
fn eq_op_shouldnt_trigger_in_tests() {
let a = 1;
let result = a + 1 == 1 + a;
assert!(result);
}
#[test]
fn eq_op_macros_shouldnt_trigger_in_tests() {
let a = 1;
let b = 2;
assert_eq!(a, a);
assert_eq!(a + b, b + a);
}