2015-02-27 01:04:25 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Cursor;
|
|
|
|
use std::io::prelude::*;
|
2014-09-09 02:38:16 +00:00
|
|
|
|
2014-09-09 14:23:09 +00:00
|
|
|
use tar::Archive;
|
2015-02-27 01:04:25 +00:00
|
|
|
use flate2::read::GzDecoder;
|
2014-11-21 20:31:00 +00:00
|
|
|
use cargo::util::process;
|
2014-09-09 14:23:09 +00:00
|
|
|
|
2014-12-21 23:19:44 +00:00
|
|
|
use support::{project, execs, cargo_dir, paths, git};
|
2014-11-21 20:31:00 +00:00
|
|
|
use support::{PACKAGING, VERIFYING, COMPILING, ARCHIVING};
|
2014-07-18 15:40:45 +00:00
|
|
|
use hamcrest::{assert_that, existing_file};
|
|
|
|
|
|
|
|
fn setup() {
|
|
|
|
}
|
|
|
|
|
|
|
|
test!(simple {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-09-09 02:38:16 +00:00
|
|
|
exclude = ["*.txt"]
|
2014-11-18 12:23:53 +00:00
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
2014-07-18 15:40:45 +00:00
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() { println!("hello"); }
|
2014-09-09 02:38:16 +00:00
|
|
|
"#)
|
|
|
|
.file("src/bar.txt", ""); // should be ignored when packaging
|
2014-07-18 15:40:45 +00:00
|
|
|
|
|
|
|
assert_that(p.cargo_process("package"),
|
|
|
|
execs().with_status(0).with_stdout(format!("\
|
|
|
|
{packaging} foo v0.0.1 ({dir})
|
2014-09-27 04:14:46 +00:00
|
|
|
{verifying} foo v0.0.1 ({dir})
|
|
|
|
{compiling} foo v0.0.1 ({dir}[..])
|
2014-07-18 15:40:45 +00:00
|
|
|
",
|
|
|
|
packaging = PACKAGING,
|
2014-09-27 04:14:46 +00:00
|
|
|
verifying = VERIFYING,
|
|
|
|
compiling = COMPILING,
|
2014-07-18 15:40:45 +00:00
|
|
|
dir = p.url()).as_slice()));
|
2014-11-05 02:56:08 +00:00
|
|
|
assert_that(&p.root().join("target/package/foo-0.0.1.crate"), existing_file());
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("package").arg("-l"),
|
2014-11-13 06:28:30 +00:00
|
|
|
execs().with_status(0).with_stdout("\
|
|
|
|
Cargo.toml
|
|
|
|
src[..]main.rs
|
|
|
|
"));
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("package"),
|
2014-09-09 02:38:16 +00:00
|
|
|
execs().with_status(0).with_stdout(""));
|
|
|
|
|
2014-12-21 23:19:44 +00:00
|
|
|
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
|
2015-02-27 01:04:25 +00:00
|
|
|
let mut rdr = GzDecoder::new(f).unwrap();
|
|
|
|
let mut contents = Vec::new();
|
|
|
|
rdr.read_to_end(&mut contents).unwrap();
|
|
|
|
let ar = Archive::new(Cursor::new(contents));
|
2014-12-21 23:19:44 +00:00
|
|
|
for f in ar.files().unwrap() {
|
|
|
|
let f = f.unwrap();
|
2014-09-09 19:35:31 +00:00
|
|
|
let fname = f.filename_bytes();
|
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-01-13 16:41:04 +00:00
|
|
|
"unexpected filename: {:?}", f.filename())
|
2014-09-09 02:38:16 +00:00
|
|
|
}
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-11-18 12:23:53 +00:00
|
|
|
|
|
|
|
test!(metadata_warning {
|
|
|
|
let p = project("all")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#);
|
|
|
|
assert_that(p.cargo_process("package"),
|
|
|
|
execs().with_status(0).with_stdout(format!("\
|
|
|
|
{packaging} foo v0.0.1 ({dir})
|
|
|
|
{verifying} foo v0.0.1 ({dir})
|
|
|
|
{compiling} foo v0.0.1 ({dir}[..])
|
|
|
|
",
|
|
|
|
packaging = PACKAGING,
|
|
|
|
verifying = VERIFYING,
|
|
|
|
compiling = COMPILING,
|
|
|
|
dir = p.url()).as_slice())
|
2014-11-25 06:18:54 +00:00
|
|
|
.with_stderr("\
|
2014-12-15 04:43:38 +00:00
|
|
|
warning: manifest has no description, license, license-file, documentation, \
|
|
|
|
homepage or repository. See \
|
2014-11-25 06:18:54 +00:00
|
|
|
http://doc.crates.io/manifest.html#package-metadata for more info."));
|
2014-11-18 12:23:53 +00:00
|
|
|
|
|
|
|
let p = project("one")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#);
|
|
|
|
assert_that(p.cargo_process("package"),
|
|
|
|
execs().with_status(0).with_stdout(format!("\
|
|
|
|
{packaging} foo v0.0.1 ({dir})
|
|
|
|
{verifying} foo v0.0.1 ({dir})
|
|
|
|
{compiling} foo v0.0.1 ({dir}[..])
|
|
|
|
",
|
|
|
|
packaging = PACKAGING,
|
|
|
|
verifying = VERIFYING,
|
|
|
|
compiling = COMPILING,
|
|
|
|
dir = p.url()).as_slice())
|
2014-11-25 06:18:54 +00:00
|
|
|
.with_stderr("\
|
2014-12-15 04:43:38 +00:00
|
|
|
warning: manifest has no description, documentation, homepage or repository. See \
|
2014-11-25 06:18:54 +00:00
|
|
|
http://doc.crates.io/manifest.html#package-metadata for more info."));
|
2014-11-18 12:23:53 +00:00
|
|
|
|
2014-12-15 04:43:38 +00:00
|
|
|
let p = project("all")
|
2015-02-27 01:04:25 +00:00
|
|
|
.file("Cargo.toml", &format!(r#"
|
2014-11-18 12:23:53 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
license = "MIT"
|
|
|
|
description = "foo"
|
2014-12-15 04:43:38 +00:00
|
|
|
repository = "bar"
|
2014-11-18 12:23:53 +00:00
|
|
|
"#))
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#);
|
|
|
|
assert_that(p.cargo_process("package"),
|
|
|
|
execs().with_status(0).with_stdout(format!("\
|
|
|
|
{packaging} foo v0.0.1 ({dir})
|
|
|
|
{verifying} foo v0.0.1 ({dir})
|
|
|
|
{compiling} foo v0.0.1 ({dir}[..])
|
|
|
|
",
|
|
|
|
packaging = PACKAGING,
|
|
|
|
verifying = VERIFYING,
|
|
|
|
compiling = COMPILING,
|
|
|
|
dir = p.url()).as_slice()));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-11-18 12:23:53 +00:00
|
|
|
|
2014-11-21 20:31:00 +00:00
|
|
|
test!(package_verbose {
|
|
|
|
let root = paths::root().join("all");
|
|
|
|
let p = git::repo(&root)
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#)
|
|
|
|
.file("a/Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("a/src/lib.rs", "");
|
|
|
|
p.build();
|
2015-02-27 01:04:25 +00:00
|
|
|
let mut cargo = process(&cargo_dir().join("cargo")).unwrap();
|
|
|
|
cargo.cwd(&root).env("HOME", &paths::home());
|
2014-11-21 20:31:00 +00:00
|
|
|
assert_that(cargo.clone().arg("build"), execs().with_status(0));
|
|
|
|
assert_that(cargo.arg("package").arg("-v")
|
|
|
|
.arg("--no-verify"),
|
|
|
|
execs().with_status(0).with_stdout(format!("\
|
|
|
|
{packaging} foo v0.0.1 ([..])
|
|
|
|
{archiving} [..]
|
|
|
|
{archiving} [..]
|
|
|
|
",
|
|
|
|
packaging = PACKAGING,
|
|
|
|
archiving = ARCHIVING).as_slice()));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-11-21 06:48:18 +00:00
|
|
|
|
|
|
|
test!(package_verification {
|
|
|
|
let p = project("all")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
"#);
|
|
|
|
assert_that(p.cargo_process("build"),
|
|
|
|
execs().with_status(0));
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("package"),
|
2014-11-21 06:48:18 +00:00
|
|
|
execs().with_status(0).with_stdout(format!("\
|
|
|
|
{packaging} foo v0.0.1 ({dir})
|
|
|
|
{verifying} foo v0.0.1 ({dir})
|
|
|
|
{compiling} foo v0.0.1 ({dir}[..])
|
|
|
|
",
|
|
|
|
packaging = PACKAGING,
|
|
|
|
verifying = VERIFYING,
|
|
|
|
compiling = COMPILING,
|
|
|
|
dir = p.url()).as_slice()));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2015-01-06 07:54:16 +00:00
|
|
|
|
|
|
|
test!(exclude {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
exclude = ["*.txt"]
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() { println!("hello"); }
|
|
|
|
"#)
|
|
|
|
.file("bar.txt", "")
|
|
|
|
.file("src/bar.txt", "");
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("package").arg("--no-verify").arg("-v"),
|
|
|
|
execs().with_status(0).with_stdout(format!("\
|
|
|
|
{packaging} foo v0.0.1 ([..])
|
|
|
|
{archiving} [..]
|
|
|
|
{archiving} [..]
|
|
|
|
", packaging = PACKAGING, archiving = ARCHIVING).as_slice()));
|
|
|
|
});
|
|
|
|
|
|
|
|
test!(include {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
exclude = ["*.txt"]
|
|
|
|
include = ["foo.txt", "**/*.rs", "Cargo.toml"]
|
|
|
|
"#)
|
|
|
|
.file("foo.txt", "")
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
fn main() { println!("hello"); }
|
|
|
|
"#)
|
|
|
|
.file("src/bar.txt", ""); // should be ignored when packaging
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("package").arg("--no-verify").arg("-v"),
|
|
|
|
execs().with_status(0).with_stdout(format!("\
|
|
|
|
{packaging} foo v0.0.1 ([..])
|
|
|
|
{archiving} [..]
|
|
|
|
{archiving} [..]
|
|
|
|
{archiving} [..]
|
|
|
|
", packaging = PACKAGING, archiving = ARCHIVING).as_slice()));
|
|
|
|
});
|
2015-03-11 20:32:59 +00:00
|
|
|
|
|
|
|
test!(package_lib_with_bin {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", r#"
|
|
|
|
extern crate foo;
|
|
|
|
fn main() {}
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "");
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("package").arg("-v"),
|
|
|
|
execs().with_status(0));
|
|
|
|
});
|