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())
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};
}
#[test]
-fn index_not_in_publish_list() {
+fn registry_not_in_publish_list() {
publish::setup();
let p = project("foo")
"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
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
}
#[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"
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
+"));
+}