Skip to content

Commit cdf1fbe

Browse files
committed
Update the test to accurately reflect behavior of cargo; this causes cargo tree-based version to fail the test
1 parent 036acd1 commit cdf1fbe

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

  • cargo-auditable/tests

cargo-auditable/tests/it.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,27 +589,47 @@ fn test_proc_macro_inner(sbom: bool) {
589589

590590
#[test]
591591
fn test_dependency_unification() {
592-
test_dependency_unification_inner(false);
593-
//test_dependency_unification_inner(true); // TODO: this fails!
592+
test_dependency_unification_inner(false); // TODO: this is a shortcoming of our filtering against `cargo tree`
593+
test_dependency_unification_inner(true);
594594
}
595595

596596
fn test_dependency_unification_inner(sbom: bool) {
597+
// Path to the toplevel crate
598+
let toplevel_crate_cargo_toml = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
599+
"tests/fixtures/runtime_and_dev_dep_with_different_features/top_level_crate/Cargo.toml",
600+
);
601+
602+
// Run in toplevel crate directory with default features; this causes a different feature resolution than using the workspace
603+
let bins = run_cargo_auditable(toplevel_crate_cargo_toml, &[], &[], sbom);
604+
eprintln!("Test fixture binary map: {bins:?}");
605+
606+
let toplevel_crate_bin = &bins.get("top_level_crate").unwrap()[0];
607+
let dep_info = get_dependency_info(toplevel_crate_bin);
608+
eprintln!("{toplevel_crate_bin} dependency info: {dep_info:?}");
609+
// optional_transitive_dep should not be present, it's only reachable through dev-dependencies
610+
assert!(!dep_info
611+
.packages
612+
.iter()
613+
.any(|p| p.name == "optional_transitive_dep"));
614+
assert!(dep_info.packages.len() == 2);
615+
597616
// Path to workspace fixture Cargo.toml. See that file for overview of workspace members and their dependencies.
598617
let workspace_cargo_toml = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
599618
.join("tests/fixtures/runtime_and_dev_dep_with_different_features/Cargo.toml");
619+
600620
// Run in workspace root with default features
601621
let bins = run_cargo_auditable(workspace_cargo_toml, &[], &[], sbom);
602622
eprintln!("Test fixture binary map: {bins:?}");
603623

604624
let toplevel_crate_bin = &bins.get("top_level_crate").unwrap()[0];
605625
let dep_info = get_dependency_info(toplevel_crate_bin);
606626
eprintln!("{toplevel_crate_bin} dependency info: {dep_info:?}");
607-
// optional_transitive_dep should not be present, it's only reachable through dev-dependencies
608-
assert!(!dep_info
627+
// optional_transitive_dep SHOULD be present, it's included because of Cargo's feature unification across a workspace
628+
assert!(dep_info
609629
.packages
610630
.iter()
611631
.any(|p| p.name == "optional_transitive_dep"));
612-
assert!(dep_info.packages.len() == 2);
632+
assert!(dep_info.packages.len() == 3);
613633
}
614634

615635
#[test]

0 commit comments

Comments
 (0)