test: verify publish failed with --index and the only implicit allowed registry

The message is misleading and shouldn't proceed when `--index` presents.
This commit is contained in:
Weihang Lo 2023-09-16 00:47:59 +08:00
parent e57ce13da8
commit e883054c59
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7

View File

@ -921,6 +921,48 @@ You may press ctrl-c [..]
);
}
#[cargo_test]
fn publish_failed_with_index_and_only_allowed_registry() {
let registry = RegistryBuilder::new()
.http_api()
.http_index()
.alternative()
.build();
let p = project().build();
let _ = repo(&paths::root().join("foo"))
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
documentation = "foo"
homepage = "foo"
repository = "foo"
publish = ["alternative"]
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("publish")
.arg("--index")
.arg(registry.index_url().as_str())
.with_status(101)
.with_stderr(
"\
[NOTE] Found `alternative` as only allowed registry. Publishing to it automatically.
[ERROR] command-line argument --index requires --token to be specified
",
)
.run();
}
#[cargo_test]
fn publish_fail_with_no_registry_specified() {
let p = project().build();