Skip to content

Commit

Permalink
clean err msg
Browse files Browse the repository at this point in the history
  • Loading branch information
likzn committed May 26, 2022
1 parent 52165e8 commit b486ada
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
14 changes: 3 additions & 11 deletions src/cargo/ops/registry.rs
Expand Up @@ -92,24 +92,16 @@ pub struct PublishOpts<'cfg> {
pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
let specs = opts.to_publish.to_package_id_specs(ws)?;
if specs.len() > 1 {
match opts.to_publish {
Packages::Default => {
bail!("must be specified to select a single package to publish. Check `default-members` or using `-p` argument")
}
Packages::Packages(_) => {
bail!("the `-p` argument must be specified to select a single package to publish")
}
_ => {}
}
bail!("the `-p` argument must be specified to select a single package to publish")
}
if Packages::Packages(vec![]) != opts.to_publish && ws.is_virtual() {
if Packages::Default == opts.to_publish && ws.is_virtual() {
bail!("the `-p` argument must be specified in the root of a virtual workspace")
}
let member_ids = ws.members().map(|p| p.package_id());
// Check that the spec matches exactly one member.
specs[0].query(member_ids)?;
let mut pkgs = ws.members_with_features(&specs, &opts.cli_features)?;
// In `members_with_features_old`, it will add "current" package(determined by the cwd). Line:1455 in workspace.rs.
// In `members_with_features_old`, it will add "current" package (determined by the cwd)
// So we need filter
pkgs = pkgs
.into_iter()
Expand Down
52 changes: 51 additions & 1 deletion tests/testsuite/publish.rs
Expand Up @@ -1754,7 +1754,7 @@ fn with_duplicate_spec_in_members() {
p.cargo("publish --no-verify --token sekrit")
.with_status(101)
.with_stderr(
"error: must be specified to select a single package to publish. Check `default-members` or using `-p` argument",
"error: the `-p` argument must be specified to select a single package to publish",
)
.run();
}
Expand Down Expand Up @@ -1837,6 +1837,56 @@ fn in_virtual_workspace() {
.run();
}

#[cargo_test]
fn in_virtual_workspace_with_p() {
registry::init();

let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["foo","li"]
"#,
)
.file(
"foo/Cargo.toml",
r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
"#,
)
.file("foo/src/main.rs", "fn main() {}")
.file(
"li/Cargo.toml",
r#"
[package]
name = "li"
version = "0.0.1"
description = "li"
license = "MIT"
"#,
)
.file("li/src/main.rs", "fn main() {}")
.build();

p.cargo("publish -p li --no-verify --token sekrit")
.with_stderr(
"\
[UPDATING] [..]
[WARNING] manifest has no documentation, homepage or repository.
See [..]
[PACKAGING] li v0.0.1 ([CWD]/li)
[UPLOADING] li v0.0.1 ([CWD]/li)
",
)
.run();
}

#[cargo_test]
fn in_package_workspace_not_found() {
registry::init();
Expand Down

0 comments on commit b486ada

Please sign in to comment.