Skip to content

Commit

Permalink
Workaround for check-cfg lint warning about cfg(test)
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed Jan 9, 2025
1 parent faedbaa commit 4a3d71a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
33 changes: 33 additions & 0 deletions tests/cfg-test.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

0 comments on commit 4a3d71a

Please sign in to comment.