diff --git a/scarb/src/core/resolver.rs b/scarb/src/core/resolver.rs index a66096b74..033d53b42 100644 --- a/scarb/src/core/resolver.rs +++ b/scarb/src/core/resolver.rs @@ -41,7 +41,10 @@ impl Resolve { /// * Asserts that `root_package` is a node in this graph. pub fn solution_of(&self, root_package: PackageId, target_kind: &TargetKind) -> Vec { assert!(&self.graph.contains_node(root_package)); - let filtered_graph = EdgeFiltered::from_fn(&self.graph, move |(_node_a, _node_b, edge)| { + let filtered_graph = EdgeFiltered::from_fn(&self.graph, move |(node_a, _node_b, edge)| { + if target_kind == &TargetKind::TEST && node_a != root_package { + return false; + } edge.accepts_target(target_kind.clone()) }); Dfs::new(&filtered_graph, root_package) diff --git a/scarb/tests/metadata.rs b/scarb/tests/metadata.rs index acac23a00..a372a06bd 100644 --- a/scarb/tests/metadata.rs +++ b/scarb/tests/metadata.rs @@ -313,6 +313,72 @@ fn dev_deps_are_not_propagated() { ); } +#[test] +fn dev_deps_are_not_propagated_for_ws_members() { + let t = assert_fs::TempDir::new().unwrap(); + + let dep1 = t.child("dep1"); + ProjectBuilder::start() + .name("dep1") + .dep_cairo_test() + .build(&dep1); + + let dep2 = t.child("dep2"); + ProjectBuilder::start() + .name("dep2") + .dep_cairo_test() + .dev_dep("dep1", &dep1) + .build(&dep2); + + let pkg = t.child("pkg"); + ProjectBuilder::start() + .name("x") + .dep_cairo_test() + .dep("dep2", &dep2) + .build(&pkg); + + WorkspaceBuilder::start() + .add_member("dep2") + .add_member("pkg") + .build(&t); + + let metadata = Scarb::quick_snapbox() + .arg("--json") + .arg("metadata") + .arg("--format-version") + .arg("1") + .current_dir(&t) + .stdout_json::(); + + assert_eq!( + units_and_components(metadata), + BTreeMap::from_iter(vec![ + ( + "dep2".to_string(), + vec!["core".to_string(), "dep2".to_string()] + ), + ( + "dep2_unittest".to_string(), + vec!["core".to_string(), "dep1".to_string(), "dep2".to_string()] + ), + ( + "x".to_string(), + vec!["core".to_string(), "dep2".to_string(), "x".to_string()] + ), + ( + "x_unittest".to_string(), + vec![ + "core".to_string(), + // With dev-deps propagation enabled, this would be included + // "dep1".to_string(), + "dep2".to_string(), + "x".to_string() + ] + ), + ]) + ); +} + #[test] fn no_dep() { let t = assert_fs::TempDir::new().unwrap();