From b486ada19ff9b065520b4aa0da4408fab7b1746f Mon Sep 17 00:00:00 2001 From: likzn <1020193211@qq.com> Date: Thu, 26 May 2022 08:49:06 +0800 Subject: [PATCH] clean err msg --- src/cargo/ops/registry.rs | 14 +++------- tests/testsuite/publish.rs | 52 +++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 32a8217fe10..5bd8decb1b8 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -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() diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index b1af6eb5785..1977aba7007 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -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(); } @@ -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();