cargo/tests/testsuite/publish.rs

821 lines
20 KiB
Rust
Raw Normal View History

use std::fs::{self, File};
use std::io::prelude::*;
use std::io::SeekFrom;
2014-09-09 14:23:09 +00:00
2018-12-06 19:17:36 +00:00
use crate::support::git::repo;
use crate::support::paths;
use crate::support::{basic_manifest, project, publish};
2018-12-08 11:19:47 +00:00
use flate2::read::GzDecoder;
2014-09-09 14:23:09 +00:00
use tar::Archive;
#[test]
fn simple() {
publish::setup();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {}")
.build();
p.cargo("publish --no-verify --index")
.arg(publish::registry().to_string())
.with_stderr(&format!(
2018-03-14 15:17:44 +00:00
"\
[UPDATING] `{reg}` index
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ([CWD])
[UPLOADING] foo v0.0.1 ([CWD])
",
reg = publish::registry_path().to_str().unwrap()
2018-12-08 11:19:47 +00:00
))
.run();
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
// Skip the metadata payload and the size of the tarball
let mut sz = [0; 4];
assert_eq!(f.read(&mut sz).unwrap(), 4);
let sz = (u32::from(sz[0]) << 0)
| (u32::from(sz[1]) << 8)
| (u32::from(sz[2]) << 16)
| (u32::from(sz[3]) << 24);
f.seek(SeekFrom::Current(i64::from(sz) + 4)).unwrap();
// Verify the tarball
let mut rdr = GzDecoder::new(f);
2018-03-14 15:17:44 +00:00
assert_eq!(
rdr.header().unwrap().filename().unwrap(),
b"foo-0.0.1.crate"
);
let mut contents = Vec::new();
rdr.read_to_end(&mut contents).unwrap();
let mut ar = Archive::new(&contents[..]);
for file in ar.entries().unwrap() {
let file = file.unwrap();
let fname = file.header().path_bytes();
let fname = &*fname;
2018-03-14 15:17:44 +00:00
assert!(
fname == b"foo-0.0.1/Cargo.toml"
|| fname == b"foo-0.0.1/Cargo.toml.orig"
2018-03-14 15:17:44 +00:00
|| fname == b"foo-0.0.1/src/main.rs",
"unexpected filename: {:?}",
file.header().path()
);
}
}
#[test]
fn old_token_location() {
publish::setup();
// publish::setup puts a token in this file.
fs::remove_file(paths::root().join(".cargo/config")).unwrap();
let credentials = paths::root().join("home/.cargo/credentials");
File::create(credentials)
.unwrap()
.write_all(br#"token = "api-token""#)
.unwrap();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {}")
.build();
p.cargo("publish --no-verify --index")
.arg(publish::registry().to_string())
.with_stderr(&format!(
2018-03-14 15:17:44 +00:00
"\
[UPDATING] `{reg}` index
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ([CWD])
[UPLOADING] foo v0.0.1 ([CWD])
",
reg = publish::registry_path().to_str().unwrap()
2018-12-08 11:19:47 +00:00
))
.run();
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
// Skip the metadata payload and the size of the tarball
let mut sz = [0; 4];
assert_eq!(f.read(&mut sz).unwrap(), 4);
let sz = (u32::from(sz[0]) << 0)
| (u32::from(sz[1]) << 8)
| (u32::from(sz[2]) << 16)
| (u32::from(sz[3]) << 24);
f.seek(SeekFrom::Current(i64::from(sz) + 4)).unwrap();
// Verify the tarball
let mut rdr = GzDecoder::new(f);
2018-03-14 15:17:44 +00:00
assert_eq!(
rdr.header().unwrap().filename().unwrap(),
b"foo-0.0.1.crate"
);
let mut contents = Vec::new();
rdr.read_to_end(&mut contents).unwrap();
let mut ar = Archive::new(&contents[..]);
for file in ar.entries().unwrap() {
let file = file.unwrap();
let fname = file.header().path_bytes();
let fname = &*fname;
2018-03-14 15:17:44 +00:00
assert!(
fname == b"foo-0.0.1/Cargo.toml"
|| fname == b"foo-0.0.1/Cargo.toml.orig"
2018-03-14 15:17:44 +00:00
|| fname == b"foo-0.0.1/src/main.rs",
"unexpected filename: {:?}",
file.header().path()
);
}
}
// TODO: Deprecated
// remove once it has been decided --host can be removed
#[test]
fn simple_with_host() {
publish::setup();
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 = []
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() {}")
.build();
2014-09-09 14:23:09 +00:00
p.cargo("publish --no-verify --host")
.arg(publish::registry().to_string())
.with_stderr(&format!(
2018-03-14 15:17:44 +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.
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.
[UPDATING] `{reg}` index
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ([CWD])
[UPLOADING] foo v0.0.1 ([CWD])
",
reg = publish::registry_path().to_str().unwrap()
2018-12-08 11:19:47 +00:00
))
.run();
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
// Skip the metadata payload and the size of the tarball
let mut sz = [0; 4];
assert_eq!(f.read(&mut sz).unwrap(), 4);
let sz = (u32::from(sz[0]) << 0)
| (u32::from(sz[1]) << 8)
| (u32::from(sz[2]) << 16)
| (u32::from(sz[3]) << 24);
f.seek(SeekFrom::Current(i64::from(sz) + 4)).unwrap();
// Verify the tarball
let mut rdr = GzDecoder::new(f);
2018-03-14 15:17:44 +00:00
assert_eq!(
rdr.header().unwrap().filename().unwrap(),
b"foo-0.0.1.crate"
2018-03-14 15:17:44 +00:00
);
let mut contents = Vec::new();
rdr.read_to_end(&mut contents).unwrap();
let mut ar = Archive::new(&contents[..]);
for file in ar.entries().unwrap() {
let file = file.unwrap();
let fname = file.header().path_bytes();
let fname = &*fname;
2018-03-14 15:17:44 +00:00
assert!(
fname == b"foo-0.0.1/Cargo.toml"
|| fname == b"foo-0.0.1/Cargo.toml.orig"
2018-03-14 15:17:44 +00:00
|| fname == b"foo-0.0.1/src/main.rs",
"unexpected filename: {:?}",
file.header().path()
);
}
}
// TODO: Deprecated
// remove once it has been decided --host can be removed
#[test]
fn simple_with_index_and_host() {
publish::setup();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {}")
.build();
p.cargo("publish --no-verify --index")
.arg(publish::registry().to_string())
.arg("--host")
.arg(publish::registry().to_string())
.with_stderr(&format!(
2018-03-14 15:17:44 +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.
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.
[UPDATING] `{reg}` index
2016-05-20 14:00:15 +00:00
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ([CWD])
[UPLOADING] foo v0.0.1 ([CWD])
2014-09-09 14:23:09 +00:00
",
reg = publish::registry_path().to_str().unwrap()
2018-12-08 11:19:47 +00:00
))
.run();
2014-09-09 14:23:09 +00:00
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
// Skip the metadata payload and the size of the tarball
let mut sz = [0; 4];
assert_eq!(f.read(&mut sz).unwrap(), 4);
let sz = (u32::from(sz[0]) << 0)
| (u32::from(sz[1]) << 8)
| (u32::from(sz[2]) << 16)
| (u32::from(sz[3]) << 24);
f.seek(SeekFrom::Current(i64::from(sz) + 4)).unwrap();
// Verify the tarball
let mut rdr = GzDecoder::new(f);
2018-03-14 15:17:44 +00:00
assert_eq!(
rdr.header().unwrap().filename().unwrap(),
b"foo-0.0.1.crate"
2018-03-14 15:17:44 +00:00
);
let mut contents = Vec::new();
rdr.read_to_end(&mut contents).unwrap();
let mut ar = Archive::new(&contents[..]);
for file in ar.entries().unwrap() {
2014-09-09 14:23:09 +00:00
let file = file.unwrap();
let fname = file.header().path_bytes();
let fname = &*fname;
2018-03-14 15:17:44 +00:00
assert!(
fname == b"foo-0.0.1/Cargo.toml"
|| fname == b"foo-0.0.1/Cargo.toml.orig"
2018-03-14 15:17:44 +00:00
|| fname == b"foo-0.0.1/src/main.rs",
"unexpected filename: {:?}",
file.header().path()
);
2014-09-09 14:23:09 +00:00
}
}
#[test]
fn git_deps() {
publish::setup();
2014-09-09 14:23:09 +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 = []
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() {}")
.build();
2014-09-09 14:23:09 +00:00
p.cargo("publish -v --no-verify --index")
.arg(publish::registry().to_string())
.with_status(101)
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[UPDATING] [..] index
[ERROR] crates cannot be published to crates.io with dependencies sourced from \
a repository\neither publish `foo` as its own crate on crates.io and \
specify a crates.io version as a dependency or pull it into this \
repository and specify it with a path and version\n\
(crate `foo` has repository path `git://path/to/nowhere`)\
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[test]
fn path_dependency_no_version() {
publish::setup();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
[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"))
.file("bar/src/lib.rs", "")
.build();
2014-09-09 14:23:09 +00:00
p.cargo("publish --index")
.arg(publish::registry().to_string())
.with_status(101)
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[UPDATING] [..] index
[ERROR] all path dependencies must have a version specified when publishing.
dependency `bar` does not specify a version
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[test]
fn unpublishable_crate() {
publish::setup();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {}")
.build();
p.cargo("publish --index")
.arg(publish::registry().to_string())
.with_status(101)
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[ERROR] some crates cannot be published.
`foo` is marked as unpublishable
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[test]
fn dont_publish_dirty() {
publish::setup();
let p = project().file("bar", "").build();
let _ = repo(&paths::root().join("foo"))
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {}")
.build();
p.cargo("publish --index")
.arg(publish::registry().to_string())
.with_status(101)
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[UPDATING] `[..]` index
error: 1 files in the working directory contain changes that were not yet \
committed into git:
bar
to proceed despite this, pass the `--allow-dirty` flag
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[test]
fn publish_clean() {
publish::setup();
let p = project().build();
let _ = repo(&paths::root().join("foo"))
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {}")
.build();
p.cargo("publish --index")
.arg(publish::registry().to_string())
.run();
}
#[test]
fn publish_in_sub_repo() {
publish::setup();
let p = project().no_manifest().file("baz", "").build();
let _ = repo(&paths::root().join("foo"))
2018-03-14 15:17:44 +00:00
.file(
"bar/Cargo.toml",
r#"
[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() {}")
.build();
p.cargo("publish")
.cwd(p.root().join("bar"))
.arg("--index")
.arg(publish::registry().to_string())
.run();
}
#[test]
fn publish_when_ignored() {
publish::setup();
let p = project().file("baz", "").build();
let _ = repo(&paths::root().join("foo"))
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {}")
.file(".gitignore", "baz")
.build();
p.cargo("publish --index")
.arg(publish::registry().to_string())
.run();
}
#[test]
fn ignore_when_crate_ignored() {
publish::setup();
let p = project().no_manifest().file("bar/baz", "").build();
let _ = repo(&paths::root().join("foo"))
.file(".gitignore", "bar")
2018-03-14 15:17:44 +00:00
.nocommit_file(
"bar/Cargo.toml",
r#"
[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() {}");
p.cargo("publish")
.cwd(p.root().join("bar"))
.arg("--index")
.arg(publish::registry().to_string())
.run();
}
#[test]
fn new_crate_rejected() {
publish::setup();
let p = project().file("baz", "").build();
let _ = repo(&paths::root().join("foo"))
2018-03-14 15:17:44 +00:00
.nocommit_file(
"Cargo.toml",
r#"
[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() {}");
p.cargo("publish --index")
.arg(publish::registry().to_string())
.with_status(101)
.run();
}
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
#[test]
fn dry_run() {
publish::setup();
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
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() {}")
.build();
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
p.cargo("publish --dry-run --index")
.arg(publish::registry().to_string())
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[UPDATING] `[..]` index
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ([CWD])
[VERIFYING] foo v0.0.1 ([CWD])
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
[COMPILING] foo v0.0.1 [..]
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[UPLOADING] foo v0.0.1 ([CWD])
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
[WARNING] aborting upload due to dry run
",
2018-12-08 11:19:47 +00:00
)
.run();
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
// Ensure the API request wasn't actually made
assert!(!publish::upload_path().join("api/v1/crates/new").exists());
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
}
#[test]
fn block_publish_feature_not_enabled() {
publish::setup();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {}")
.build();
p.cargo("publish --registry alternative -Zunstable-options")
.masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
error: failed to parse manifest at `[..]`
Caused by:
the `publish` manifest key is unstable for anything other than a value of true or false
Caused by:
feature `alternative-registries` is required
consider adding `cargo-features = [\"alternative-registries\"]` to the manifest
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[test]
fn registry_not_in_publish_list() {
publish::setup();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
cargo-features = ["alternative-registries"]
[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() {}")
.build();
p.cargo("publish")
.masquerade_as_nightly_cargo()
.arg("--registry")
.arg("alternative")
.arg("-Zunstable-options")
.with_status(101)
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[ERROR] some crates cannot be published.
`foo` is marked as unpublishable
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[test]
fn publish_empty_list() {
publish::setup();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
cargo-features = ["alternative-registries"]
[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() {}")
.build();
p.cargo("publish --registry alternative -Zunstable-options")
.masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[ERROR] some crates cannot be published.
`foo` is marked as unpublishable
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[test]
fn publish_allowed_registry() {
publish::setup();
let p = project().build();
let _ = repo(&paths::root().join("foo"))
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
cargo-features = ["alternative-registries"]
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
documentation = "foo"
homepage = "foo"
publish = ["alternative"]
2018-03-14 15:17:44 +00:00
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("publish --registry alternative -Zunstable-options")
.masquerade_as_nightly_cargo()
.run();
}
#[test]
fn block_publish_no_registry() {
publish::setup();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
cargo-features = ["alternative-registries"]
[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() {}")
.build();
p.cargo("publish --registry alternative -Zunstable-options")
.masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[ERROR] some crates cannot be published.
`foo` is marked as unpublishable
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}