2016-06-10 13:43:34 +00:00
|
|
|
#[macro_use]
|
2016-05-26 00:06:25 +00:00
|
|
|
extern crate cargotest;
|
|
|
|
extern crate flate2;
|
|
|
|
extern crate hamcrest;
|
|
|
|
extern crate tar;
|
|
|
|
extern crate url;
|
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
use std::io::prelude::*;
|
|
|
|
use std::fs::{self, File};
|
2016-01-20 17:07:47 +00:00
|
|
|
use std::io::SeekFrom;
|
2015-02-27 01:04:25 +00:00
|
|
|
use std::path::PathBuf;
|
2014-09-09 14:23:09 +00:00
|
|
|
|
2016-05-26 00:06:25 +00:00
|
|
|
use cargotest::support::git::repo;
|
|
|
|
use cargotest::support::paths;
|
|
|
|
use cargotest::support::{project, execs};
|
2015-02-27 01:04:25 +00:00
|
|
|
use flate2::read::GzDecoder;
|
2016-05-26 00:06:25 +00:00
|
|
|
use hamcrest::assert_that;
|
2014-09-09 14:23:09 +00:00
|
|
|
use tar::Archive;
|
|
|
|
use url::Url;
|
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
fn registry_path() -> PathBuf { paths::root().join("registry") }
|
|
|
|
fn registry() -> Url { Url::from_file_path(&*registry_path()).ok().unwrap() }
|
|
|
|
fn upload_path() -> PathBuf { paths::root().join("upload") }
|
|
|
|
fn upload() -> Url { Url::from_file_path(&*upload_path()).ok().unwrap() }
|
2014-09-09 14:23:09 +00:00
|
|
|
|
|
|
|
fn setup() {
|
|
|
|
let config = paths::root().join(".cargo/config");
|
2016-02-03 18:54:07 +00:00
|
|
|
t!(fs::create_dir_all(config.parent().unwrap()));
|
|
|
|
t!(t!(File::create(&config)).write_all(&format!(r#"
|
2014-09-09 14:23:09 +00:00
|
|
|
[registry]
|
|
|
|
token = "api-token"
|
2016-02-03 18:54:07 +00:00
|
|
|
"#).as_bytes()));
|
|
|
|
t!(fs::create_dir_all(&upload_path().join("api/v1/crates")));
|
2014-09-09 14:23:09 +00:00
|
|
|
|
|
|
|
repo(®istry_path())
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("config.json", &format!(r#"{{
|
2014-09-27 04:14:46 +00:00
|
|
|
"dl": "{0}",
|
|
|
|
"api": "{0}"
|
2014-09-09 14:23:09 +00:00
|
|
|
}}"#, upload()))
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn simple() {
|
|
|
|
setup();
|
|
|
|
|
2014-09-09 14:23:09 +00:00
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[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
|
|
|
"#)
|
|
|
|
.file("src/main.rs", "fn main() {}");
|
|
|
|
|
2016-02-03 18:54:07 +00:00
|
|
|
assert_that(p.cargo_process("publish").arg("--no-verify")
|
|
|
|
.arg("--host").arg(registry().to_string()),
|
2016-05-14 21:44:18 +00:00
|
|
|
execs().with_status(0).with_stderr(&format!("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[UPDATING] registry `{reg}`
|
2016-05-20 14:00:15 +00:00
|
|
|
[WARNING] manifest has no documentation, [..]
|
2016-09-01 00:04:29 +00:00
|
|
|
See [..]
|
2016-05-12 15:23:53 +00:00
|
|
|
[PACKAGING] foo v0.0.1 ({dir})
|
|
|
|
[UPLOADING] foo v0.0.1 ({dir})
|
2014-09-09 14:23:09 +00:00
|
|
|
",
|
|
|
|
dir = p.url(),
|
2015-03-26 18:17:44 +00:00
|
|
|
reg = registry())));
|
2014-09-09 14:23:09 +00:00
|
|
|
|
2014-09-27 04:14:46 +00:00
|
|
|
let mut f = File::open(&upload_path().join("api/v1/crates/new")).unwrap();
|
|
|
|
// Skip the metadata payload and the size of the tarball
|
2015-02-27 01:04:25 +00:00
|
|
|
let mut sz = [0; 4];
|
2015-04-02 18:12:21 +00:00
|
|
|
assert_eq!(f.read(&mut sz).unwrap(), 4);
|
2015-02-27 01:04:25 +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();
|
2014-09-27 04:14:46 +00:00
|
|
|
|
|
|
|
// Verify the tarball
|
|
|
|
let mut rdr = GzDecoder::new(f).unwrap();
|
2015-03-22 23:58:11 +00:00
|
|
|
assert_eq!(rdr.header().filename().unwrap(), "foo-0.0.1.crate".as_bytes());
|
2015-02-27 01:04:25 +00:00
|
|
|
let mut contents = Vec::new();
|
|
|
|
rdr.read_to_end(&mut contents).unwrap();
|
2016-01-20 17:07:47 +00:00
|
|
|
let mut ar = Archive::new(&contents[..]);
|
|
|
|
for file in ar.entries().unwrap() {
|
2014-09-09 14:23:09 +00:00
|
|
|
let file = file.unwrap();
|
2015-08-03 17:04:22 +00:00
|
|
|
let fname = file.header().path_bytes();
|
|
|
|
let fname = &*fname;
|
2014-11-19 06:29:19 +00:00
|
|
|
assert!(fname == b"foo-0.0.1/Cargo.toml" ||
|
|
|
|
fname == b"foo-0.0.1/src/main.rs",
|
2015-08-03 17:04:22 +00:00
|
|
|
"unexpected filename: {:?}", file.header().path());
|
2014-09-09 14:23:09 +00:00
|
|
|
}
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn git_deps() {
|
|
|
|
setup();
|
2014-09-09 14:23:09 +00:00
|
|
|
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[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"
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", "fn main() {}");
|
|
|
|
|
2016-02-03 18:54:07 +00:00
|
|
|
assert_that(p.cargo_process("publish").arg("-v").arg("--no-verify")
|
|
|
|
.arg("--host").arg(registry().to_string()),
|
2016-05-12 17:06:36 +00:00
|
|
|
execs().with_status(101).with_stderr("\
|
2016-05-20 14:00:15 +00:00
|
|
|
[UPDATING] registry [..]
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] all dependencies must come from the same source.
|
2014-09-27 04:14:46 +00:00
|
|
|
dependency `foo` comes from git://path/to/nowhere instead
|
2016-05-12 17:06:36 +00:00
|
|
|
"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn path_dependency_no_version() {
|
|
|
|
setup();
|
2014-09-27 04:14:46 +00:00
|
|
|
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[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"
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("bar/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("bar/src/lib.rs", "");
|
2014-09-09 14:23:09 +00:00
|
|
|
|
2016-02-03 18:54:07 +00:00
|
|
|
assert_that(p.cargo_process("publish")
|
|
|
|
.arg("--host").arg(registry().to_string()),
|
2016-05-12 17:06:36 +00:00
|
|
|
execs().with_status(101).with_stderr("\
|
2016-05-20 14:00:15 +00:00
|
|
|
[UPDATING] registry [..]
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] all path dependencies must have a version specified when publishing.
|
2014-09-27 04:14:46 +00:00
|
|
|
dependency `bar` does not specify a version
|
2016-05-12 17:06:36 +00:00
|
|
|
"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unpublishable_crate() {
|
|
|
|
setup();
|
2016-01-23 21:16:30 +00:00
|
|
|
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
publish = false
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", "fn main() {}");
|
|
|
|
|
2016-02-03 18:54:07 +00:00
|
|
|
assert_that(p.cargo_process("publish")
|
|
|
|
.arg("--host").arg(registry().to_string()),
|
2016-05-12 17:06:36 +00:00
|
|
|
execs().with_status(101).with_stderr("\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] some crates cannot be published.
|
2016-01-23 21:16:30 +00:00
|
|
|
`foo` is marked as unpublishable
|
2016-05-12 17:06:36 +00:00
|
|
|
"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-06-10 13:43:34 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dont_publish_dirty() {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
repo(&paths::root().join("foo"))
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
repository = "foo"
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let p = project("foo");
|
|
|
|
t!(File::create(p.root().join("bar")));
|
2016-02-03 18:54:07 +00:00
|
|
|
assert_that(p.cargo("publish")
|
|
|
|
.arg("--host").arg(registry().to_string()),
|
2016-06-10 13:43:34 +00:00
|
|
|
execs().with_status(101).with_stderr("\
|
|
|
|
[UPDATING] registry `[..]`
|
|
|
|
error: 1 dirty files found in the working directory:
|
|
|
|
|
|
|
|
bar
|
|
|
|
|
2016-09-03 01:05:26 +00:00
|
|
|
to proceed despite this, pass the `--allow-dirty` flag
|
2016-06-10 13:43:34 +00:00
|
|
|
"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn publish_clean() {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
repo(&paths::root().join("foo"))
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
repository = "foo"
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let p = project("foo");
|
2016-02-03 18:54:07 +00:00
|
|
|
assert_that(p.cargo("publish")
|
|
|
|
.arg("--host").arg(registry().to_string()),
|
2016-06-10 13:43:34 +00:00
|
|
|
execs().with_status(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn publish_in_sub_repo() {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
repo(&paths::root().join("foo"))
|
|
|
|
.file("bar/Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
repository = "foo"
|
|
|
|
"#)
|
|
|
|
.file("bar/src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let p = project("foo");
|
|
|
|
t!(File::create(p.root().join("baz")));
|
2016-02-03 18:54:07 +00:00
|
|
|
assert_that(p.cargo("publish").cwd(p.root().join("bar"))
|
|
|
|
.arg("--host").arg(registry().to_string()),
|
2016-06-10 13:43:34 +00:00
|
|
|
execs().with_status(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn publish_when_ignored() {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
repo(&paths::root().join("foo"))
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
repository = "foo"
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(".gitignore", "baz")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let p = project("foo");
|
|
|
|
t!(File::create(p.root().join("baz")));
|
2016-02-03 18:54:07 +00:00
|
|
|
assert_that(p.cargo("publish")
|
|
|
|
.arg("--host").arg(registry().to_string()),
|
2016-06-10 13:43:34 +00:00
|
|
|
execs().with_status(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ignore_when_crate_ignored() {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
repo(&paths::root().join("foo"))
|
|
|
|
.file(".gitignore", "bar")
|
|
|
|
.nocommit_file("bar/Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
repository = "foo"
|
|
|
|
"#)
|
|
|
|
.nocommit_file("bar/src/main.rs", "fn main() {}");
|
|
|
|
let p = project("foo");
|
|
|
|
t!(File::create(p.root().join("bar/baz")));
|
2016-02-03 18:54:07 +00:00
|
|
|
assert_that(p.cargo("publish").cwd(p.root().join("bar"))
|
|
|
|
.arg("--host").arg(registry().to_string()),
|
2016-06-10 13:43:34 +00:00
|
|
|
execs().with_status(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn new_crate_rejected() {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
repo(&paths::root().join("foo"))
|
|
|
|
.nocommit_file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
documentation = "foo"
|
|
|
|
homepage = "foo"
|
|
|
|
repository = "foo"
|
|
|
|
"#)
|
|
|
|
.nocommit_file("src/main.rs", "fn main() {}");
|
|
|
|
let p = project("foo");
|
|
|
|
t!(File::create(p.root().join("baz")));
|
2016-02-03 18:54:07 +00:00
|
|
|
assert_that(p.cargo("publish")
|
|
|
|
.arg("--host").arg(registry().to_string()),
|
2016-06-10 13:43:34 +00:00
|
|
|
execs().with_status(101));
|
|
|
|
}
|
2016-07-17 23:43:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dry_run() {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", "fn main() {}");
|
|
|
|
|
2016-02-03 18:54:07 +00:00
|
|
|
assert_that(p.cargo_process("publish").arg("--dry-run")
|
|
|
|
.arg("--host").arg(registry().to_string()),
|
2016-07-17 23:43:57 +00:00
|
|
|
execs().with_status(0).with_stderr(&format!("\
|
2016-07-05 17:28:51 +00:00
|
|
|
[UPDATING] registry `[..]`
|
2016-07-17 23:43:57 +00:00
|
|
|
[WARNING] manifest has no documentation, [..]
|
2016-09-01 00:04:29 +00:00
|
|
|
See [..]
|
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 [..]
|
2016-07-25 23:30:03 +00:00
|
|
|
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
|
2016-07-17 23:43:57 +00:00
|
|
|
[UPLOADING] foo v0.0.1 ({dir})
|
|
|
|
[WARNING] aborting upload due to dry run
|
|
|
|
",
|
2016-07-05 17:28:51 +00:00
|
|
|
dir = p.url())));
|
2016-07-17 23:43:57 +00:00
|
|
|
|
|
|
|
// Ensure the API request wasn't actually made
|
|
|
|
assert!(!upload_path().join("api/v1/crates/new").exists());
|
|
|
|
}
|