From 4a3d71af5fa83cc95b9c5890b34607a775e31082 Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 9 Jan 2025 03:24:25 +0100 Subject: [PATCH] Workaround for check-cfg lint warning about cfg(test) --- src/lib.rs | 6 ++++++ tests/cfg-test.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/cfg-test.rs diff --git a/src/lib.rs b/src/lib.rs index 082ee2c..5a63524 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -589,6 +589,12 @@ impl Executor for Exec { let is_path = id.source_id().is_path(); let is_workspace_member; + + // Temporary fix until https://github.com/rust-lang/cargo/pull/14963 arrives + // https://github.com/est31/cargo-udeps/issues/293 + cmd.arg("--check-cfg"); + cmd.arg("cfg(test)"); + { // TODO unwrap used let mut bt = self.data.lock().unwrap(); diff --git a/tests/cfg-test.rs b/tests/cfg-test.rs new file mode 100644 index 0000000..750cd9e --- /dev/null +++ b/tests/cfg-test.rs @@ -0,0 +1,33 @@ +mod runner; + +use cargo::CargoResult; +use pretty_assertions::assert_eq; + +use crate::runner::Runner; + +static CARGO_TOML :&str = r#"[workspace] +[package] +name = "has-test-cfg" +version = "0.0.1" +[dependencies] +"#; + +static LIB_RS :&str = r#" +#![deny(unexpected_cfgs)] +#[cfg(test)] +pub fn something_conditional() {} +"#; + +#[test] +fn cfg_test_no_unexpected_cfg() -> CargoResult<()> { + let (code, stdout_masked) = + Runner::new("cargo_udeps_cfg_test_no_unexpected_cfg")? + .cargo_toml(CARGO_TOML)? + .dir("./src")? + .file("./src/lib.rs", LIB_RS)? + .arg("--all-targets") + .run()?; + assert_eq!(0, code); + assert_eq!("All deps seem to have been used.\n", stdout_masked); + Ok(()) +}