Switch over to use --registry for publish list.
authorChris Swindle <christopher.swindle@metaswitch.com>
Tue, 31 Oct 2017 06:28:09 +0000 (06:28 +0000)
committerChris Swindle <christopher.swindle@metaswitch.com>
Tue, 31 Oct 2017 06:28:09 +0000 (06:28 +0000)
src/cargo/ops/registry.rs
tests/cargotest/support/publish.rs
tests/publish.rs

index fc2cde8232cdccfb440b2517dc72a76cc51cbc93..2bd696a34ead23919a67626663f3d14889330327 100755 (executable)
@@ -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());
         }
index b82e5d0d02c0e4fe4a626d21740e1e7b7bb554e2..c827be7806500a5544fe70cb90712d2402dd9c7a 100644 (file)
@@ -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(&registry_path())
index d7eb8ab2e24391deae73c37a9f01eba8579c6d2f..96aae5a3e04d82139b97efe3dc7d48ca65849311 100755 (executable)
@@ -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
+"));
+}