Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not mask workspace dependencies with a source attribute #247

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/skeleton/version_masking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn mask_local_versions_in_lockfile(
.get("name")
.map(|name| local_package_names.contains(name))
.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