From d6dc48d8887bf62addc88211df1d3a62d212c9c8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 20 Nov 2024 16:17:04 +0100 Subject: [PATCH] Add ui test for `include_file_outside_project` lint --- tests/ui/include_file_outside_project.rs | 12 ++++++++++++ tests/ui/include_file_outside_project.stderr | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/ui/include_file_outside_project.rs create mode 100644 tests/ui/include_file_outside_project.stderr diff --git a/tests/ui/include_file_outside_project.rs b/tests/ui/include_file_outside_project.rs new file mode 100644 index 000000000000..1c0677828997 --- /dev/null +++ b/tests/ui/include_file_outside_project.rs @@ -0,0 +1,12 @@ +//@ normalize-stderr-test: "located at `.+/.crates.toml`" -> "located at `$$DIR/.crates.toml`" +//@ normalize-stderr-test: "folder \(`.+`" -> "folder (`$$CLIPPY_DIR`" + +#![deny(clippy::include_file_outside_project)] + +// Should not lint. +include!("./auxiliary/external_consts.rs"); + +fn main() { + let x = include_str!(concat!(env!("CARGO_HOME"), "/.crates.toml")); + //~^ include_file_outside_project +} diff --git a/tests/ui/include_file_outside_project.stderr b/tests/ui/include_file_outside_project.stderr new file mode 100644 index 000000000000..7be65c68f379 --- /dev/null +++ b/tests/ui/include_file_outside_project.stderr @@ -0,0 +1,15 @@ +error: attempted to include a file outside of the project + --> tests/ui/include_file_outside_project.rs:10:13 + | +LL | let x = include_str!(concat!(env!("CARGO_HOME"), "/.crates.toml")); + | ^ + | + = note: file is located at `$DIR/.crates.toml` which is outside of project folder (`$CLIPPY_DIR`) +note: the lint level is defined here + --> tests/ui/include_file_outside_project.rs:4:9 + | +LL | #![deny(clippy::include_file_outside_project)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error +