From 1f1408bf38cb578f315e92e1a83137b855daca52 Mon Sep 17 00:00:00 2001 From: maciektr Date: Fri, 12 Jan 2024 11:19:27 +0100 Subject: [PATCH] Add ignored test case for dev-deps propagation (#1030) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit-id:001f9da5 --- **Stack**: - #1007 - #1030 ⬅ ⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do not merge manually using the UI - doing so may have unexpected results.* --- scarb/tests/metadata.rs | 88 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/scarb/tests/metadata.rs b/scarb/tests/metadata.rs index 91b6005f4..62102cbe1 100644 --- a/scarb/tests/metadata.rs +++ b/scarb/tests/metadata.rs @@ -2,6 +2,7 @@ use std::collections::BTreeMap; use assert_fs::prelude::*; use indoc::indoc; +use itertools::Itertools; use serde_json::json; use scarb_metadata::{Cfg, DepKind, ManifestMetadataBuilder, Metadata, PackageMetadata}; @@ -31,6 +32,18 @@ fn packages_and_deps(meta: Metadata) -> BTreeMap> { .collect::>() } +fn units_and_components(meta: Metadata) -> BTreeMap> { + meta.compilation_units + .iter() + .map(|cu| { + ( + cu.target.name.clone(), + cu.components.iter().map(|c| c.name.clone()).collect_vec(), + ) + }) + .collect::>() +} + #[test] fn simple() { let t = assert_fs::TempDir::new().unwrap(); @@ -259,6 +272,81 @@ fn dev_dependencies() { ); } +#[test] +#[ignore = "not implemented yet"] +fn dev_deps_are_not_propagated() { + // TODO(maciektr): Make sure dev-deps are not propagated. + let t = assert_fs::TempDir::new().unwrap(); + + let dep1 = t.child("dep1"); + ProjectBuilder::start().name("dep1").build(&dep1); + + let dep2 = t.child("dep2"); + ProjectBuilder::start() + .name("dep2") + .dev_dep("dep1", &dep1) + .build(&dep2); + + let pkg = t.child("pkg"); + ProjectBuilder::start() + .name("x") + .dev_dep("dep2", &dep2) + .build(&pkg); + + let metadata = Scarb::quick_snapbox() + .arg("--json") + .arg("metadata") + .arg("--format-version") + .arg("1") + .current_dir(&pkg) + .stdout_json::(); + + assert_eq!( + packages_and_deps(metadata.clone()), + BTreeMap::from_iter([ + ("core".to_string(), vec![]), + ("test_plugin".to_string(), vec![]), + ( + "x".to_string(), + vec![ + "core".to_string(), + "dep2".to_string(), + "test_plugin".to_string(), + ] + ), + ( + "dep1".to_string(), + vec!["core".to_string(), "test_plugin".to_string()] + ), + ( + "dep2".to_string(), + vec![ + "core".to_string(), + "dep1".to_string(), + "test_plugin".to_string() + ] + ) + ]) + ); + + assert_eq!( + units_and_components(metadata), + BTreeMap::from_iter(vec![ + ("x".to_string(), vec!["core".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();