about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorAndre Bogus <bogusandre@gmail.com>2024-04-28 00:01:14 +0200
committerblyxyas <blyxyas@gmail.com>2024-04-28 22:07:56 +0200
commit87efce4fa22f51075e1fd25904f757f783eebfdc (patch)
treee195fd5cf9ef50ad05d866818f5161544f988332 /tests
parentc6bf9548d53233f8a08928955a996f4bf30ea1bd (diff)
configurably allow `useless_vec` in tests
This adds a `àllow-useless-vec-in-test` configuration which, when set
to `true` will allow the `useless_vec` lint in `#[test]` functions and
code within `#[cfg(test)]`. It also moves a `is_in_test` helper to
`clippy_utils`.
Diffstat (limited to 'tests')
-rw-r--r--tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr3
-rw-r--r--tests/ui-toml/useless_vec/clippy.toml1
-rw-r--r--tests/ui-toml/useless_vec/useless_vec.fixed26
-rw-r--r--tests/ui-toml/useless_vec/useless_vec.rs26
-rw-r--r--tests/ui-toml/useless_vec/useless_vec.stderr11
5 files changed, 67 insertions, 0 deletions
diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
index 24645b61fdb..722e9b3bc8d 100644
--- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
+++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
@@ -11,6 +11,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
            allow-print-in-tests
            allow-private-module-inception
            allow-unwrap-in-tests
+           allow-useless-vec-in-tests
            allowed-dotfiles
            allowed-duplicate-crates
            allowed-idents-below-min-chars
@@ -91,6 +92,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
            allow-print-in-tests
            allow-private-module-inception
            allow-unwrap-in-tests
+           allow-useless-vec-in-tests
            allowed-dotfiles
            allowed-duplicate-crates
            allowed-idents-below-min-chars
@@ -171,6 +173,7 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
            allow-print-in-tests
            allow-private-module-inception
            allow-unwrap-in-tests
+           allow-useless-vec-in-tests
            allowed-dotfiles
            allowed-duplicate-crates
            allowed-idents-below-min-chars
diff --git a/tests/ui-toml/useless_vec/clippy.toml b/tests/ui-toml/useless_vec/clippy.toml
new file mode 100644
index 00000000000..230ca2d0ab7
--- /dev/null
+++ b/tests/ui-toml/useless_vec/clippy.toml
@@ -0,0 +1 @@
+allow-useless-vec-in-tests = true
diff --git a/tests/ui-toml/useless_vec/useless_vec.fixed b/tests/ui-toml/useless_vec/useless_vec.fixed
new file mode 100644
index 00000000000..08323a0dcc9
--- /dev/null
+++ b/tests/ui-toml/useless_vec/useless_vec.fixed
@@ -0,0 +1,26 @@
+//@compile-flags: --test
+#![warn(clippy::useless_vec)]
+#![allow(clippy::unnecessary_operation, clippy::no_effect)]
+
+fn foo(_: &[u32]) {}
+
+fn main() {
+    foo(&[1_u32]);
+}
+
+#[test]
+pub fn in_test() {
+    foo(&vec![2_u32]);
+}
+
+#[cfg(test)]
+fn in_cfg_test() {
+    foo(&vec![3_u32]);
+}
+
+#[cfg(test)]
+mod mod1 {
+    fn in_cfg_test_mod() {
+        super::foo(&vec![4_u32]);
+    }
+}
diff --git a/tests/ui-toml/useless_vec/useless_vec.rs b/tests/ui-toml/useless_vec/useless_vec.rs
new file mode 100644
index 00000000000..1f4b27c5342
--- /dev/null
+++ b/tests/ui-toml/useless_vec/useless_vec.rs
@@ -0,0 +1,26 @@
+//@compile-flags: --test
+#![warn(clippy::useless_vec)]
+#![allow(clippy::unnecessary_operation, clippy::no_effect)]
+
+fn foo(_: &[u32]) {}
+
+fn main() {
+    foo(&vec![1_u32]);
+}
+
+#[test]
+pub fn in_test() {
+    foo(&vec![2_u32]);
+}
+
+#[cfg(test)]
+fn in_cfg_test() {
+    foo(&vec![3_u32]);
+}
+
+#[cfg(test)]
+mod mod1 {
+    fn in_cfg_test_mod() {
+        super::foo(&vec![4_u32]);
+    }
+}
diff --git a/tests/ui-toml/useless_vec/useless_vec.stderr b/tests/ui-toml/useless_vec/useless_vec.stderr
new file mode 100644
index 00000000000..633110c3c8d
--- /dev/null
+++ b/tests/ui-toml/useless_vec/useless_vec.stderr
@@ -0,0 +1,11 @@
+error: useless use of `vec!`
+  --> tests/ui-toml/useless_vec/useless_vec.rs:8:9
+   |
+LL |     foo(&vec![1_u32]);
+   |         ^^^^^^^^^^^^ help: you can use a slice directly: `&[1_u32]`
+   |
+   = note: `-D clippy::useless-vec` implied by `-D warnings`
+   = help: to override `-D warnings` add `#[allow(clippy::useless_vec)]`
+
+error: aborting due to 1 previous error
+