2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for the `cargo publish` command.
|
|
|
|
|
2017-12-20 03:37:14 +00:00
|
|
|
use std::fs::{self, File};
|
2018-08-28 09:20:03 +00:00
|
|
|
use std::io::prelude::*;
|
2014-09-09 14:23:09 +00:00
|
|
|
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::git::{self, repo};
|
|
|
|
use cargo_test_support::paths;
|
|
|
|
use cargo_test_support::registry::{self, registry_path, registry_url, Package};
|
|
|
|
use cargo_test_support::{basic_manifest, project, publish};
|
2018-12-30 04:46:15 +00:00
|
|
|
|
|
|
|
const CLEAN_FOO_JSON: &str = r#"
|
|
|
|
{
|
|
|
|
"authors": [],
|
|
|
|
"badges": {},
|
|
|
|
"categories": [],
|
|
|
|
"deps": [],
|
|
|
|
"description": "foo",
|
|
|
|
"documentation": "foo",
|
|
|
|
"features": {},
|
|
|
|
"homepage": "foo",
|
|
|
|
"keywords": [],
|
|
|
|
"license": "MIT",
|
|
|
|
"license_file": null,
|
|
|
|
"links": null,
|
|
|
|
"name": "foo",
|
|
|
|
"readme": null,
|
|
|
|
"readme_file": null,
|
|
|
|
"repository": "foo",
|
|
|
|
"vers": "0.0.1"
|
|
|
|
}
|
|
|
|
"#;
|
|
|
|
|
|
|
|
fn validate_upload_foo() {
|
|
|
|
publish::validate_upload(
|
|
|
|
r#"
|
|
|
|
{
|
|
|
|
"authors": [],
|
|
|
|
"badges": {},
|
|
|
|
"categories": [],
|
|
|
|
"deps": [],
|
|
|
|
"description": "foo",
|
|
|
|
"documentation": null,
|
|
|
|
"features": {},
|
|
|
|
"homepage": null,
|
|
|
|
"keywords": [],
|
|
|
|
"license": "MIT",
|
|
|
|
"license_file": null,
|
|
|
|
"links": null,
|
|
|
|
"name": "foo",
|
|
|
|
"readme": null,
|
|
|
|
"readme_file": null,
|
|
|
|
"repository": null,
|
|
|
|
"vers": "0.0.1"
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
"foo-0.0.1.crate",
|
2019-06-10 19:38:51 +00:00
|
|
|
&["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
|
2018-12-30 04:46:15 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn validate_upload_foo_clean() {
|
|
|
|
publish::validate_upload(
|
|
|
|
CLEAN_FOO_JSON,
|
|
|
|
"foo-0.0.1.crate",
|
|
|
|
&[
|
2019-06-10 19:38:51 +00:00
|
|
|
"Cargo.lock",
|
2018-12-30 04:46:15 +00:00
|
|
|
"Cargo.toml",
|
|
|
|
"Cargo.toml.orig",
|
|
|
|
"src/main.rs",
|
|
|
|
".cargo_vcs_info.json",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2014-09-09 14:23:09 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn simple() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2016-05-25 20:55:42 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-06-22 19:32:30 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-06-22 19:32:30 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish --no-verify --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr(&format!(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 09:23:57 +00:00
|
|
|
[UPDATING] `{reg}` index
|
2017-06-22 19:32:30 +00:00
|
|
|
[WARNING] manifest has no documentation, [..]
|
|
|
|
See [..]
|
2018-09-08 02:42:26 +00:00
|
|
|
[PACKAGING] foo v0.0.1 ([CWD])
|
|
|
|
[UPLOADING] foo v0.0.1 ([CWD])
|
2017-12-20 03:37:14 +00:00
|
|
|
",
|
2019-01-11 23:56:46 +00:00
|
|
|
reg = registry::registry_path().to_str().unwrap()
|
2018-12-08 11:19:47 +00:00
|
|
|
))
|
|
|
|
.run();
|
2017-12-20 03:37:14 +00:00
|
|
|
|
2018-12-30 04:46:15 +00:00
|
|
|
validate_upload_foo();
|
2017-12-20 03:37:14 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-12-20 03:37:14 +00:00
|
|
|
fn old_token_location() {
|
2019-01-11 23:56:46 +00:00
|
|
|
// Check that the `token` key works at the root instead of under a
|
|
|
|
// `[registry]` table.
|
|
|
|
registry::init();
|
2017-12-20 03:37:14 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-12-20 03:37:14 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-12-20 03:37:14 +00:00
|
|
|
.build();
|
|
|
|
|
2019-01-11 23:56:46 +00:00
|
|
|
let credentials = paths::home().join(".cargo/credentials");
|
|
|
|
fs::remove_file(&credentials).unwrap();
|
|
|
|
|
|
|
|
// Verify can't publish without a token.
|
|
|
|
p.cargo("publish --no-verify --index")
|
|
|
|
.arg(registry_url().to_string())
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[ERROR] no upload token found, please run `cargo login`")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
File::create(&credentials)
|
|
|
|
.unwrap()
|
|
|
|
.write_all(br#"token = "api-token""#)
|
|
|
|
.unwrap();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish --no-verify --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr(&format!(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 09:23:57 +00:00
|
|
|
[UPDATING] `{reg}` index
|
2017-12-20 03:37:14 +00:00
|
|
|
[WARNING] manifest has no documentation, [..]
|
|
|
|
See [..]
|
2018-09-08 02:42:26 +00:00
|
|
|
[PACKAGING] foo v0.0.1 ([CWD])
|
|
|
|
[UPLOADING] foo v0.0.1 ([CWD])
|
2017-06-22 19:32:30 +00:00
|
|
|
",
|
2019-01-11 23:56:46 +00:00
|
|
|
reg = registry_path().to_str().unwrap()
|
2018-12-08 11:19:47 +00:00
|
|
|
))
|
|
|
|
.run();
|
2017-06-22 19:32:30 +00:00
|
|
|
|
2018-12-30 04:46:15 +00:00
|
|
|
validate_upload_foo();
|
2017-06-22 19:32:30 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 20:34:57 +00:00
|
|
|
// TODO: Deprecated
|
|
|
|
// remove once it has been decided --host can be removed
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-06-22 19:32:30 +00:00
|
|
|
fn simple_with_host() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2017-06-22 19:32:30 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-09-09 14:23:09 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-11-18 12:23:53 +00:00
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-09-09 14:23:09 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish --no-verify --host")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr(&format!(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2017-06-22 19:32:30 +00:00
|
|
|
[WARNING] The flag '--host' is no longer valid.
|
|
|
|
|
|
|
|
Previous versions of Cargo accepted this flag, but it is being
|
|
|
|
deprecated. The flag is being renamed to 'index', as the flag
|
2018-03-08 11:12:00 +00:00
|
|
|
wants the location of the index. Please use '--index' instead.
|
2017-06-22 19:47:07 +00:00
|
|
|
|
|
|
|
This will soon become a hard error, so it's either recommended
|
|
|
|
to update to a fixed version or contact the upstream maintainer
|
|
|
|
about this warning.
|
2018-09-08 09:23:57 +00:00
|
|
|
[UPDATING] `{reg}` index
|
2017-06-22 19:47:07 +00:00
|
|
|
[WARNING] manifest has no documentation, [..]
|
|
|
|
See [..]
|
2018-09-08 02:42:26 +00:00
|
|
|
[PACKAGING] foo v0.0.1 ([CWD])
|
|
|
|
[UPLOADING] foo v0.0.1 ([CWD])
|
2017-06-22 19:47:07 +00:00
|
|
|
",
|
2019-01-11 23:56:46 +00:00
|
|
|
reg = registry_path().to_str().unwrap()
|
2018-12-08 11:19:47 +00:00
|
|
|
))
|
|
|
|
.run();
|
2017-06-22 19:47:07 +00:00
|
|
|
|
2018-12-30 04:46:15 +00:00
|
|
|
validate_upload_foo();
|
2017-06-22 19:47:07 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 20:34:57 +00:00
|
|
|
// TODO: Deprecated
|
|
|
|
// remove once it has been decided --host can be removed
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-06-22 19:47:07 +00:00
|
|
|
fn simple_with_index_and_host() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2017-06-22 19:47:07 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-06-22 19:47:07 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-06-22 19:47:07 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish --no-verify --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.arg("--host")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr(&format!(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2017-06-22 19:47:07 +00:00
|
|
|
[WARNING] The flag '--host' is no longer valid.
|
|
|
|
|
|
|
|
Previous versions of Cargo accepted this flag, but it is being
|
|
|
|
deprecated. The flag is being renamed to 'index', as the flag
|
2018-03-08 11:12:00 +00:00
|
|
|
wants the location of the index. Please use '--index' instead.
|
2017-06-22 19:32:30 +00:00
|
|
|
|
|
|
|
This will soon become a hard error, so it's either recommended
|
|
|
|
to update to a fixed version or contact the upstream maintainer
|
|
|
|
about this warning.
|
2018-09-08 09:23:57 +00:00
|
|
|
[UPDATING] `{reg}` index
|
2016-05-20 14:00:15 +00:00
|
|
|
[WARNING] manifest has no documentation, [..]
|
2016-09-01 00:04:29 +00:00
|
|
|
See [..]
|
2018-09-08 02:42:26 +00:00
|
|
|
[PACKAGING] foo v0.0.1 ([CWD])
|
|
|
|
[UPLOADING] foo v0.0.1 ([CWD])
|
2014-09-09 14:23:09 +00:00
|
|
|
",
|
2019-01-11 23:56:46 +00:00
|
|
|
reg = registry_path().to_str().unwrap()
|
2018-12-08 11:19:47 +00:00
|
|
|
))
|
|
|
|
.run();
|
2014-09-09 14:23:09 +00:00
|
|
|
|
2018-12-30 04:46:15 +00:00
|
|
|
validate_upload_foo();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn git_deps() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2014-09-09 14:23:09 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-09-09 14:23:09 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-11-18 12:23:53 +00:00
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
2014-09-09 14:23:09 +00:00
|
|
|
|
|
|
|
[dependencies.foo]
|
|
|
|
git = "git://path/to/nowhere"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-09-09 14:23:09 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish -v --no-verify --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 09:23:57 +00:00
|
|
|
[UPDATING] [..] index
|
2019-08-11 23:50:13 +00:00
|
|
|
[ERROR] all dependencies must have a version specified when publishing.
|
|
|
|
dependency `foo` does not specify a version
|
|
|
|
Note: The published dependency will use the version from crates.io,
|
|
|
|
the `git` specification will be removed from the dependency declaration.
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn path_dependency_no_version() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2014-09-27 04:14:46 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-09-27 04:14:46 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-11-18 12:23:53 +00:00
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
2014-09-27 04:14:46 +00:00
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
2014-09-09 14:23:09 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 09:23:57 +00:00
|
|
|
[UPDATING] [..] index
|
2019-08-11 23:50:13 +00:00
|
|
|
[ERROR] all dependencies must have a version specified when publishing.
|
2014-09-27 04:14:46 +00:00
|
|
|
dependency `bar` does not specify a version
|
2019-08-11 23:50:13 +00:00
|
|
|
Note: The published dependency will use the version from crates.io,
|
|
|
|
the `path` specification will be removed from the dependency declaration.
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn unpublishable_crate() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2016-01-23 21:16:30 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-01-23 21:16:30 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
publish = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-01-23 21:16:30 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2019-04-11 18:34:00 +00:00
|
|
|
[ERROR] `foo` cannot be published.
|
|
|
|
The registry `crates-io` is not listed in the `publish` value in Cargo.toml.
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-06-10 13:43:34 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-06-10 13:43:34 +00:00
|
|
|
fn dont_publish_dirty() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project().file("bar", "").build();
|
2016-06-10 13:43:34 +00:00
|
|
|
|
2019-08-11 23:50:13 +00:00
|
|
|
let _ = git::repo(&paths::root().join("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-06-10 13:43:34 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
repository = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2016-06-10 13:43:34 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 09:23:57 +00:00
|
|
|
[UPDATING] `[..]` index
|
2017-04-09 02:20:41 +00:00
|
|
|
error: 1 files in the working directory contain changes that were not yet \
|
|
|
|
committed into git:
|
2016-06-10 13:43:34 +00:00
|
|
|
|
|
|
|
bar
|
|
|
|
|
2019-12-11 14:31:26 +00:00
|
|
|
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-06-10 13:43:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-06-10 13:43:34 +00:00
|
|
|
fn publish_clean() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2016-06-10 13:43:34 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project().build();
|
2017-02-15 14:16:41 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let _ = repo(&paths::root().join("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-06-10 13:43:34 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
repository = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2016-06-10 13:43:34 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-12-30 04:46:15 +00:00
|
|
|
|
|
|
|
validate_upload_foo_clean();
|
2016-06-10 13:43:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-06-10 13:43:34 +00:00
|
|
|
fn publish_in_sub_repo() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2016-06-10 13:43:34 +00:00
|
|
|
|
2018-07-24 12:59:42 +00:00
|
|
|
let p = project().no_manifest().file("baz", "").build();
|
2017-02-15 14:16:41 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let _ = repo(&paths::root().join("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2016-06-10 13:43:34 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
repository = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/src/main.rs", "fn main() {}")
|
2016-06-10 13:43:34 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish")
|
2019-03-20 23:34:56 +00:00
|
|
|
.cwd("bar")
|
2018-08-28 09:20:03 +00:00
|
|
|
.arg("--index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-12-30 04:46:15 +00:00
|
|
|
|
|
|
|
validate_upload_foo_clean();
|
2016-06-10 13:43:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-06-10 13:43:34 +00:00
|
|
|
fn publish_when_ignored() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2016-06-10 13:43:34 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project().file("baz", "").build();
|
2017-02-15 14:16:41 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let _ = repo(&paths::root().join("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-06-10 13:43:34 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
repository = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2016-06-10 13:43:34 +00:00
|
|
|
.file(".gitignore", "baz")
|
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-12-30 04:46:15 +00:00
|
|
|
|
|
|
|
publish::validate_upload(
|
|
|
|
CLEAN_FOO_JSON,
|
|
|
|
"foo-0.0.1.crate",
|
|
|
|
&[
|
2019-06-10 19:38:51 +00:00
|
|
|
"Cargo.lock",
|
2018-12-30 04:46:15 +00:00
|
|
|
"Cargo.toml",
|
|
|
|
"Cargo.toml.orig",
|
|
|
|
"src/main.rs",
|
|
|
|
".gitignore",
|
|
|
|
".cargo_vcs_info.json",
|
|
|
|
],
|
|
|
|
);
|
2016-06-10 13:43:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-06-10 13:43:34 +00:00
|
|
|
fn ignore_when_crate_ignored() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2016-06-10 13:43:34 +00:00
|
|
|
|
2018-07-24 12:59:42 +00:00
|
|
|
let p = project().no_manifest().file("bar/baz", "").build();
|
2017-02-15 14:16:41 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let _ = repo(&paths::root().join("foo"))
|
2016-06-10 13:43:34 +00:00
|
|
|
.file(".gitignore", "bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.nocommit_file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2016-06-10 13:43:34 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
repository = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.nocommit_file("bar/src/main.rs", "fn main() {}");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish")
|
2019-03-20 23:34:56 +00:00
|
|
|
.cwd("bar")
|
2018-08-28 09:20:03 +00:00
|
|
|
.arg("--index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-12-30 04:46:15 +00:00
|
|
|
|
|
|
|
publish::validate_upload(
|
|
|
|
CLEAN_FOO_JSON,
|
|
|
|
"foo-0.0.1.crate",
|
2019-06-10 19:38:51 +00:00
|
|
|
&[
|
|
|
|
"Cargo.lock",
|
|
|
|
"Cargo.toml",
|
|
|
|
"Cargo.toml.orig",
|
|
|
|
"src/main.rs",
|
|
|
|
"baz",
|
|
|
|
],
|
2018-12-30 04:46:15 +00:00
|
|
|
);
|
2016-06-10 13:43:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-06-10 13:43:34 +00:00
|
|
|
fn new_crate_rejected() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2016-06-10 13:43:34 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project().file("baz", "").build();
|
2017-02-15 14:16:41 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let _ = repo(&paths::root().join("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.nocommit_file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-06-10 13:43:34 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
repository = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.nocommit_file("src/main.rs", "fn main() {}");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_status(101)
|
2018-12-29 01:47:50 +00:00
|
|
|
.with_stderr_contains(
|
|
|
|
"[ERROR] 3 files in the working directory contain \
|
|
|
|
changes that were not yet committed into git:",
|
|
|
|
)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-06-10 13:43:34 +00:00
|
|
|
}
|
2016-07-17 23:43:57 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-07-17 23:43:57 +00:00
|
|
|
fn dry_run() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2016-07-17 23:43:57 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-07-17 23:43:57 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-07-17 23:43:57 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish --dry-run --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 09:23:57 +00:00
|
|
|
[UPDATING] `[..]` index
|
2016-07-17 23:43:57 +00:00
|
|
|
[WARNING] manifest has no documentation, [..]
|
2016-09-01 00:04:29 +00:00
|
|
|
See [..]
|
2018-09-08 02:42:26 +00:00
|
|
|
[PACKAGING] foo v0.0.1 ([CWD])
|
|
|
|
[VERIFYING] foo v0.0.1 ([CWD])
|
2016-07-17 23:43:57 +00:00
|
|
|
[COMPILING] foo v0.0.1 [..]
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-09-08 02:42:26 +00:00
|
|
|
[UPLOADING] foo v0.0.1 ([CWD])
|
2016-07-17 23:43:57 +00:00
|
|
|
[WARNING] aborting upload due to dry run
|
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-07-17 23:43:57 +00:00
|
|
|
|
|
|
|
// Ensure the API request wasn't actually made
|
2019-01-11 23:56:46 +00:00
|
|
|
assert!(registry::api_path().join("api/v1/crates").exists());
|
|
|
|
assert!(!registry::api_path().join("api/v1/crates/new").exists());
|
2016-07-17 23:43:57 +00:00
|
|
|
}
|
2017-10-03 08:36:46 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-10-31 06:28:09 +00:00
|
|
|
fn registry_not_in_publish_list() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2017-10-03 08:36:46 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-10-03 08:36:46 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
publish = [
|
|
|
|
"test"
|
|
|
|
]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-10-31 06:28:09 +00:00
|
|
|
.build();
|
2017-10-03 08:36:46 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("publish")
|
|
|
|
.arg("--registry")
|
|
|
|
.arg("alternative")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2019-04-11 18:34:00 +00:00
|
|
|
[ERROR] `foo` cannot be published.
|
|
|
|
The registry `alternative` is not listed in the `publish` value in Cargo.toml.
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2017-10-03 08:36:46 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-10-03 08:36:46 +00:00
|
|
|
fn publish_empty_list() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2017-10-03 08:36:46 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-10-03 08:36:46 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
publish = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-10-31 06:28:09 +00:00
|
|
|
.build();
|
2017-10-03 08:36:46 +00:00
|
|
|
|
2019-02-11 23:16:13 +00:00
|
|
|
p.cargo("publish --registry alternative")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2019-04-11 18:34:00 +00:00
|
|
|
[ERROR] `foo` cannot be published.
|
|
|
|
The registry `alternative` is not listed in the `publish` value in Cargo.toml.
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2017-10-03 08:36:46 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-10-31 06:28:09 +00:00
|
|
|
fn publish_allowed_registry() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2017-10-03 08:36:46 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project().build();
|
2017-10-03 08:36:46 +00:00
|
|
|
|
2017-10-31 06:28:09 +00:00
|
|
|
let _ = repo(&paths::root().join("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-10-03 08:36:46 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
2018-12-30 04:46:15 +00:00
|
|
|
repository = "foo"
|
2017-10-31 06:28:09 +00:00
|
|
|
publish = ["alternative"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-10-03 08:36:46 +00:00
|
|
|
.build();
|
|
|
|
|
2019-02-11 23:16:13 +00:00
|
|
|
p.cargo("publish --registry alternative").run();
|
2018-12-30 04:46:15 +00:00
|
|
|
|
2019-01-11 23:56:46 +00:00
|
|
|
publish::validate_alt_upload(
|
|
|
|
CLEAN_FOO_JSON,
|
|
|
|
"foo-0.0.1.crate",
|
|
|
|
&[
|
2019-06-10 19:38:51 +00:00
|
|
|
"Cargo.lock",
|
2019-01-11 23:56:46 +00:00
|
|
|
"Cargo.toml",
|
|
|
|
"Cargo.toml.orig",
|
|
|
|
"src/main.rs",
|
|
|
|
".cargo_vcs_info.json",
|
|
|
|
],
|
|
|
|
);
|
2017-10-03 08:36:46 +00:00
|
|
|
}
|
2017-10-31 06:28:09 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-10-31 06:28:09 +00:00
|
|
|
fn block_publish_no_registry() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2017-10-31 06:28:09 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-10-31 06:28:09 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
publish = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-10-31 06:28:09 +00:00
|
|
|
.build();
|
|
|
|
|
2019-02-11 23:16:13 +00:00
|
|
|
p.cargo("publish --registry alternative")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2019-04-11 18:34:00 +00:00
|
|
|
[ERROR] `foo` cannot be published.
|
|
|
|
The registry `alternative` is not listed in the `publish` value in Cargo.toml.
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2017-10-31 06:28:09 +00:00
|
|
|
}
|
2018-12-26 13:48:25 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-11 18:34:00 +00:00
|
|
|
fn publish_with_crates_io_explicit() {
|
|
|
|
// Explicitly setting `crates-io` in the publish list.
|
|
|
|
registry::init();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
publish = ["crates-io"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("publish --registry alternative")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] `foo` cannot be published.
|
|
|
|
The registry `alternative` is not listed in the `publish` value in Cargo.toml.
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("publish").run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-12-26 13:48:25 +00:00
|
|
|
fn publish_with_select_features() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2018-12-26 13:48:25 +00:00
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
required = []
|
|
|
|
optional = []
|
|
|
|
"#,
|
2018-12-29 15:33:20 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-12-26 13:48:25 +00:00
|
|
|
"src/main.rs",
|
2019-01-09 16:41:03 +00:00
|
|
|
"#[cfg(not(feature = \"required\"))]
|
2018-12-26 13:48:25 +00:00
|
|
|
compile_error!(\"This crate requires `required` feature!\");
|
|
|
|
fn main() {}",
|
2019-01-09 16:41:03 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-12-26 13:48:25 +00:00
|
|
|
|
2019-01-09 16:41:03 +00:00
|
|
|
p.cargo("publish --features required --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2019-01-09 16:41:03 +00:00
|
|
|
.with_stderr_contains("[UPLOADING] foo v0.0.1 ([CWD])")
|
|
|
|
.run();
|
2018-12-26 13:48:25 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-12-26 13:48:25 +00:00
|
|
|
fn publish_with_all_features() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2018-12-26 13:48:25 +00:00
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
required = []
|
|
|
|
optional = []
|
|
|
|
"#,
|
2018-12-29 15:33:20 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-12-26 13:48:25 +00:00
|
|
|
"src/main.rs",
|
2019-01-09 16:41:03 +00:00
|
|
|
"#[cfg(not(feature = \"required\"))]
|
2018-12-26 13:48:25 +00:00
|
|
|
compile_error!(\"This crate requires `required` feature!\");
|
|
|
|
fn main() {}",
|
2019-01-09 16:41:03 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-12-26 13:48:25 +00:00
|
|
|
|
2019-01-09 16:41:03 +00:00
|
|
|
p.cargo("publish --all-features --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2019-01-09 16:41:03 +00:00
|
|
|
.with_stderr_contains("[UPLOADING] foo v0.0.1 ([CWD])")
|
|
|
|
.run();
|
2017-10-31 06:28:09 +00:00
|
|
|
}
|
2019-01-09 17:25:36 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-01-09 17:25:36 +00:00
|
|
|
fn publish_with_no_default_features() {
|
2019-01-11 23:56:46 +00:00
|
|
|
registry::init();
|
2019-01-09 17:25:36 +00:00
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["required"]
|
|
|
|
required = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"#[cfg(not(feature = \"required\"))]
|
|
|
|
compile_error!(\"This crate requires `required` feature!\");
|
|
|
|
fn main() {}",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("publish --no-default-features --index")
|
2019-01-11 23:56:46 +00:00
|
|
|
.arg(registry_url().to_string())
|
2019-01-09 17:25:36 +00:00
|
|
|
.with_stderr_contains("error: This crate requires `required` feature!")
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
2019-01-11 23:56:46 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-01-11 23:56:46 +00:00
|
|
|
fn publish_with_patch() {
|
|
|
|
Package::new("bar", "1.0.0").publish();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
[dependencies]
|
|
|
|
bar = "1.0"
|
|
|
|
[patch.crates-io]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
"#,
|
|
|
|
)
|
2019-01-10 06:38:13 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"extern crate bar;
|
|
|
|
fn main() {
|
|
|
|
bar::newfunc();
|
|
|
|
}",
|
|
|
|
)
|
2019-01-11 23:56:46 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "1.0.0"))
|
2019-01-10 06:38:13 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn newfunc() {}")
|
2019-01-11 23:56:46 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
// Check that it works with the patched crate.
|
|
|
|
p.cargo("build").run();
|
|
|
|
|
2019-01-10 06:38:13 +00:00
|
|
|
// Check that verify fails with patched crate which has new functionality.
|
2019-01-11 23:56:46 +00:00
|
|
|
p.cargo("publish --index")
|
|
|
|
.arg(registry_url().to_string())
|
2019-01-10 06:38:13 +00:00
|
|
|
.with_stderr_contains("[..]newfunc[..]")
|
2019-01-11 23:56:46 +00:00
|
|
|
.with_status(101)
|
|
|
|
.run();
|
2019-01-10 06:38:13 +00:00
|
|
|
|
|
|
|
// Remove the usage of new functionality and try again.
|
|
|
|
p.change_file("src/main.rs", "extern crate bar; pub fn main() {}");
|
|
|
|
|
|
|
|
p.cargo("publish --index")
|
|
|
|
.arg(registry_url().to_string())
|
|
|
|
.run();
|
|
|
|
|
|
|
|
// Note, use of `registry` in the deps here is an artifact that this
|
|
|
|
// publishes to a fake, local registry that is pretending to be crates.io.
|
|
|
|
// Normal publishes would set it to null.
|
|
|
|
publish::validate_upload(
|
|
|
|
r#"
|
|
|
|
{
|
|
|
|
"authors": [],
|
|
|
|
"badges": {},
|
|
|
|
"categories": [],
|
|
|
|
"deps": [
|
|
|
|
{
|
|
|
|
"default_features": true,
|
|
|
|
"features": [],
|
|
|
|
"kind": "normal",
|
|
|
|
"name": "bar",
|
|
|
|
"optional": false,
|
|
|
|
"registry": "https://github.com/rust-lang/crates.io-index",
|
|
|
|
"target": null,
|
|
|
|
"version_req": "^1.0"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"description": "foo",
|
|
|
|
"documentation": null,
|
|
|
|
"features": {},
|
|
|
|
"homepage": null,
|
|
|
|
"keywords": [],
|
|
|
|
"license": "MIT",
|
|
|
|
"license_file": null,
|
|
|
|
"links": null,
|
|
|
|
"name": "foo",
|
|
|
|
"readme": null,
|
|
|
|
"readme_file": null,
|
|
|
|
"repository": null,
|
|
|
|
"vers": "0.0.1"
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
"foo-0.0.1.crate",
|
2019-06-10 19:38:51 +00:00
|
|
|
&["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
|
2019-01-10 06:38:13 +00:00
|
|
|
);
|
2019-01-11 23:56:46 +00:00
|
|
|
}
|
2019-04-16 16:52:07 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-16 16:52:07 +00:00
|
|
|
fn publish_checks_for_token_before_verify() {
|
|
|
|
registry::init();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let credentials = paths::home().join(".cargo/credentials");
|
|
|
|
fs::remove_file(&credentials).unwrap();
|
|
|
|
|
|
|
|
// Assert upload token error before the package is verified
|
|
|
|
p.cargo("publish")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[ERROR] no upload token found, please run `cargo login`")
|
|
|
|
.with_stderr_does_not_contain("[VERIFYING] foo v0.0.1 ([CWD])")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
// Assert package verified successfully on dry run
|
|
|
|
p.cargo("publish --dry-run")
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[VERIFYING] foo v0.0.1 ([CWD])")
|
|
|
|
.run();
|
|
|
|
}
|
2019-08-12 01:58:52 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn publish_with_bad_source() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
|
|
|
[source.crates-io]
|
|
|
|
replace-with = 'local-registry'
|
|
|
|
|
|
|
|
[source.local-registry]
|
|
|
|
local-registry = 'registry'
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("publish")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] registry `[..]/foo/registry` does not support API commands.
|
|
|
|
Check for a source-replacement in .cargo/config.
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.change_file(
|
|
|
|
".cargo/config",
|
|
|
|
r#"
|
|
|
|
[source.crates-io]
|
|
|
|
replace-with = "vendored-sources"
|
|
|
|
|
|
|
|
[source.vendored-sources]
|
|
|
|
directory = "vendor"
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
p.cargo("publish")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] dir [..]/foo/vendor does not support API commands.
|
|
|
|
Check for a source-replacement in .cargo/config.
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2019-08-11 23:50:13 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn publish_git_with_version() {
|
|
|
|
// A dependency with both `git` and `version`.
|
|
|
|
Package::new("dep1", "1.0.1")
|
|
|
|
.file("src/lib.rs", "pub fn f() -> i32 {1}")
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
let git_project = git::new("dep1", |project| {
|
|
|
|
project
|
|
|
|
.file("Cargo.toml", &basic_manifest("dep1", "1.0.0"))
|
|
|
|
.file("src/lib.rs", "pub fn f() -> i32 {2}")
|
|
|
|
});
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
edition = "2018"
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
dep1 = {{version = "1.0", git="{}"}}
|
|
|
|
"#,
|
|
|
|
git_project.url()
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
pub fn main() {
|
|
|
|
println!("{}", dep1::f());
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("run").with_stdout("2").run();
|
|
|
|
p.cargo("publish --no-verify --index")
|
|
|
|
.arg(registry_url().to_string())
|
|
|
|
.run();
|
|
|
|
|
|
|
|
publish::validate_upload_with_contents(
|
|
|
|
r#"
|
|
|
|
{
|
|
|
|
"authors": [],
|
|
|
|
"badges": {},
|
|
|
|
"categories": [],
|
|
|
|
"deps": [
|
|
|
|
{
|
|
|
|
"default_features": true,
|
|
|
|
"features": [],
|
|
|
|
"kind": "normal",
|
|
|
|
"name": "dep1",
|
|
|
|
"optional": false,
|
|
|
|
"registry": "https://github.com/rust-lang/crates.io-index",
|
|
|
|
"target": null,
|
|
|
|
"version_req": "^1.0"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"description": "foo",
|
|
|
|
"documentation": null,
|
|
|
|
"features": {},
|
|
|
|
"homepage": null,
|
|
|
|
"keywords": [],
|
|
|
|
"license": "MIT",
|
|
|
|
"license_file": null,
|
|
|
|
"links": null,
|
|
|
|
"name": "foo",
|
|
|
|
"readme": null,
|
|
|
|
"readme_file": null,
|
|
|
|
"repository": null,
|
|
|
|
"vers": "0.1.0"
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
"foo-0.1.0.crate",
|
|
|
|
&["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
|
|
|
|
&[
|
|
|
|
(
|
|
|
|
"Cargo.toml",
|
|
|
|
// Check that only `version` is included in Cargo.toml.
|
|
|
|
"[..]\n\
|
|
|
|
[dependencies.dep1]\n\
|
|
|
|
version = \"1.0\"\n\
|
|
|
|
",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"Cargo.lock",
|
|
|
|
// The important check here is that it is 1.0.1 in the registry.
|
|
|
|
"[..]\n\
|
|
|
|
[[package]]\n\
|
|
|
|
name = \"foo\"\n\
|
|
|
|
version = \"0.1.0\"\n\
|
|
|
|
dependencies = [\n\
|
2019-11-08 23:48:04 +00:00
|
|
|
\x20\"dep1\",\n\
|
2019-08-11 23:50:13 +00:00
|
|
|
]\n\
|
|
|
|
[..]",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2019-09-05 21:56:21 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn publish_dev_dep_no_version() {
|
|
|
|
registry::init();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
repository = "foo"
|
|
|
|
|
|
|
|
[dev-dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("publish --no-verify --index")
|
|
|
|
.arg(registry_url().to_string())
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[UPDATING] [..]
|
|
|
|
[PACKAGING] foo v0.1.0 [..]
|
|
|
|
[UPLOADING] foo v0.1.0 [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
2019-09-11 00:06:32 +00:00
|
|
|
publish::validate_upload_with_contents(
|
2019-09-05 21:56:21 +00:00
|
|
|
r#"
|
|
|
|
{
|
|
|
|
"authors": [],
|
|
|
|
"badges": {},
|
|
|
|
"categories": [],
|
|
|
|
"deps": [],
|
|
|
|
"description": "foo",
|
|
|
|
"documentation": "foo",
|
|
|
|
"features": {},
|
|
|
|
"homepage": "foo",
|
|
|
|
"keywords": [],
|
|
|
|
"license": "MIT",
|
|
|
|
"license_file": null,
|
|
|
|
"links": null,
|
|
|
|
"name": "foo",
|
|
|
|
"readme": null,
|
|
|
|
"readme_file": null,
|
|
|
|
"repository": "foo",
|
|
|
|
"vers": "0.1.0"
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
"foo-0.1.0.crate",
|
|
|
|
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
|
2019-09-11 00:06:32 +00:00
|
|
|
&[(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"[..]
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
description = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
license = "MIT"
|
|
|
|
repository = "foo"
|
|
|
|
|
|
|
|
[dev-dependencies]
|
|
|
|
"#,
|
|
|
|
)],
|
2019-09-05 21:56:21 +00:00
|
|
|
);
|
|
|
|
}
|