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

Use workspace lockfile when running cargo package and cargo publish #11477

Merged
merged 4 commits into from
Dec 19, 2022
Merged
Changes from 1 commit
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
94 changes: 94 additions & 0 deletions tests/testsuite/publish_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,97 @@ fn ignore_lockfile_inner() {
)
.run();
}

#[cargo_test]
fn respect_workspace_lockfile() {
// Issue #11148
Package::new("serde", "0.2.0").publish();
Package::new("serde", "0.2.1").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"

[dependencies]
serde = "0.2"

[workspace]
members = ["bar"]
"#,
)
.file("src/main.rs", "fn main() {}")
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
license = "MIT"
description = "bar"
workspace = ".."

[dependencies]
serde = "0.2"
"#,
)
.file("bar/src/main.rs", "fn main() {}")
.build();
p.cargo("generate-lockfile").run();
p.cargo("update -p serde:0.2.1 --precise 0.2.0").run();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to move Package::new("serde", "0.2.1").publish(); to this line (and to replace it)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Yeah, that makes it clearer what the test is doing.


p.cargo("package --workspace")
.with_stderr(
"\
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] bar v0.0.1 ([CWD]/bar)
[UPDATING] `dummy-registry` index
[VERIFYING] bar v0.0.1 ([CWD]/bar)
[DOWNLOADING] crates ...
[DOWNLOADED] serde v0.2.1 ([..])
[COMPILING] serde v0.2.1
[COMPILING] bar v0.0.1 ([CWD][..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] 4 files, [..]
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ([CWD])
[VERIFYING] foo v0.0.1 ([CWD])
[DOWNLOADING] crates ...
[DOWNLOADED] serde v0.2.0 ([..])
[COMPILING] serde v0.2.0
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] 4 files, [..]
",
)
.run();

let package_path = p.root().join("target/package/foo-0.0.1.crate");
assert!(package_path.is_file());
let f = File::open(&package_path).unwrap();
validate_crate_contents(
f,
"foo-0.0.1.crate",
&["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
&[],
);

let package_path = p.root().join("target/package/bar-0.0.1.crate");
assert!(package_path.is_file());
let f = File::open(&package_path).unwrap();
validate_crate_contents(
f,
"bar-0.0.1.crate",
&["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
&[],
);
}