cargo/tests/testsuite/publish.rs

875 lines
22 KiB
Rust
Raw Normal View History

use std::io::prelude::*;
use std::fs::{self, File};
use std::io::SeekFrom;
2014-09-09 14:23:09 +00:00
use support::ChannelChanger;
use support::git::repo;
use support::paths;
use support::{execs, project, publish};
use flate2::read::GzDecoder;
use support::hamcrest::assert_that;
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
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.arg("--no-verify")
.arg("--index")
.arg(publish::registry().to_string()),
execs().with_status(0).with_stderr(&format!(
"\
[UPDATING] registry `{reg}`
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ({dir})
[UPLOADING] foo v0.0.1 ({dir})
",
2018-03-14 15:17:44 +00:00
dir = p.url(),
reg = publish::registry()
)),
);
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);
2018-03-14 15:17:44 +00:00
let sz = ((sz[0] as u32) << 0) | ((sz[1] as u32) << 8) | ((sz[2] as u32) << 16)
| ((sz[3] as u32) << 24);
f.seek(SeekFrom::Current(sz as i64 + 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"
|| 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()
2018-03-14 15:17:44 +00:00
.write_all(
br#"
token = "api-token"
2018-03-14 15:17:44 +00:00
"#,
)
.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
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.arg("--no-verify")
.arg("--index")
.arg(publish::registry().to_string()),
execs().with_status(0).with_stderr(&format!(
"\
[UPDATING] registry `{reg}`
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ({dir})
[UPLOADING] foo v0.0.1 ({dir})
",
2018-03-14 15:17:44 +00:00
dir = p.url(),
reg = publish::registry()
)),
);
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);
2018-03-14 15:17:44 +00:00
let sz = ((sz[0] as u32) << 0) | ((sz[1] as u32) << 8) | ((sz[2] as u32) << 16)
| ((sz[3] as u32) << 24);
f.seek(SeekFrom::Current(sz as i64 + 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"
|| 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
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
2014-09-09 14:23:09 +00:00
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.arg("--no-verify")
.arg("--host")
.arg(publish::registry().to_string()),
execs().with_status(0).with_stderr(&format!(
"\
[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] registry `{reg}`
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ({dir})
[UPLOADING] foo v0.0.1 ({dir})
",
2018-03-14 15:17:44 +00:00
dir = p.url(),
reg = publish::registry()
)),
);
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);
2018-03-14 15:17:44 +00:00
let sz = ((sz[0] as u32) << 0) | ((sz[1] as u32) << 8) | ((sz[2] as u32) << 16)
| ((sz[3] as u32) << 24);
f.seek(SeekFrom::Current(sz as i64 + 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(),
"foo-0.0.1.crate".as_bytes()
);
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"
|| 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
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.arg("--no-verify")
.arg("--index")
.arg(publish::registry().to_string())
.arg("--host")
.arg(publish::registry().to_string()),
execs().with_status(0).with_stderr(&format!(
"\
[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] registry `{reg}`
2016-05-20 14:00:15 +00:00
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ({dir})
[UPLOADING] foo v0.0.1 ({dir})
2014-09-09 14:23:09 +00:00
",
2018-03-14 15:17:44 +00:00
dir = p.url(),
reg = publish::registry()
)),
);
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);
2018-03-14 15:17:44 +00:00
let sz = ((sz[0] as u32) << 0) | ((sz[1] as u32) << 8) | ((sz[2] as u32) << 16)
| ((sz[3] as u32) << 24);
f.seek(SeekFrom::Current(sz as i64 + 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(),
"foo-0.0.1.crate".as_bytes()
);
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"
|| 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
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
2014-09-09 14:23:09 +00:00
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.arg("-v")
.arg("--no-verify")
.arg("--index")
.arg(publish::registry().to_string()),
execs().with_status(101).with_stderr(
"\
2016-05-20 14:00:15 +00:00
[UPDATING] registry [..]
[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
",
),
);
}
#[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
"#,
)
.file("src/main.rs", "fn main() {}")
2018-03-14 15:17:44 +00:00
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
2018-03-14 15:17:44 +00:00
"#,
)
.file("bar/src/lib.rs", "")
.build();
2014-09-09 14:23:09 +00:00
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.arg("--index")
.arg(publish::registry().to_string()),
execs().with_status(101).with_stderr(
"\
2016-05-20 14:00:15 +00:00
[UPDATING] registry [..]
[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
",
),
);
}
#[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
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.arg("--index")
.arg(publish::registry().to_string()),
execs().with_status(101).with_stderr(
"\
[ERROR] some crates cannot be published.
`foo` is marked as unpublishable
2018-03-14 15:17:44 +00:00
",
),
);
}
#[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
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.arg("--index")
.arg(publish::registry().to_string()),
execs().with_status(101).with_stderr(
"\
[UPDATING] registry `[..]`
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
",
),
);
}
#[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
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.arg("--index")
.arg(publish::registry().to_string()),
execs().with_status(0),
);
}
#[test]
fn publish_in_sub_repo() {
publish::setup();
let p = project().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
"#,
)
.file("bar/src/main.rs", "fn main() {}")
.build();
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.cwd(p.root().join("bar"))
.arg("--index")
.arg(publish::registry().to_string()),
execs().with_status(0),
);
}
#[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
"#,
)
.file("src/main.rs", "fn main() {}")
.file(".gitignore", "baz")
.build();
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.arg("--index")
.arg(publish::registry().to_string()),
execs().with_status(0),
);
}
#[test]
fn ignore_when_crate_ignored() {
publish::setup();
let p = project().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
"#,
)
.nocommit_file("bar/src/main.rs", "fn main() {}");
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.cwd(p.root().join("bar"))
.arg("--index")
.arg(publish::registry().to_string()),
execs().with_status(0),
);
}
#[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
"#,
)
.nocommit_file("src/main.rs", "fn main() {}");
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.arg("--index")
.arg(publish::registry().to_string()),
execs().with_status(101),
);
}
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
"#,
)
.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
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.arg("--dry-run")
.arg("--index")
.arg(publish::registry().to_string()),
execs().with_status(0).with_stderr(&format!(
"\
2016-07-05 17:28:51 +00:00
[UPDATING] registry `[..]`
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 [..]
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
[PACKAGING] foo v0.0.1 ({dir})
[VERIFYING] foo v0.0.1 ({dir})
[COMPILING] foo v0.0.1 [..]
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
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
[UPLOADING] foo v0.0.1 ({dir})
[WARNING] aborting upload due to dry run
",
2018-03-14 15:17:44 +00:00
dir = p.url()
)),
);
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
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("publish")
.masquerade_as_nightly_cargo()
.arg("--registry")
.arg("alternative")
.arg("-Zunstable-options"),
execs().with_status(101).with_stderr(
"\
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
",
),
);
}
#[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
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
2018-03-14 15:17:44 +00:00
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
2018-03-14 15:17:44 +00:00
",
),
);
}
#[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
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
2018-03-14 15:17:44 +00:00
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
2018-03-14 15:17:44 +00:00
",
),
);
}
#[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
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
2018-03-14 15:17:44 +00:00
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()
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
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
2018-03-14 15:17:44 +00:00
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
2018-03-14 15:17:44 +00:00
",
),
);
}