From cb37d335fc6046b4658746cf831a0cc66d45b66e Mon Sep 17 00:00:00 2001 From: Chris Swindle Date: Wed, 8 Nov 2017 05:42:48 +0000 Subject: [PATCH] Code review markups. --- src/cargo/ops/registry.rs | 5 ++++- tests/alt-registry.rs | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index eef46da9e20..18f2d5cea6a 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -43,7 +43,10 @@ pub fn publish(ws: &Workspace, opts: &PublishOpts) -> CargoResult<()> { let pkg = ws.current()?; if let &Some(ref allowed_registries) = pkg.publish() { - if opts.registry.is_none() || !allowed_registries.contains(&opts.registry.clone().unwrap()) { + if !match opts.registry { + Some(ref registry) => allowed_registries.contains(registry), + None => false, + } { bail!("some crates cannot be published.\n\ `{}` is marked as unpublishable", pkg.name()); } diff --git a/tests/alt-registry.rs b/tests/alt-registry.rs index fa8c15b8d99..430a37fcc53 100644 --- a/tests/alt-registry.rs +++ b/tests/alt-registry.rs @@ -73,7 +73,7 @@ fn depend_on_alt_registry() { } #[test] -fn depend_on_alt_registry_depends_on_same_registry() { +fn depend_on_alt_registry_depends_on_same_registry_no_index() { let p = project("foo") .file("Cargo.toml", r#" cargo-features = ["alternative-registries"] @@ -107,6 +107,41 @@ fn depend_on_alt_registry_depends_on_same_registry() { reg = registry::alt_registry()))); } +#[test] +fn depend_on_alt_registry_depends_on_same_registry() { + let p = project("foo") + .file("Cargo.toml", r#" + cargo-features = ["alternative-registries"] + + [project] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies.bar] + version = "0.0.1" + registry = "alternative" + "#) + .file("src/main.rs", "fn main() {}") + .build(); + + Package::new("baz", "0.0.1").alternative(true).publish(); + Package::new("bar", "0.0.1").registry_dep("baz", "0.0.1", registry::alt_registry().as_str()).alternative(true).publish(); + + assert_that(p.cargo("build").masquerade_as_nightly_cargo(), + execs().with_status(0).with_stderr(&format!("\ +[UPDATING] registry `{reg}` +[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`) +[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`) +[COMPILING] baz v0.0.1 (registry `file://[..]`) +[COMPILING] bar v0.0.1 (registry `file://[..]`) +[COMPILING] foo v0.0.1 ({dir}) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +", + dir = p.url(), + reg = registry::alt_registry()))); +} + #[test] fn depend_on_alt_registry_depends_on_crates_io() { let p = project("foo")