Skip to content

Commit

Permalink
Only check for duplicate dependencies with default features
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Nov 27, 2024
1 parent 73a7d87 commit a3e53ad
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 114 deletions.
124 changes: 57 additions & 67 deletions cargo-dylint/tests/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,74 +234,64 @@ fn format_util_readmes() {
#[cfg_attr(dylint_lib = "general", allow(non_thread_safe_call_in_test))]
#[test]
fn duplicate_dependencies() {
for feature in ["cargo-cli", "cargo-lib"] {
for target in TARGETS {
let mut command = Command::new("cargo");
command.args([
"tree",
"--duplicates",
"--no-default-features",
&format!("--features={feature}"),
"--target",
target,
]);
let assert = command.assert().success();

let stdout_actual = std::str::from_utf8(&assert.get_output().stdout).unwrap();
let package_versions = stdout_actual
.lines()
.filter(|line| line.chars().next().map_or(false, char::is_alphabetic))
.map(|line| {
<[_; 2]>::try_from(line.split_ascii_whitespace().take(2).collect::<Vec<_>>())
.unwrap()
})
for target in TARGETS {
let mut command = Command::new("cargo");
command.args(["tree", "--duplicates", "--target", target]);
let assert = command.assert().success();

let stdout_actual = std::str::from_utf8(&assert.get_output().stdout).unwrap();
let package_versions = stdout_actual
.lines()
.filter(|line| line.chars().next().map_or(false, char::is_alphabetic))
.map(|line| {
<[_; 2]>::try_from(line.split_ascii_whitespace().take(2).collect::<Vec<_>>())
.unwrap()
})
.collect::<Vec<_>>();
#[allow(clippy::format_collect)]
let stdout_filtered = {
const PACKAGE: usize = 0;
const VERSION: usize = 1;
let mut package_versions_filtered = package_versions
.windows(2)
.filter(|w| w[0][PACKAGE] == w[1][PACKAGE])
.filter(|w| w[0][VERSION] != w[1][VERSION])
.flatten()
.collect::<Vec<_>>();
#[allow(clippy::format_collect)]
let stdout_filtered = {
const PACKAGE: usize = 0;
const VERSION: usize = 1;
let mut package_versions_filtered = package_versions
.windows(2)
.filter(|w| w[0][PACKAGE] == w[1][PACKAGE])
.filter(|w| w[0][VERSION] != w[1][VERSION])
.flatten()
.collect::<Vec<_>>();
// smoelius: If `package_versions` contains three versions of a package, then
// `package_versions_filtered` will contain:
// ```
// package version-0
// package version-1
// package version-1
// package version-2
// ```
package_versions_filtered.dedup();
package_versions_filtered
.into_iter()
.map(|package_version| {
format!(
"{} {}\n",
package_version[PACKAGE], package_version[VERSION]
)
})
.collect::<String>()
};

let subdir = feature.replace('-', "_");
let path = PathBuf::from(format!(
"cargo-dylint/tests/duplicate_dependencies/{subdir}/{target}.txt"
));

let stdout_expected = read_to_string(&path).unwrap();

if env::enabled("BLESS") {
write(path, stdout_filtered).unwrap();
} else {
assert!(
stdout_expected == stdout_filtered,
"{}",
SimpleDiff::from_str(&stdout_expected, &stdout_filtered, "left", "right")
);
}
// smoelius: If `package_versions` contains three versions of a package, then
// `package_versions_filtered` will contain:
// ```
// package version-0
// package version-1
// package version-1
// package version-2
// ```
package_versions_filtered.dedup();
package_versions_filtered
.into_iter()
.map(|package_version| {
format!(
"{} {}\n",
package_version[PACKAGE], package_version[VERSION]
)
})
.collect::<String>()
};

let path = PathBuf::from(format!(
"cargo-dylint/tests/duplicate_dependencies/{target}.txt"
));

let stdout_expected = read_to_string(&path).unwrap();

if env::enabled("BLESS") {
write(path, stdout_filtered).unwrap();
} else {
assert!(
stdout_expected == stdout_filtered,
"{}",
SimpleDiff::from_str(&stdout_expected, &stdout_filtered, "left", "right")
);
}
}
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit a3e53ad

Please sign in to comment.