Skip to content

Commit

Permalink
Do not mask workspace dependencies with a source attribute - they are…
Browse files Browse the repository at this point in the history
… transitive and not sourced from the workspace
  • Loading branch information
elliotkennedy committed Sep 28, 2023
1 parent ef26ab3 commit 82326c9
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/skeleton/version_masking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn mask_local_versions_in_lockfile(
package
.get("name")
.map(|name| local_package_names.contains(name))
.unwrap_or_default()
.unwrap_or_default() && package.get("source").is_none()
})
// Mask the version
.for_each(|package| {
Expand Down
202 changes: 202 additions & 0 deletions tests/skeletons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,208 @@ version = "1.8.1"
);
}

#[test]
pub fn transitive_workspace_dependency_not_masked() {
// Arrange
let project = CargoWorkspace::new()
.manifest(
".",
r#"
[workspace]
members = [
"src/project_a",
"src/project_b",
]
"#,
)
.bin_package(
"src/project_a",
r#"
[package]
name = "project_a"
version = "2.2.2"
edition = "2018"
[[bin]]
name = "test-dummy"
path = "src/main.rs"
[dependencies]
either = { version = "=1.8.1" }
"#,
)
.lib_package(
"src/project_b",
r#"
[package]
name = "project_b"
version = "5.5.5"
edition = "2018"
[lib]
crate-type = ["cdylib"]
[dependencies]
"#,
)
.file(
"Cargo.lock",
r#"
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "either"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
dependencies = [
"project_b 5.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "project_a"
version = "2.2.2"
dependencies = [
"either",
]
[[package]]
name = "project_b"
version = "5.5.5"
[[package]]
name = "project_b"
version = "5.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
"#,
)
.build();

// Act
let skeleton = Skeleton::derive(project.path(), None).unwrap();
let cook_directory = TempDir::new().unwrap();
skeleton
.build_minimum_project(cook_directory.path(), false)
.unwrap();

// Assert
let lock_file = skeleton.lock_file.expect("there should be a lock_file");
assert!(!lock_file.contains(
r#"
[[package]]
name = "project_a"
version = "2.2.2"
"#
));
assert!(lock_file.contains(
r#"
[[package]]
name = "project_a"
version = "0.0.1"
"#
));
assert!(lock_file.contains(
r#"
[[package]]
name = "project_b"
version = "5.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
"#
));
assert!(lock_file.contains(
r#"
[[package]]
name = "project_b"
version = "0.0.1"
"#
));
assert!(lock_file.contains(
r#"
[[package]]
name = "either"
version = "1.8.1"
"#
));

let first = skeleton.manifests[0].clone();
check(
&first.contents,
expect_test::expect![[r#"
[workspace]
members = ["src/project_a", "src/project_b"]
"#]],
);
let second = skeleton.manifests[1].clone();
check(
&second.contents,
expect_test::expect![[r#"
bench = []
test = []
example = []
[[bin]]
path = "src/main.rs"
name = "test-dummy"
test = true
doctest = true
bench = true
doc = true
plugin = false
proc-macro = false
harness = true
required-features = []
[package]
name = "project_a"
edition = "2018"
version = "0.0.1"
autobins = true
autoexamples = true
autotests = true
autobenches = true
[dependencies.either]
version = "=1.8.1"
"#]],
);
let third = skeleton.manifests[2].clone();
check(
&third.contents,
expect_test::expect![[r#"
bin = []
bench = []
test = []
example = []
[package]
name = "project_b"
edition = "2018"
version = "0.0.1"
autobins = true
autoexamples = true
autotests = true
autobenches = true
[dependencies]
[lib]
test = true
doctest = true
bench = true
doc = true
plugin = false
proc-macro = false
harness = true
required-features = []
crate-type = ["cdylib"]
"#]],
);
}

#[test]
pub fn ignore_vendored_directory() {
// Arrange
Expand Down

0 comments on commit 82326c9

Please sign in to comment.