From caf7681fe2f7c28f0d3e1e9efca03739da4d7a51 Mon Sep 17 00:00:00 2001 From: Chris Swindle Date: Tue, 31 Oct 2017 06:28:09 +0000 Subject: [PATCH] Switch over to use --registry for publish list. --- src/cargo/ops/registry.rs | 3 +- tests/cargotest/support/publish.rs | 13 ++++++- tests/publish.rs | 59 ++++++++++++++++++++++-------- 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index fc2cde823..2bd696a34 100755 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -43,8 +43,7 @@ pub fn publish(ws: &Workspace, opts: &PublishOpts) -> CargoResult<()> { let pkg = ws.current()?; if let &Some(ref allowed_registries) = pkg.publish() { - let index = opts.index.clone(); - if index.is_none() || !allowed_registries.contains(&index.unwrap()) { + if opts.registry.is_none() || !allowed_registries.contains(&opts.registry.clone().unwrap()) { bail!("some crates cannot be published.\n\ `{}` is marked as unpublishable", pkg.name()); } diff --git a/tests/cargotest/support/publish.rs b/tests/cargotest/support/publish.rs index b82e5d0d0..c827be780 100644 --- a/tests/cargotest/support/publish.rs +++ b/tests/cargotest/support/publish.rs @@ -10,10 +10,21 @@ use url::Url; pub fn setup() -> Repository { let config = paths::root().join(".cargo/config"); t!(fs::create_dir_all(config.parent().unwrap())); - t!(t!(File::create(&config)).write_all(br#" + t!(t!(File::create(&config)).write_all(format!(r#" [registry] token = "api-token" + + [registries.alternative] + index = "{registry}" + "#, registry = registry().to_string()).as_bytes())); + + let credentials = paths::root().join("home/.cargo/credentials"); + t!(fs::create_dir_all(credentials.parent().unwrap())); + t!(t!(File::create(&credentials)).write_all(br#" + [alternative] + token = "api-token" "#)); + t!(fs::create_dir_all(&upload_path().join("api/v1/crates"))); repo(®istry_path()) diff --git a/tests/publish.rs b/tests/publish.rs index d7eb8ab2e..96aae5a3e 100755 --- a/tests/publish.rs +++ b/tests/publish.rs @@ -7,6 +7,7 @@ use std::io::prelude::*; use std::fs::File; use std::io::SeekFrom; +use cargotest::ChannelChanger; use cargotest::support::git::repo; use cargotest::support::paths; use cargotest::support::{project, execs, publish}; @@ -502,7 +503,7 @@ See [..] } #[test] -fn index_not_in_publish_list() { +fn registry_not_in_publish_list() { publish::setup(); let p = project("foo") @@ -517,10 +518,11 @@ fn index_not_in_publish_list() { "test" ] "#) - .file("src/main.rs", "fn main() {}"); + .file("src/main.rs", "fn main() {}") + .build(); - assert_that(p.cargo_process("publish") - .arg("--index").arg(publish::registry().to_string()), + assert_that(p.cargo("publish").masquerade_as_nightly_cargo() + .arg("--registry").arg("alternative").arg("-Zunstable-options"), execs().with_status(101).with_stderr("\ [ERROR] some crates cannot be published. `foo` is marked as unpublishable @@ -541,10 +543,11 @@ fn publish_empty_list() { description = "foo" publish = [] "#) - .file("src/main.rs", "fn main() {}"); + .file("src/main.rs", "fn main() {}") + .build(); - assert_that(p.cargo_process("publish") - .arg("--index").arg(publish::registry().to_string()), + assert_that(p.cargo("publish").masquerade_as_nightly_cargo() + .arg("--registry").arg("alternative").arg("-Zunstable-options"), execs().with_status(101).with_stderr("\ [ERROR] some crates cannot be published. `foo` is marked as unpublishable @@ -552,14 +555,13 @@ fn publish_empty_list() { } #[test] -fn publish_allowed_index() { +fn publish_allowed_registry() { publish::setup(); - let p = project("foo"); - p.build(); + let p = project("foo").build(); - repo(&paths::root().join("foo")) - .file("Cargo.toml", &format!(r#" + let _ = repo(&paths::root().join("foo")) + .file("Cargo.toml", r#" [project] name = "foo" version = "0.0.1" @@ -568,12 +570,37 @@ fn publish_allowed_index() { description = "foo" documentation = "foo" homepage = "foo" - publish = ["{}"] - "#, publish::registry().to_string())) + publish = ["alternative"] + "#) .file("src/main.rs", "fn main() {}") .build(); - assert_that(p.cargo("publish") - .arg("--index").arg(publish::registry().to_string()), + assert_that(p.cargo("publish").masquerade_as_nightly_cargo() + .arg("--registry").arg("alternative").arg("-Zunstable-options"), execs().with_status(0)); } + +#[test] +fn block_publish_no_registry() { + publish::setup(); + + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + license = "MIT" + description = "foo" + publish = [] + "#) + .file("src/main.rs", "fn main() {}") + .build(); + + assert_that(p.cargo("publish").masquerade_as_nightly_cargo() + .arg("--index").arg(publish::registry().to_string()), + execs().with_status(101).with_stderr("\ +[ERROR] some crates cannot be published. +`foo` is marked as unpublishable +")); +} -- 2.30.2