diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2025-08-23 10:46:59 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2025-08-23 12:53:52 +0200 |
| commit | d32e5633732cfa124240c3ea8abd45d77f46c469 (patch) | |
| tree | 9b7c00cdd98521ce8cea2ed67bdfa7931776b223 | |
| parent | b7d76e299e0f03f3ab005fead1a83733398b5e88 (diff) | |
| download | rust-d32e5633732cfa124240c3ea8abd45d77f46c469.tar.gz rust-d32e5633732cfa124240c3ea8abd45d77f46c469.zip | |
Check that no profile is present in `Cargo.toml` files
| -rw-r--r-- | tests/no-profile-in-cargo-toml.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/no-profile-in-cargo-toml.rs b/tests/no-profile-in-cargo-toml.rs new file mode 100644 index 00000000000..2ad9bfb75de --- /dev/null +++ b/tests/no-profile-in-cargo-toml.rs @@ -0,0 +1,34 @@ +// Check that we do not have `profile.*` sections in our `Cargo.toml` files, +// as this causes warnings when run from the compiler repository which includes +// Clippy in a workspace. +// +// Those sections can be put into `.cargo/config.toml` which will be read +// when commands are issued from the top-level Clippy directory, outside of +// a workspace. + +use std::fs::File; +use std::io::{self, BufRead as _}; +use walkdir::WalkDir; + +#[test] +fn no_profile_in_cargo_toml() { + // This check could parse `Cargo.toml` using a TOML deserializer, but in practice + // profile sections would be added at the beginning of a line as `[profile.*]`, so + // keep it fast and simple. + for entry in WalkDir::new(".") + .into_iter() + .filter_map(Result::ok) + .filter(|e| e.file_name().to_str() == Some("Cargo.toml")) + { + for line in io::BufReader::new(File::open(entry.path()).unwrap()) + .lines() + .map(Result::unwrap) + { + if line.starts_with("[profile.") { + eprintln!("Profile section `{line}` found in file `{}`.", entry.path().display()); + eprintln!("Use `.cargo/config.toml` for profiles specific to the standalone Clippy repository."); + panic!("Profile section found in `Cargo.toml`"); + } + } + } +} |
