about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorTrevor Arjeski <tmarjeski@gmail.com>2022-11-04 20:33:04 +0300
committerTrevor Arjeski <tmarjeski@gmail.com>2022-11-04 20:33:04 +0300
commitddcfff6d9a33fd8ee95f715055e8ea3e691cc1f2 (patch)
tree740565d66145883c072f1dd2640679981c6fedd7 /tests
parent704e00cb75ef5be2080d21be0965afd938d6fbec (diff)
Add allow-print-in-tests config
Add a config, allow-print-in-tests, that can be set in clippy.toml which
allows the usage of `[e]print[ln]!` macros in tests.

Closes #9795
Diffstat (limited to 'tests')
-rw-r--r--tests/ui-toml/print_macro/clippy.toml1
-rw-r--r--tests/ui-toml/print_macro/print_macro.rs20
-rw-r--r--tests/ui-toml/print_macro/print_macro.stderr18
-rw-r--r--tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr1
4 files changed, 40 insertions, 0 deletions
diff --git a/tests/ui-toml/print_macro/clippy.toml b/tests/ui-toml/print_macro/clippy.toml
new file mode 100644
index 00000000000..40b1dda5b2e
--- /dev/null
+++ b/tests/ui-toml/print_macro/clippy.toml
@@ -0,0 +1 @@
+allow-print-in-tests = true
diff --git a/tests/ui-toml/print_macro/print_macro.rs b/tests/ui-toml/print_macro/print_macro.rs
new file mode 100644
index 00000000000..5aefb6a6b4d
--- /dev/null
+++ b/tests/ui-toml/print_macro/print_macro.rs
@@ -0,0 +1,20 @@
+// compile-flags: --test
+#![warn(clippy::print_stdout)]
+#![warn(clippy::print_stderr)]
+
+fn foo(n: u32) {
+    print!("{n}");
+    eprint!("{n}");
+}
+
+#[test]
+pub fn foo1() {
+    print!("{}", 1);
+    eprint!("{}", 1);
+}
+
+#[cfg(test)]
+fn foo3() {
+    print!("{}", 1);
+    eprint!("{}", 1);
+}
diff --git a/tests/ui-toml/print_macro/print_macro.stderr b/tests/ui-toml/print_macro/print_macro.stderr
new file mode 100644
index 00000000000..d4b1ae84fd7
--- /dev/null
+++ b/tests/ui-toml/print_macro/print_macro.stderr
@@ -0,0 +1,18 @@
+error: use of `print!`
+  --> $DIR/print_macro.rs:6:5
+   |
+LL |     print!("{n}");
+   |     ^^^^^^^^^^^^^
+   |
+   = note: `-D clippy::print-stdout` implied by `-D warnings`
+
+error: use of `eprint!`
+  --> $DIR/print_macro.rs:7:5
+   |
+LL |     eprint!("{n}");
+   |     ^^^^^^^^^^^^^^
+   |
+   = note: `-D clippy::print-stderr` implied by `-D warnings`
+
+error: aborting due to 2 previous errors
+
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 b7842c36240..f91d285c2e0 100644
--- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
+++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
@@ -1,6 +1,7 @@
 error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of
            allow-dbg-in-tests
            allow-expect-in-tests
+           allow-print-in-tests
            allow-unwrap-in-tests
            allowed-scripts
            arithmetic-side-effects-allowed