Remove the test! macro

This isn't really necessary and we can do setup manually in a few cases and
lazily do it in all the others.
This commit is contained in:
Alex Crichton 2016-05-25 13:55:42 -07:00
parent 3ff108a94c
commit 6950bbb0b4
45 changed files with 2055 additions and 1477 deletions

View File

@ -1,4 +1,5 @@
use std::env;
use std::cell::Cell;
use std::fs;
use std::io::{self, ErrorKind};
use std::path::{Path, PathBuf};
@ -9,9 +10,26 @@ use filetime::{self, FileTime};
static CARGO_INTEGRATION_TEST_DIR : &'static str = "cit";
static NEXT_ID: AtomicUsize = ATOMIC_USIZE_INIT;
thread_local!(static TASK_ID: usize = NEXT_ID.fetch_add(1, Ordering::SeqCst));
pub fn root() -> PathBuf {
fn init() {
static GLOBAL_INIT: Once = ONCE_INIT;
thread_local!(static LOCAL_INIT: Cell<bool> = Cell::new(false));
GLOBAL_INIT.call_once(|| {
global_root().mkdir_p().unwrap();
});
LOCAL_INIT.with(|i| {
if i.get() {
return
}
i.set(true);
root().rm_rf().unwrap();
home().mkdir_p().unwrap();
})
}
fn global_root() -> PathBuf {
let mut path = env::current_exe().unwrap();
path.pop(); // chop off exe name
path.pop(); // chop off 'debug'
@ -26,7 +44,11 @@ pub fn root() -> PathBuf {
}
path.join(CARGO_INTEGRATION_TEST_DIR)
.join(&TASK_ID.with(|my_id| format!("t{}", my_id)))
}
pub fn root() -> PathBuf {
init();
global_root().join(&TASK_ID.with(|my_id| format!("t{}", my_id)))
}
pub fn home() -> PathBuf {
@ -142,14 +164,3 @@ impl CargoPathExt for Path {
fs::metadata(self)
}
}
/// Ensure required test directories exist and are empty
pub fn setup() {
debug!("path setup; root={}; home={}", root().display(), home().display());
static INIT: Once = ONCE_INIT;
INIT.call_once(|| {
root().parent().unwrap().mkdir_p().unwrap();
});
root().rm_rf().unwrap();
home().mkdir_p().unwrap();
}

View File

@ -2,9 +2,8 @@ use support::{project, execs};
use support::registry::Package;
use hamcrest::assert_that;
fn setup() {}
test!(bad1 {
#[test]
fn bad1() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -23,9 +22,10 @@ test!(bad1 {
[ERROR] expected table for configuration key `target.nonexistent-target`, \
but found string in [..]config
"));
});
}
test!(bad2 {
#[test]
fn bad2() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -54,9 +54,10 @@ Caused by:
Caused by:
found TOML configuration value of unknown type `float`
"));
});
}
test!(bad3 {
#[test]
fn bad3() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -75,9 +76,10 @@ test!(bad3 {
[ERROR] invalid configuration for key `http.proxy`
expected a string, but found a boolean in [..]config
"));
});
}
test!(bad4 {
#[test]
fn bad4() {
let foo = project("foo")
.file(".cargo/config", r#"
[cargo-new]
@ -91,9 +93,10 @@ Caused by:
invalid configuration for key `cargo-new.name`
expected a string, but found a boolean in [..]config
"));
});
}
test!(bad5 {
#[test]
fn bad5() {
let foo = project("foo")
.file(".cargo/config", r#"
foo = ""
@ -115,9 +118,10 @@ Caused by:
Caused by:
expected integer, but found string
"));
});
}
test!(bad_cargo_config_jobs {
#[test]
fn bad_cargo_config_jobs() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -134,9 +138,10 @@ test!(bad_cargo_config_jobs {
execs().with_status(101).with_stderr("\
[ERROR] build.jobs must be positive, but found -1 in [..]
"));
});
}
test!(default_cargo_config_jobs {
#[test]
fn default_cargo_config_jobs() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -151,9 +156,10 @@ test!(default_cargo_config_jobs {
"#);
assert_that(foo.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}
test!(good_cargo_config_jobs {
#[test]
fn good_cargo_config_jobs() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -168,9 +174,10 @@ test!(good_cargo_config_jobs {
"#);
assert_that(foo.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}
test!(invalid_global_config {
#[test]
fn invalid_global_config() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -196,9 +203,10 @@ Caused by:
[..]config:1:2 expected `=`, but found eof
"));
});
}
test!(bad_cargo_lock {
#[test]
fn bad_cargo_lock() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -216,9 +224,10 @@ test!(bad_cargo_lock {
Caused by:
expected a section for the key `root`
"));
});
}
test!(bad_git_dependency {
#[test]
fn bad_git_dependency() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -242,9 +251,10 @@ Caused by:
Caused by:
[[..]] 'file:///' is not a valid local file URI
"));
});
}
test!(bad_crate_type {
#[test]
fn bad_crate_type() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -263,9 +273,10 @@ warning: crate-type \"bad_type\" was not one of lib|rlib|dylib|staticlib
[COMPILING] foo v0.0.0 (file:///[..])
[RUNNING] `rustc [..] --crate-type rlib [..]`
"));
});
}
test!(malformed_override {
#[test]
fn malformed_override() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -289,9 +300,10 @@ Caused by:
Cargo.toml:[..]
"));
});
}
test!(duplicate_binary_names {
#[test]
fn duplicate_binary_names() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -317,9 +329,10 @@ test!(duplicate_binary_names {
Caused by:
found duplicate binary name e, but all binary targets must have a unique name
"));
});
}
test!(duplicate_example_names {
#[test]
fn duplicate_example_names() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -345,9 +358,10 @@ test!(duplicate_example_names {
Caused by:
found duplicate example name ex, but all binary targets must have a unique name
"));
});
}
test!(duplicate_bench_names {
#[test]
fn duplicate_bench_names() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -373,9 +387,10 @@ test!(duplicate_bench_names {
Caused by:
found duplicate bench name ex, but all binary targets must have a unique name
"));
});
}
test!(duplicate_deps {
#[test]
fn duplicate_deps() {
let foo = project("foo")
.file("shim-bar/Cargo.toml", r#"
[package]
@ -416,9 +431,10 @@ test!(duplicate_deps {
Caused by:
found duplicate dependency name bar, but all dependencies must have a unique name
"));
});
}
test!(unused_keys {
#[test]
fn unused_keys() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -436,9 +452,10 @@ test!(unused_keys {
warning: unused manifest key: target.foo.bar
[COMPILING] foo v0.1.0 (file:///[..])
"));
});
}
test!(empty_dependencies {
#[test]
fn empty_dependencies() {
let p = project("empty_deps")
.file("Cargo.toml", r#"
[package]
@ -458,4 +475,4 @@ test!(empty_dependencies {
warning: dependency (foo) specified without providing a local path, Git repository, or version \
to use. This will be considered an error in future versions
"));
});
}

View File

@ -1,8 +1,6 @@
use support::{project, execs, main_file, basic_bin_manifest};
use hamcrest::{assert_that};
fn setup() {}
fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
@ -32,231 +30,288 @@ fn assert_cargo_toml_doesnt_exist(command: &str, manifest_path_argument: &str) {
));
}
test!(bench_dir_containing_cargo_toml {
#[test]
fn bench_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("bench", "foo");
});
}
test!(bench_dir_plus_file {
#[test]
fn bench_dir_plus_file() {
assert_not_a_cargo_toml("bench", "foo/bar");
});
}
test!(bench_dir_plus_path {
#[test]
fn bench_dir_plus_path() {
assert_not_a_cargo_toml("bench", "foo/bar/baz");
});
}
test!(bench_dir_to_nonexistent_cargo_toml {
#[test]
fn bench_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("bench", "foo/bar/baz/Cargo.toml");
});
}
test!(build_dir_containing_cargo_toml {
#[test]
fn build_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("build", "foo");
});
}
test!(build_dir_plus_file {
#[test]
fn build_dir_plus_file() {
assert_not_a_cargo_toml("bench", "foo/bar");
});
}
test!(build_dir_plus_path {
#[test]
fn build_dir_plus_path() {
assert_not_a_cargo_toml("bench", "foo/bar/baz");
});
}
test!(build_dir_to_nonexistent_cargo_toml {
#[test]
fn build_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("build", "foo/bar/baz/Cargo.toml");
});
}
test!(clean_dir_containing_cargo_toml {
#[test]
fn clean_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("clean", "foo");
});
}
test!(clean_dir_plus_file {
#[test]
fn clean_dir_plus_file() {
assert_not_a_cargo_toml("clean", "foo/bar");
});
}
test!(clean_dir_plus_path {
#[test]
fn clean_dir_plus_path() {
assert_not_a_cargo_toml("clean", "foo/bar/baz");
});
}
test!(clean_dir_to_nonexistent_cargo_toml {
#[test]
fn clean_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("clean", "foo/bar/baz/Cargo.toml");
});
}
test!(doc_dir_containing_cargo_toml {
#[test]
fn doc_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("doc", "foo");
});
}
test!(doc_dir_plus_file {
#[test]
fn doc_dir_plus_file() {
assert_not_a_cargo_toml("doc", "foo/bar");
});
}
test!(doc_dir_plus_path {
#[test]
fn doc_dir_plus_path() {
assert_not_a_cargo_toml("doc", "foo/bar/baz");
});
}
test!(doc_dir_to_nonexistent_cargo_toml {
#[test]
fn doc_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("doc", "foo/bar/baz/Cargo.toml");
});
}
test!(fetch_dir_containing_cargo_toml {
#[test]
fn fetch_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("fetch", "foo");
});
}
test!(fetch_dir_plus_file {
#[test]
fn fetch_dir_plus_file() {
assert_not_a_cargo_toml("fetch", "foo/bar");
});
}
test!(fetch_dir_plus_path {
#[test]
fn fetch_dir_plus_path() {
assert_not_a_cargo_toml("fetch", "foo/bar/baz");
});
}
test!(fetch_dir_to_nonexistent_cargo_toml {
#[test]
fn fetch_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("fetch", "foo/bar/baz/Cargo.toml");
});
}
test!(generate_lockfile_dir_containing_cargo_toml {
#[test]
fn generate_lockfile_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("generate-lockfile", "foo");
});
}
test!(generate_lockfile_dir_plus_file {
#[test]
fn generate_lockfile_dir_plus_file() {
assert_not_a_cargo_toml("generate-lockfile", "foo/bar");
});
}
test!(generate_lockfile_dir_plus_path {
#[test]
fn generate_lockfile_dir_plus_path() {
assert_not_a_cargo_toml("generate-lockfile", "foo/bar/baz");
});
}
test!(generate_lockfile_dir_to_nonexistent_cargo_toml {
#[test]
fn generate_lockfile_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("generate-lockfile", "foo/bar/baz/Cargo.toml");
});
}
test!(package_dir_containing_cargo_toml {
#[test]
fn package_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("package", "foo");
});
}
test!(package_dir_plus_file {
#[test]
fn package_dir_plus_file() {
assert_not_a_cargo_toml("package", "foo/bar");
});
}
test!(package_dir_plus_path {
#[test]
fn package_dir_plus_path() {
assert_not_a_cargo_toml("package", "foo/bar/baz");
});
}
test!(package_dir_to_nonexistent_cargo_toml {
#[test]
fn package_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("package", "foo/bar/baz/Cargo.toml");
});
}
test!(pkgid_dir_containing_cargo_toml {
#[test]
fn pkgid_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("pkgid", "foo");
});
}
test!(pkgid_dir_plus_file {
#[test]
fn pkgid_dir_plus_file() {
assert_not_a_cargo_toml("pkgid", "foo/bar");
});
}
test!(pkgid_dir_plus_path {
#[test]
fn pkgid_dir_plus_path() {
assert_not_a_cargo_toml("pkgid", "foo/bar/baz");
});
}
test!(pkgid_dir_to_nonexistent_cargo_toml {
#[test]
fn pkgid_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("pkgid", "foo/bar/baz/Cargo.toml");
});
}
test!(publish_dir_containing_cargo_toml {
#[test]
fn publish_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("publish", "foo");
});
}
test!(publish_dir_plus_file {
#[test]
fn publish_dir_plus_file() {
assert_not_a_cargo_toml("publish", "foo/bar");
});
}
test!(publish_dir_plus_path {
#[test]
fn publish_dir_plus_path() {
assert_not_a_cargo_toml("publish", "foo/bar/baz");
});
}
test!(publish_dir_to_nonexistent_cargo_toml {
#[test]
fn publish_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("publish", "foo/bar/baz/Cargo.toml");
});
}
test!(read_manifest_dir_containing_cargo_toml {
#[test]
fn read_manifest_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("read-manifest", "foo");
});
}
test!(read_manifest_dir_plus_file {
#[test]
fn read_manifest_dir_plus_file() {
assert_not_a_cargo_toml("read-manifest", "foo/bar");
});
}
test!(read_manifest_dir_plus_path {
#[test]
fn read_manifest_dir_plus_path() {
assert_not_a_cargo_toml("read-manifest", "foo/bar/baz");
});
}
test!(read_manifest_dir_to_nonexistent_cargo_toml {
#[test]
fn read_manifest_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("read-manifest", "foo/bar/baz/Cargo.toml");
});
}
test!(run_dir_containing_cargo_toml {
#[test]
fn run_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("run", "foo");
});
}
test!(run_dir_plus_file {
#[test]
fn run_dir_plus_file() {
assert_not_a_cargo_toml("run", "foo/bar");
});
}
test!(run_dir_plus_path {
#[test]
fn run_dir_plus_path() {
assert_not_a_cargo_toml("run", "foo/bar/baz");
});
}
test!(run_dir_to_nonexistent_cargo_toml {
#[test]
fn run_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("run", "foo/bar/baz/Cargo.toml");
});
}
test!(rustc_dir_containing_cargo_toml {
#[test]
fn rustc_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("rustc", "foo");
});
}
test!(rustc_dir_plus_file {
#[test]
fn rustc_dir_plus_file() {
assert_not_a_cargo_toml("rustc", "foo/bar");
});
}
test!(rustc_dir_plus_path {
#[test]
fn rustc_dir_plus_path() {
assert_not_a_cargo_toml("rustc", "foo/bar/baz");
});
}
test!(rustc_dir_to_nonexistent_cargo_toml {
#[test]
fn rustc_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("rustc", "foo/bar/baz/Cargo.toml");
});
}
test!(test_dir_containing_cargo_toml {
#[test]
fn test_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("test", "foo");
});
}
test!(test_dir_plus_file {
#[test]
fn test_dir_plus_file() {
assert_not_a_cargo_toml("test", "foo/bar");
});
}
test!(test_dir_plus_path {
#[test]
fn test_dir_plus_path() {
assert_not_a_cargo_toml("test", "foo/bar/baz");
});
}
test!(test_dir_to_nonexistent_cargo_toml {
#[test]
fn test_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("test", "foo/bar/baz/Cargo.toml");
});
}
test!(update_dir_containing_cargo_toml {
#[test]
fn update_dir_containing_cargo_toml() {
assert_not_a_cargo_toml("update", "foo");
});
}
test!(update_dir_plus_file {
#[test]
fn update_dir_plus_file() {
assert_not_a_cargo_toml("update", "foo/bar");
});
}
test!(update_dir_plus_path {
#[test]
fn update_dir_plus_path() {
assert_not_a_cargo_toml("update", "foo/bar/baz");
});
}
test!(update_dir_to_nonexistent_cargo_toml {
#[test]
fn update_dir_to_nonexistent_cargo_toml() {
assert_cargo_toml_doesnt_exist("update", "foo/bar/baz/Cargo.toml");
});
}
test!(verify_project_dir_containing_cargo_toml {
#[test]
fn verify_project_dir_containing_cargo_toml() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -268,9 +323,10 @@ test!(verify_project_dir_containing_cargo_toml {
.with_stdout("\
{\"invalid\":\"the manifest-path must be a path to a Cargo.toml file\"}\
"));
});
}
test!(verify_project_dir_plus_file {
#[test]
fn verify_project_dir_plus_file() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -282,9 +338,10 @@ test!(verify_project_dir_plus_file {
.with_stdout("\
{\"invalid\":\"the manifest-path must be a path to a Cargo.toml file\"}\
"));
});
}
test!(verify_project_dir_plus_path {
#[test]
fn verify_project_dir_plus_path() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -296,9 +353,10 @@ test!(verify_project_dir_plus_path {
.with_stdout("\
{\"invalid\":\"the manifest-path must be a path to a Cargo.toml file\"}\
"));
});
}
test!(verify_project_dir_to_nonexistent_cargo_toml {
#[test]
fn verify_project_dir_to_nonexistent_cargo_toml() {
let p = project("foo");
assert_that(p.cargo_process("verify-project")
.arg("--manifest-path").arg("foo/bar/baz/Cargo.toml")
@ -307,4 +365,4 @@ test!(verify_project_dir_to_nonexistent_cargo_toml {
.with_stdout("\
{\"invalid\":\"manifest path `foo[..]bar[..]baz[..]Cargo.toml` does not exist\"}\
"));
});
}

View File

@ -10,9 +10,6 @@ use support::paths;
use support::{execs, project, mkdir_recursive, ProjectBuilder};
use hamcrest::{assert_that};
fn setup() {
}
#[cfg_attr(windows,allow(dead_code))]
enum FakeKind<'a> {
Executable,
@ -61,7 +58,8 @@ fn path() -> Vec<PathBuf> {
env::split_paths(&env::var_os("PATH").unwrap_or(OsString::new())).collect()
}
test!(list_command_looks_at_path {
#[test]
fn list_command_looks_at_path() {
let proj = project("list-non-overlapping");
let proj = fake_file(proj, &Path::new("path-test"), "cargo-1", FakeKind::Executable);
let mut pr = cargo_process();
@ -74,11 +72,12 @@ test!(list_command_looks_at_path {
let output = output.exec_with_output().unwrap();
let output = str::from_utf8(&output.stdout).unwrap();
assert!(output.contains("\n 1\n"), "missing 1: {}", output);
});
}
// windows and symlinks don't currently agree that well
#[cfg(unix)]
test!(list_command_resolves_symlinks {
#[test]
fn list_command_resolves_symlinks() {
use support::cargo_dir;
let proj = project("list-non-overlapping");
@ -94,9 +93,10 @@ test!(list_command_resolves_symlinks {
let output = output.exec_with_output().unwrap();
let output = str::from_utf8(&output.stdout).unwrap();
assert!(output.contains("\n 2\n"), "missing 2: {}", output);
});
}
test!(find_closest_biuld_to_build {
#[test]
fn find_closest_biuld_to_build() {
let mut pr = cargo_process();
pr.arg("biuld");
@ -107,10 +107,11 @@ test!(find_closest_biuld_to_build {
<tab>Did you mean `build`?
"));
});
}
// if a subcommand is more than 3 edit distance away, we don't make a suggestion
test!(find_closest_dont_correct_nonsense {
#[test]
fn find_closest_dont_correct_nonsense() {
let mut pr = cargo_process();
pr.arg("there-is-no-way-that-there-is-a-command-close-to-this")
.cwd(&paths::root());
@ -119,9 +120,10 @@ test!(find_closest_dont_correct_nonsense {
execs().with_status(101)
.with_stderr("[ERROR] no such subcommand
"));
});
}
test!(override_cargo_home {
#[test]
fn override_cargo_home() {
let root = paths::root();
let my_home = root.join("my_home");
fs::create_dir(&my_home).unwrap();
@ -142,9 +144,10 @@ test!(override_cargo_home {
let mut contents = String::new();
File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"authors = ["foo <bar>"]"#));
});
}
test!(cargo_help {
#[test]
fn cargo_help() {
assert_that(cargo_process(),
execs().with_status(0));
assert_that(cargo_process().arg("help"),
@ -159,9 +162,10 @@ test!(cargo_help {
execs().with_status(0));
assert_that(cargo_process().arg("help").arg("help"),
execs().with_status(0));
});
}
test!(explain {
#[test]
fn explain() {
assert_that(cargo_process().arg("--explain").arg("E0001"),
execs().with_status(0));
});
}

View File

@ -5,9 +5,8 @@ use support::paths::CargoPathExt;
use hamcrest::{assert_that, existing_file};
use cargo::util::process;
fn setup() {}
test!(cargo_bench_simple {
#[test]
fn cargo_bench_simple() {
if !::is_nightly() { return }
let p = project("foo")
@ -46,9 +45,10 @@ test bench_hello ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"));
});
}
test!(bench_tarname {
#[test]
fn bench_tarname() {
if !::is_nightly() { return }
let prj = project("foo")
@ -80,9 +80,10 @@ test run2 ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"));
});
}
test!(cargo_bench_verbose {
#[test]
fn cargo_bench_verbose() {
if !::is_nightly() { return }
let p = project("foo")
@ -106,9 +107,10 @@ test bench_hello ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"));
});
}
test!(many_similar_names {
#[test]
fn many_similar_names() {
if !::is_nightly() { return }
let p = project("foo")
@ -143,9 +145,10 @@ test!(many_similar_names {
assert!(output.contains("test bin_bench"), "bin_bench missing\n{}", output);
assert!(output.contains("test lib_bench"), "lib_bench missing\n{}", output);
assert!(output.contains("test bench_bench"), "bench_bench missing\n{}", output);
});
}
test!(cargo_bench_failing_test {
#[test]
fn cargo_bench_failing_test() {
if !::is_nightly() { return }
let p = project("foo")
@ -185,9 +188,10 @@ thread '<main>' panicked at 'assertion failed: \
[..]
", p.url()))
.with_status(101));
});
}
test!(bench_with_lib_dep {
#[test]
fn bench_with_lib_dep() {
if !::is_nightly() { return }
let p = project("foo")
@ -244,9 +248,10 @@ test lib_bench ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"))
});
}
test!(bench_with_deep_lib_dep {
#[test]
fn bench_with_deep_lib_dep() {
if !::is_nightly() { return }
let p = project("bar")
@ -299,9 +304,10 @@ test bar_bench ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"));
});
}
test!(external_bench_explicit {
#[test]
fn external_bench_explicit() {
if !::is_nightly() { return }
let p = project("foo")
@ -350,9 +356,10 @@ test internal_bench ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"))
});
}
test!(external_bench_implicit {
#[test]
fn external_bench_implicit() {
if !::is_nightly() { return }
let p = project("foo")
@ -398,9 +405,10 @@ test internal_bench ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"))
});
}
test!(dont_run_examples {
#[test]
fn dont_run_examples() {
if !::is_nightly() { return }
let p = project("foo")
@ -417,9 +425,10 @@ test!(dont_run_examples {
"#);
assert_that(p.cargo_process("bench"),
execs().with_status(0));
});
}
test!(pass_through_command_line {
#[test]
fn pass_through_command_line() {
if !::is_nightly() { return }
let p = project("foo")
@ -461,11 +470,12 @@ test foo ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"));
});
}
// Regression test for running cargo-bench twice with
// tests in an rlib
test!(cargo_bench_twice {
#[test]
fn cargo_bench_twice() {
if !::is_nightly() { return }
let p = project("test_twice")
@ -486,9 +496,10 @@ test!(cargo_bench_twice {
assert_that(p.cargo("bench"),
execs().with_status(0));
}
});
}
test!(lib_bin_same_name {
#[test]
fn lib_bin_same_name() {
if !::is_nightly() { return }
let p = project("foo")
@ -535,9 +546,10 @@ test [..] ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"))
});
}
test!(lib_with_standard_name {
#[test]
fn lib_with_standard_name() {
if !::is_nightly() { return }
let p = project("foo")
@ -587,9 +599,10 @@ test foo_bench ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"));
});
}
test!(lib_with_standard_name2 {
#[test]
fn lib_with_standard_name2() {
if !::is_nightly() { return }
let p = project("foo")
@ -630,9 +643,10 @@ test bench ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"));
});
}
test!(bench_dylib {
#[test]
fn bench_dylib() {
if !::is_nightly() { return }
let p = project("foo")
@ -726,9 +740,10 @@ test foo ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"));
});
}
test!(bench_twice_with_build_cmd {
#[test]
fn bench_twice_with_build_cmd() {
if !::is_nightly() { return }
let p = project("foo")
@ -771,9 +786,10 @@ test foo ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"));
});
}
test!(bench_with_examples {
#[test]
fn bench_with_examples() {
if !::is_nightly() { return }
let p = project("testbench")
@ -850,9 +866,10 @@ test bench_bench1 ... bench: [..] 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"));
});
}
test!(test_a_bench {
#[test]
fn test_a_bench() {
if !::is_nightly() { return }
let p = project("foo")
@ -889,9 +906,10 @@ test foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(test_bench_no_run {
#[test]
fn test_bench_no_run() {
if !::is_nightly() { return }
let p = project("foo")
@ -918,9 +936,10 @@ test!(test_bench_no_run {
.with_stderr("\
[COMPILING] foo v0.1.0 ([..])
"));
});
}
test!(test_bench_multiple_packages {
#[test]
fn test_bench_multiple_packages() {
if !::is_nightly() { return }
let p = project("foo")
@ -1003,4 +1022,4 @@ test bench_bar ... bench: 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
"));
});
}

View File

@ -10,11 +10,9 @@ use support::{project, execs};
use support::paths;
use hamcrest::assert_that;
fn setup() {
}
// Test that HTTP auth is offered from `credential.helper`
test!(http_auth_offered {
#[test]
fn http_auth_offered() {
let a = TcpListener::bind("127.0.0.1:0").unwrap();
let addr = a.local_addr().unwrap();
@ -115,10 +113,11 @@ To learn more, run the command again with --verbose.
addr = addr)));
t.join().ok().unwrap();
});
}
// Boy, sure would be nice to have a TLS implementation in rust!
test!(https_something_happens {
#[test]
fn https_something_happens() {
let a = TcpListener::bind("127.0.0.1:0").unwrap();
let addr = a.local_addr().unwrap();
let t = thread::spawn(move|| {
@ -163,10 +162,11 @@ Caused by:
})));
t.join().ok().unwrap();
});
}
// Boy, sure would be nice to have an SSH implementation in rust!
test!(ssh_something_happens {
#[test]
fn ssh_something_happens() {
let a = TcpListener::bind("127.0.0.1:0").unwrap();
let addr = a.local_addr().unwrap();
let t = thread::spawn(move|| {
@ -196,4 +196,4 @@ Caused by:
[[..]] Failed to start SSH session: Failed getting banner
"));
t.join().ok().unwrap();
});
}

View File

@ -2,9 +2,6 @@ use std::path::MAIN_SEPARATOR as SEP;
use support::{basic_bin_manifest, execs, project, ProjectBuilder};
use hamcrest::{assert_that};
fn setup() {
}
fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
format!("\
[COMPILING] {name} v{version} ({url})
@ -18,7 +15,8 @@ fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
name = "foo", version = "0.0.1")
}
test!(build_lib_only {
#[test]
fn build_lib_only() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -36,10 +34,11 @@ test!(build_lib_only {
execs()
.with_status(0)
.with_stderr(verbose_output_for_lib(&p)));
});
}
test!(build_with_no_lib {
#[test]
fn build_with_no_lib() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/main.rs", r#"
@ -49,9 +48,10 @@ test!(build_with_no_lib {
assert_that(p.cargo_process("build").arg("--lib"),
execs().with_status(101)
.with_stderr("[ERROR] no library targets found"));
});
}
test!(build_with_relative_cargo_home_path {
#[test]
fn build_with_relative_cargo_home_path() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -79,4 +79,4 @@ test!(build_with_relative_cargo_home_path {
assert_that(p.cargo_process("build").env("CARGO_HOME", "./cargo_home/"),
execs()
.with_status(0));
});
}

View File

@ -132,9 +132,8 @@ fn cfg_matches() {
assert!(!e!(any((not(foo)), (all(foo, bar)))).matches(&[c!(foo)]));
}
fn setup() {}
test!(cfg_easy {
#[test]
fn cfg_easy() {
if !::is_nightly() { return }
let p = project("foo")
@ -159,9 +158,10 @@ test!(cfg_easy {
.file("b/src/lib.rs", "");
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}
test!(dont_include {
#[test]
fn dont_include() {
if !::is_nightly() { return }
let other_family = if cfg!(unix) {"windows"} else {"unix"};
@ -187,9 +187,10 @@ test!(dont_include {
execs().with_status(0).with_stderr("\
[COMPILING] a v0.0.1 ([..])
"));
});
}
test!(works_through_the_registry {
#[test]
fn works_through_the_registry() {
if !::is_nightly() { return }
Package::new("foo", "0.1.0").publish();
@ -219,9 +220,10 @@ test!(works_through_the_registry {
[COMPILING] bar v0.1.0 ([..])
[COMPILING] a v0.0.1 ([..])
"));
});
}
test!(bad_target_spec {
#[test]
fn bad_target_spec() {
let p = project("a")
.file("Cargo.toml", &r#"
[package]
@ -244,9 +246,10 @@ Caused by:
Caused by:
unexpected character in cfg `4`, [..]
"));
});
}
test!(bad_target_spec2 {
#[test]
fn bad_target_spec2() {
let p = project("a")
.file("Cargo.toml", &r#"
[package]
@ -269,9 +272,10 @@ Caused by:
Caused by:
expected a string, found nothing
"));
});
}
test!(multiple_match_ok {
#[test]
fn multiple_match_ok() {
if !::is_nightly() { return }
let p = project("foo")
@ -305,9 +309,10 @@ test!(multiple_match_ok {
.file("b/src/lib.rs", "");
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}
test!(any_ok {
#[test]
fn any_ok() {
if !::is_nightly() { return }
let p = project("foo")
@ -330,4 +335,4 @@ test!(any_ok {
.file("b/src/lib.rs", "");
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}

View File

@ -4,10 +4,8 @@ use support::{git, project, execs, main_file, basic_bin_manifest};
use support::registry::Package;
use hamcrest::{assert_that, existing_dir, existing_file, is_not};
fn setup() {
}
test!(cargo_clean_simple {
#[test]
fn cargo_clean_simple() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -18,9 +16,10 @@ test!(cargo_clean_simple {
assert_that(p.cargo("clean"),
execs().with_status(0));
assert_that(&p.build_dir(), is_not(existing_dir()));
});
}
test!(different_dir {
#[test]
fn different_dir() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
@ -32,9 +31,10 @@ test!(different_dir {
assert_that(p.cargo("clean").cwd(&p.root().join("src")),
execs().with_status(0).with_stdout(""));
assert_that(&p.build_dir(), is_not(existing_dir()));
});
}
test!(clean_multiple_packages {
#[test]
fn clean_multiple_packages() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -93,9 +93,10 @@ test!(clean_multiple_packages {
assert_that(&p.bin("foo"), existing_file());
assert_that(d1_path, is_not(existing_file()));
assert_that(d2_path, is_not(existing_file()));
});
}
test!(clean_release {
#[test]
fn clean_release() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -130,9 +131,10 @@ test!(clean_release {
execs().with_status(0).with_stderr("\
[COMPILING] foo v0.0.1 ([..])
"));
});
}
test!(build_script {
#[test]
fn build_script() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -169,9 +171,10 @@ test!(build_script {
[RUNNING] `[..]build-script-build[..]`
[RUNNING] `rustc src[..]main.rs [..]`
"));
});
}
test!(clean_git {
#[test]
fn clean_git() {
let git = git::new("dep", |project| {
project.file("Cargo.toml", r#"
[project]
@ -201,9 +204,10 @@ test!(clean_git {
execs().with_status(0).with_stdout(""));
assert_that(p.cargo("build"),
execs().with_status(0));
});
}
test!(registry {
#[test]
fn registry() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -225,4 +229,4 @@ test!(registry {
execs().with_status(0).with_stdout(""));
assert_that(p.cargo("build"),
execs().with_status(0));
});
}

View File

@ -9,10 +9,8 @@ use hamcrest::{assert_that, existing_file, is_not};
use support::paths::{CargoPathExt,root};
use cargo::util::process;
fn setup() {
}
test!(cargo_compile_simple {
#[test]
fn cargo_compile_simple() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -22,9 +20,10 @@ test!(cargo_compile_simple {
assert_that(process(&p.bin("foo")),
execs().with_stdout("i am foo\n"));
});
}
test!(cargo_compile_manifest_path {
#[test]
fn cargo_compile_manifest_path() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -34,9 +33,10 @@ test!(cargo_compile_manifest_path {
.cwd(p.root().parent().unwrap()),
execs().with_status(0));
assert_that(&p.bin("foo"), existing_file());
});
}
test!(cargo_compile_with_invalid_manifest {
#[test]
fn cargo_compile_with_invalid_manifest() {
let p = project("foo")
.file("Cargo.toml", "");
@ -49,9 +49,10 @@ test!(cargo_compile_with_invalid_manifest {
Caused by:
no `package` or `project` section found.
"))
});
}
test!(cargo_compile_with_invalid_manifest2 {
#[test]
fn cargo_compile_with_invalid_manifest2() {
let p = project("foo")
.file("Cargo.toml", r"
[project]
@ -69,9 +70,10 @@ Caused by:
Cargo.toml:3:19-3:20 expected a value
"))
});
}
test!(cargo_compile_with_invalid_manifest3 {
#[test]
fn cargo_compile_with_invalid_manifest3() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -91,9 +93,10 @@ test!(cargo_compile_with_invalid_manifest3 {
Caused by:
could not parse input as TOML\n\
src[..]Cargo.toml:1:5-1:6 expected a value\n\n"))
});
}
test!(cargo_compile_with_invalid_version {
#[test]
fn cargo_compile_with_invalid_version() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -112,9 +115,10 @@ Caused by:
cannot parse '1.0' as a semver for the key `project.version`
"))
});
}
test!(cargo_compile_with_invalid_package_name {
#[test]
fn cargo_compile_with_invalid_package_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -132,9 +136,10 @@ test!(cargo_compile_with_invalid_package_name {
Caused by:
package name cannot be an empty string.
"))
});
}
test!(cargo_compile_with_invalid_bin_target_name {
#[test]
fn cargo_compile_with_invalid_bin_target_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -155,9 +160,10 @@ test!(cargo_compile_with_invalid_bin_target_name {
Caused by:
binary target names cannot be empty.
"))
});
}
test!(cargo_compile_with_forbidden_bin_target_name {
#[test]
fn cargo_compile_with_forbidden_bin_target_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -178,9 +184,10 @@ test!(cargo_compile_with_forbidden_bin_target_name {
Caused by:
the binary target name `build` is forbidden
"))
});
}
test!(cargo_compile_with_invalid_lib_target_name {
#[test]
fn cargo_compile_with_invalid_lib_target_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -201,9 +208,10 @@ test!(cargo_compile_with_invalid_lib_target_name {
Caused by:
library target names cannot be empty.
"))
});
}
test!(cargo_compile_without_manifest {
#[test]
fn cargo_compile_without_manifest() {
let tmpdir = TempDir::new("cargo").unwrap();
let p = ProjectBuilder::new("foo", tmpdir.path().to_path_buf());
@ -212,9 +220,10 @@ test!(cargo_compile_without_manifest {
.with_stderr("\
[ERROR] could not find `Cargo.toml` in `[..]` or any parent directory
"));
});
}
test!(cargo_compile_with_invalid_code {
#[test]
fn cargo_compile_with_invalid_code() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", "invalid rust code!");
@ -232,9 +241,10 @@ src[..]foo.rs:1 invalid rust code!
To learn more, run the command again with --verbose.\n"));
assert_that(&p.root().join("Cargo.lock"), existing_file());
});
}
test!(cargo_compile_with_invalid_code_in_deps {
#[test]
fn cargo_compile_with_invalid_code_in_deps() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -257,9 +267,10 @@ test!(cargo_compile_with_invalid_code_in_deps {
bar.build();
baz.build();
assert_that(p.cargo_process("build"), execs().with_status(101));
});
}
test!(cargo_compile_with_warnings_in_the_root_package {
#[test]
fn cargo_compile_with_warnings_in_the_root_package() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", "fn main() {} fn dead() {}");
@ -273,9 +284,10 @@ src[..]foo.rs:1:14: 1:26 warning: function is never used: `dead`, \
src[..]foo.rs:1 fn main() {} fn dead() {}
[..] ^~~~~~~~~~~~
"));
});
}
test!(cargo_compile_with_warnings_in_a_dep_package {
#[test]
fn cargo_compile_with_warnings_in_a_dep_package() {
let mut p = project("foo");
p = p
@ -328,9 +340,10 @@ test!(cargo_compile_with_warnings_in_a_dep_package {
assert_that(
process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
});
}
test!(cargo_compile_with_nested_deps_inferred {
#[test]
fn cargo_compile_with_nested_deps_inferred() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -386,9 +399,10 @@ test!(cargo_compile_with_nested_deps_inferred {
assert_that(
process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
});
}
test!(cargo_compile_with_nested_deps_correct_bin {
#[test]
fn cargo_compile_with_nested_deps_correct_bin() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -444,9 +458,10 @@ test!(cargo_compile_with_nested_deps_correct_bin {
assert_that(
process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
});
}
test!(cargo_compile_with_nested_deps_shorthand {
#[test]
fn cargo_compile_with_nested_deps_shorthand() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -511,9 +526,10 @@ test!(cargo_compile_with_nested_deps_shorthand {
assert_that(
process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
});
}
test!(cargo_compile_with_nested_deps_longhand {
#[test]
fn cargo_compile_with_nested_deps_longhand() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -577,11 +593,12 @@ test!(cargo_compile_with_nested_deps_longhand {
assert_that(process(&p.bin("foo")),
execs().with_stdout("test passed\n"));
});
}
// Check that Cargo gives a sensible error if a dependency can't be found
// because of a name mismatch.
test!(cargo_compile_with_dep_name_mismatch {
#[test]
fn cargo_compile_with_dep_name_mismatch() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -608,9 +625,10 @@ r#"[ERROR] no matching package named `notquitebar` found (required by `foo`)
location searched: {proj_dir}/bar
version required: *
"#, proj_dir = p.url())));
});
}
test!(cargo_compile_with_filename{
#[test]
fn cargo_compile_with_filename() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -646,9 +664,10 @@ Did you mean `a`?"));
[ERROR] no example target named `a.rs`
Did you mean `a`?"));
});
}
test!(compile_path_dep_then_change_version {
#[test]
fn compile_path_dep_then_change_version() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -685,9 +704,10 @@ version required: = 0.0.1
versions found: 0.0.2
consider running `cargo update` to update a path dependency's locked version
"));
});
}
test!(ignores_carriage_return_in_lockfile {
#[test]
fn ignores_carriage_return_in_lockfile() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -710,9 +730,10 @@ test!(ignores_carriage_return_in_lockfile {
File::create(&lockfile).unwrap().write_all(lock.as_bytes()).unwrap();
assert_that(p.cargo("build"),
execs().with_status(0));
});
}
test!(crate_env_vars {
#[test]
fn crate_env_vars() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -770,9 +791,10 @@ test!(crate_env_vars {
println!("test");
assert_that(p.cargo("test").arg("-v"),
execs().with_status(0));
});
}
test!(crate_authors_env_vars {
#[test]
fn crate_authors_env_vars() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -808,10 +830,11 @@ test!(crate_authors_env_vars {
println!("test");
assert_that(p.cargo("test").arg("-v"),
execs().with_status(0));
});
}
// this is testing that src/<pkg-name>.rs still works (for now)
test!(many_crate_types_old_style_lib_location {
#[test]
fn many_crate_types_old_style_lib_location() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
@ -835,9 +858,10 @@ test!(many_crate_types_old_style_lib_location {
let fname = format!("{}foo{}", env::consts::DLL_PREFIX,
env::consts::DLL_SUFFIX);
assert_that(&p.root().join("target/debug").join(&fname), existing_file());
});
}
test!(many_crate_types_correct {
#[test]
fn many_crate_types_correct() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
@ -862,9 +886,10 @@ test!(many_crate_types_correct {
let fname = format!("{}foo{}", env::consts::DLL_PREFIX,
env::consts::DLL_SUFFIX);
assert_that(&p.root().join("target/debug").join(&fname), existing_file());
});
}
test!(unused_keys {
#[test]
fn unused_keys() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
@ -912,9 +937,10 @@ warning: unused manifest key: project.bulid
warning: unused manifest key: lib.build
[COMPILING] foo [..]
"));
});
}
test!(self_dependency {
#[test]
fn self_dependency() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
@ -938,9 +964,10 @@ test!(self_dependency {
.with_stderr("\
[ERROR] cyclic package dependency: package `test v0.0.0 ([..])` depends on itself
"));
});
}
test!(ignore_broken_symlinks {
#[test]
fn ignore_broken_symlinks() {
// windows and symlinks don't currently agree that well
if cfg!(windows) { return }
@ -954,9 +981,10 @@ test!(ignore_broken_symlinks {
assert_that(process(&p.bin("foo")),
execs().with_stdout("i am foo\n"));
});
}
test!(missing_lib_and_bin {
#[test]
fn missing_lib_and_bin() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
@ -974,9 +1002,10 @@ test!(missing_lib_and_bin {
Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present\n"));
});
}
test!(lto_build {
#[test]
fn lto_build() {
// FIXME: currently this hits a linker bug on 32-bit MSVC
if cfg!(all(target_env = "msvc", target_pointer_width = "32")) {
return
@ -1009,9 +1038,10 @@ test!(lto_build {
dir = p.root().display(),
url = p.url(),
)));
});
}
test!(verbose_build {
#[test]
fn verbose_build() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
@ -1034,9 +1064,10 @@ test!(verbose_build {
dir = p.root().display(),
url = p.url(),
)));
});
}
test!(verbose_release_build {
#[test]
fn verbose_release_build() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
@ -1060,9 +1091,10 @@ test!(verbose_release_build {
dir = p.root().display(),
url = p.url(),
)));
});
}
test!(verbose_release_build_deps {
#[test]
fn verbose_release_build_deps() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
@ -1115,9 +1147,10 @@ test!(verbose_release_build_deps {
url = p.url(),
prefix = env::consts::DLL_PREFIX,
suffix = env::consts::DLL_SUFFIX)));
});
}
test!(explicit_examples {
#[test]
fn explicit_examples() {
let mut p = project("world");
p = p.file("Cargo.toml", r#"
[package]
@ -1156,9 +1189,10 @@ test!(explicit_examples {
execs().with_stdout("Hello, World!\n"));
assert_that(process(&p.bin("examples/goodbye")),
execs().with_stdout("Goodbye, World!\n"));
});
}
test!(implicit_examples {
#[test]
fn implicit_examples() {
let mut p = project("world");
p = p.file("Cargo.toml", r#"
[package]
@ -1189,9 +1223,10 @@ test!(implicit_examples {
execs().with_stdout("Hello, World!\n"));
assert_that(process(&p.bin("examples/goodbye")),
execs().with_stdout("Goodbye, World!\n"));
});
}
test!(standard_build_no_ndebug {
#[test]
fn standard_build_no_ndebug() {
let p = project("world")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", r#"
@ -1207,9 +1242,10 @@ test!(standard_build_no_ndebug {
assert_that(p.cargo_process("build"), execs().with_status(0));
assert_that(process(&p.bin("foo")),
execs().with_stdout("slow\n"));
});
}
test!(release_build_ndebug {
#[test]
fn release_build_ndebug() {
let p = project("world")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", r#"
@ -1226,9 +1262,10 @@ test!(release_build_ndebug {
execs().with_status(0));
assert_that(process(&p.release_bin("foo")),
execs().with_stdout("fast\n"));
});
}
test!(inferred_main_bin {
#[test]
fn inferred_main_bin() {
let p = project("world")
.file("Cargo.toml", r#"
[project]
@ -1242,9 +1279,10 @@ test!(inferred_main_bin {
assert_that(p.cargo_process("build"), execs().with_status(0));
assert_that(process(&p.bin("foo")), execs().with_status(0));
});
}
test!(deletion_causes_failure {
#[test]
fn deletion_causes_failure() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1275,9 +1313,10 @@ test!(deletion_causes_failure {
authors = []
"#);
assert_that(p.cargo_process("build"), execs().with_status(101));
});
}
test!(bad_cargo_toml_in_target_dir {
#[test]
fn bad_cargo_toml_in_target_dir() {
let p = project("world")
.file("Cargo.toml", r#"
[project]
@ -1292,9 +1331,10 @@ test!(bad_cargo_toml_in_target_dir {
assert_that(p.cargo_process("build"), execs().with_status(0));
assert_that(process(&p.bin("foo")), execs().with_status(0));
});
}
test!(lib_with_standard_name {
#[test]
fn lib_with_standard_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1316,9 +1356,10 @@ test!(lib_with_standard_name {
[COMPILING] syntax v0.0.1 ({dir})
",
dir = p.url())));
});
}
test!(simple_staticlib {
#[test]
fn simple_staticlib() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1335,9 +1376,10 @@ test!(simple_staticlib {
// env var is a test for #1381
assert_that(p.cargo_process("build").env("RUST_LOG", "nekoneko=trace"),
execs().with_status(0));
});
}
test!(staticlib_rlib_and_bin {
#[test]
fn staticlib_rlib_and_bin() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1358,9 +1400,10 @@ test!(staticlib_rlib_and_bin {
}"#);
assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0));
});
}
test!(opt_out_of_bin {
#[test]
fn opt_out_of_bin() {
let p = project("foo")
.file("Cargo.toml", r#"
bin = []
@ -1373,9 +1416,10 @@ test!(opt_out_of_bin {
.file("src/lib.rs", "")
.file("src/main.rs", "bad syntax");
assert_that(p.cargo_process("build"), execs().with_status(0));
});
}
test!(single_lib {
#[test]
fn single_lib() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1389,9 +1433,10 @@ test!(single_lib {
"#)
.file("src/bar.rs", "");
assert_that(p.cargo_process("build"), execs().with_status(0));
});
}
test!(freshness_ignores_excluded {
#[test]
fn freshness_ignores_excluded() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1424,9 +1469,10 @@ test!(freshness_ignores_excluded {
assert_that(foo.cargo("build"),
execs().with_status(0)
.with_stdout(""));
});
}
test!(rebuild_preserves_out_dir {
#[test]
fn rebuild_preserves_out_dir() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1465,9 +1511,10 @@ test!(rebuild_preserves_out_dir {
.with_stderr(&format!("\
[COMPILING] foo v0.0.0 ({url})
", url = foo.url())));
});
}
test!(dep_no_libs {
#[test]
fn dep_no_libs() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1488,9 +1535,10 @@ test!(dep_no_libs {
.file("bar/src/main.rs", "");
assert_that(foo.cargo_process("build"),
execs().with_status(0));
});
}
test!(recompile_space_in_name {
#[test]
fn recompile_space_in_name() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1507,10 +1555,11 @@ test!(recompile_space_in_name {
foo.root().move_into_the_past().unwrap();
assert_that(foo.cargo("build"),
execs().with_status(0).with_stdout(""));
});
}
#[cfg(unix)]
test!(ignore_bad_directories {
#[test]
fn ignore_bad_directories() {
use std::os::unix::prelude::*;
let foo = project("foo")
.file("Cargo.toml", r#"
@ -1531,9 +1580,10 @@ test!(ignore_bad_directories {
execs().with_status(0));
perms.set_mode(0o755);
fs::set_permissions(&dir, perms).unwrap();
});
}
test!(bad_cargo_config {
#[test]
fn bad_cargo_config() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1557,9 +1607,10 @@ Caused by:
[..].cargo[..]config:2:20-2:21 expected `=`, but found `i`
"));
});
}
test!(cargo_platform_specific_dependency {
#[test]
fn cargo_platform_specific_dependency() {
let host = ::rustc_host();
let p = project("foo")
.file("Cargo.toml", &format!(r#"
@ -1617,9 +1668,10 @@ test!(cargo_platform_specific_dependency {
assert_that(&p.bin("foo"), existing_file());
assert_that(p.cargo("test"),
execs().with_status(0));
});
}
test!(bad_platform_specific_dependency {
#[test]
fn bad_platform_specific_dependency() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1650,9 +1702,10 @@ test!(bad_platform_specific_dependency {
assert_that(p.cargo_process("build"),
execs().with_status(101));
});
}
test!(cargo_platform_specific_dependency_wrong_platform {
#[test]
fn cargo_platform_specific_dependency_wrong_platform() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1688,9 +1741,10 @@ test!(cargo_platform_specific_dependency_wrong_platform {
let mut lockfile = String::new();
File::open(&loc).unwrap().read_to_string(&mut lockfile).unwrap();
assert!(lockfile.contains("bar"))
});
}
test!(example_bin_same_name {
#[test]
fn example_bin_same_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1714,9 +1768,10 @@ test!(example_bin_same_name {
assert_that(&p.bin("foo"), is_not(existing_file()));
assert_that(&p.bin("examples/foo"), existing_file());
});
}
test!(compile_then_delete {
#[test]
fn compile_then_delete() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1735,9 +1790,10 @@ test!(compile_then_delete {
fs::remove_file(&p.bin("foo")).unwrap();
assert_that(p.cargo("run"),
execs().with_status(0));
});
}
test!(transitive_dependencies_not_available {
#[test]
fn transitive_dependencies_not_available() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1772,9 +1828,10 @@ test!(transitive_dependencies_not_available {
.with_stderr_contains("\
[..] can't find crate for `bbbbb`[..]
"));
});
}
test!(cyclic_deps_rejected {
#[test]
fn cyclic_deps_rejected() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1802,9 +1859,10 @@ test!(cyclic_deps_rejected {
.with_stderr("\
[ERROR] cyclic package dependency: package `foo v0.0.1 ([..])` depends on itself
"));
});
}
test!(predictable_filenames {
#[test]
fn predictable_filenames() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1825,9 +1883,10 @@ test!(predictable_filenames {
env::consts::DLL_SUFFIX);
assert_that(&p.root().join("target/debug").join(dylib_name),
existing_file());
});
}
test!(dashes_to_underscores {
#[test]
fn dashes_to_underscores() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1841,9 +1900,10 @@ test!(dashes_to_underscores {
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
assert_that(&p.bin("foo-bar"), existing_file());
});
}
test!(dashes_in_crate_name_bad {
#[test]
fn dashes_in_crate_name_bad() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1859,9 +1919,10 @@ test!(dashes_in_crate_name_bad {
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(101));
});
}
test!(rustc_env_var {
#[test]
fn rustc_env_var() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1882,9 +1943,10 @@ Caused by:
[..]
"));
assert_that(&p.bin("a"), is_not(existing_file()));
});
}
test!(filtering {
#[test]
fn filtering() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1909,9 +1971,10 @@ test!(filtering {
assert_that(&p.bin("b"), is_not(existing_file()));
assert_that(&p.bin("examples/a"), existing_file());
assert_that(&p.bin("examples/b"), is_not(existing_file()));
});
}
test!(ignore_dotfile {
#[test]
fn ignore_dotfile() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1925,9 +1988,10 @@ test!(ignore_dotfile {
assert_that(p.cargo("build"),
execs().with_status(0));
});
}
test!(ignore_dotdirs {
#[test]
fn ignore_dotdirs() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1942,9 +2006,10 @@ test!(ignore_dotdirs {
assert_that(p.cargo("build"),
execs().with_status(0));
});
}
test!(dotdir_root {
#[test]
fn dotdir_root() {
let p = ProjectBuilder::new("foo", root().join(".foo"))
.file("Cargo.toml", r#"
[package]
@ -1956,10 +2021,11 @@ test!(dotdir_root {
p.build();
assert_that(p.cargo("build"),
execs().with_status(0));
});
}
test!(custom_target_dir {
#[test]
fn custom_target_dir() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1999,9 +2065,10 @@ test!(custom_target_dir {
existing_file());
assert_that(&p.root().join("target/debug").join(&exe_name),
existing_file());
});
}
test!(rustc_no_trans {
#[test]
fn rustc_no_trans() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -2014,9 +2081,10 @@ test!(rustc_no_trans {
assert_that(p.cargo("rustc").arg("-v").arg("--").arg("-Zno-trans"),
execs().with_status(0));
});
}
test!(build_multiple_packages {
#[test]
fn build_multiple_packages() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -2076,9 +2144,10 @@ test!(build_multiple_packages {
assert_that(d2_path, existing_file());
assert_that(process(d2_path),
execs().with_stdout("d2"));
});
}
test!(invalid_spec {
#[test]
fn invalid_spec() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -2115,9 +2184,10 @@ test!(invalid_spec {
execs().with_status(101).with_stderr("\
[ERROR] package id specification `notAValidDep` matched no packages
"));
});
}
test!(manifest_with_bom_is_ok {
#[test]
fn manifest_with_bom_is_ok() {
let p = project("foo")
.file("Cargo.toml", "\u{FEFF}
[package]
@ -2128,9 +2198,10 @@ test!(manifest_with_bom_is_ok {
.file("src/lib.rs", "");
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}
test!(panic_abort_compiles_with_panic_abort {
#[test]
fn panic_abort_compiles_with_panic_abort() {
if !::is_nightly() {
return
}
@ -2148,4 +2219,4 @@ test!(panic_abort_compiles_with_panic_abort {
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0)
.with_stderr_contains("[..] -C panic=abort [..]"));
});
}

View File

@ -5,10 +5,8 @@ use support::{project, execs};
use support::paths::CargoPathExt;
use hamcrest::{assert_that, existing_file, existing_dir};
fn setup() {
}
test!(custom_build_script_failed {
#[test]
fn custom_build_script_failed() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -36,9 +34,10 @@ test!(custom_build_script_failed {
Process didn't exit successfully: `[..]build[..]build-script-build[..]` \
(exit code: 101)",
url = p.url())));
});
}
test!(custom_build_env_vars {
#[test]
fn custom_build_env_vars() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -107,9 +106,10 @@ test!(custom_build_env_vars {
assert_that(p.cargo_process("build").arg("--features").arg("bar_feat"),
execs().with_status(0));
});
}
test!(custom_build_script_wrong_rustc_flags {
#[test]
fn custom_build_script_wrong_rustc_flags() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -134,10 +134,11 @@ test!(custom_build_script_wrong_rustc_flags {
[ERROR] Only `-l` and `-L` flags are allowed in build script of `foo v0.5.0 ({})`: \
`-aaa -bbb`",
p.url())));
});
}
/*
test!(custom_build_script_rustc_flags {
#[test]
fn custom_build_script_rustc_flags() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -184,10 +185,11 @@ test!(custom_build_script_rustc_flags {
dir = p.root().display(),
url = p.url(),
)));
});
}
*/
test!(links_no_build_cmd {
#[test]
fn links_no_build_cmd() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -204,9 +206,10 @@ test!(links_no_build_cmd {
[ERROR] package `foo v0.5.0 (file://[..])` specifies that it links to `a` but does \
not have a custom build script
"));
});
}
test!(links_duplicates {
#[test]
fn links_duplicates() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -241,9 +244,10 @@ linked to by one package
[..] v0.5.0 (file://[..])
[..] v0.5.0 (file://[..])
"));
});
}
test!(overrides_and_links {
#[test]
fn overrides_and_links() {
let target = ::rustc_host();
let p = project("foo")
@ -294,9 +298,10 @@ test!(overrides_and_links {
[..]
[RUNNING] `rustc [..] --crate-name foo [..] -L foo -L bar[..]`
"));
});
}
test!(unused_overrides {
#[test]
fn unused_overrides() {
let target = ::rustc_host();
let p = project("foo")
@ -318,9 +323,10 @@ test!(unused_overrides {
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}
test!(links_passes_env_vars {
#[test]
fn links_passes_env_vars() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -362,9 +368,10 @@ test!(links_passes_env_vars {
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}
test!(only_rerun_build_script {
#[test]
fn only_rerun_build_script() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -392,9 +399,10 @@ test!(only_rerun_build_script {
[RUNNING] `[..]build-script-build[..]`
[RUNNING] `rustc [..] --crate-name foo [..]`
"));
});
}
test!(rebuild_continues_to_pass_env_vars {
#[test]
fn rebuild_continues_to_pass_env_vars() {
let a = project("a")
.file("Cargo.toml", r#"
[project]
@ -445,9 +453,10 @@ test!(rebuild_continues_to_pass_env_vars {
assert_that(p.cargo("build").arg("-v"),
execs().with_status(0));
});
}
test!(testing_and_such {
#[test]
fn testing_and_such() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -509,9 +518,10 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
[COMPILING] foo v0.5.0 (file://[..])
[RUNNING] `target[..]foo[..]`
"));
});
}
test!(propagation_of_l_flags {
#[test]
fn propagation_of_l_flags() {
let target = ::rustc_host();
let p = project("foo")
.file("Cargo.toml", r#"
@ -562,9 +572,10 @@ test!(propagation_of_l_flags {
[COMPILING] foo v0.5.0 (file://[..])
[RUNNING] `rustc [..] --crate-name foo [..] -L bar -L foo`
"));
});
}
test!(propagation_of_l_flags_new {
#[test]
fn propagation_of_l_flags_new() {
let target = ::rustc_host();
let p = project("foo")
.file("Cargo.toml", r#"
@ -615,9 +626,10 @@ test!(propagation_of_l_flags_new {
[COMPILING] foo v0.5.0 (file://[..])
[RUNNING] `rustc [..] --crate-name foo [..] -L bar -L foo`
"));
});
}
test!(build_deps_simple {
#[test]
fn build_deps_simple() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -651,9 +663,10 @@ test!(build_deps_simple {
[RUNNING] `[..]foo-[..]build-script-build[..]`
[RUNNING] `rustc [..] --crate-name foo [..]`
"));
});
}
test!(build_deps_not_for_normal {
#[test]
fn build_deps_not_for_normal() {
let target = ::rustc_host();
let p = project("foo")
.file("Cargo.toml", r#"
@ -690,9 +703,10 @@ error: aborting due to previous error
Caused by:
Process didn't exit successfully: [..]
"));
});
}
test!(build_cmd_with_a_build_cmd {
#[test]
fn build_cmd_with_a_build_cmd() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -752,9 +766,10 @@ test!(build_cmd_with_a_build_cmd {
--out-dir [..]target[..]debug --emit=dep-info,link \
-L [..]target[..]debug -L [..]target[..]deps`
"));
});
}
test!(out_dir_is_preserved {
#[test]
fn out_dir_is_preserved() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -800,9 +815,10 @@ test!(out_dir_is_preserved {
File::create(&p.root().join("foo")).unwrap();
assert_that(p.cargo("build").arg("-v"),
execs().with_status(0));
});
}
test!(output_separate_lines {
#[test]
fn output_separate_lines() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -828,9 +844,10 @@ test!(output_separate_lines {
[ERROR] could not find native static library [..]
[ERROR] Could not compile [..]
"));
});
}
test!(output_separate_lines_new {
#[test]
fn output_separate_lines_new() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -856,10 +873,11 @@ test!(output_separate_lines_new {
[ERROR] could not find native static library [..]
[ERROR] Could not compile [..]
"));
});
}
#[cfg(not(windows))] // FIXME(#867)
test!(code_generation {
#[test]
fn code_generation() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -902,9 +920,10 @@ Hello, World!
assert_that(p.cargo_process("test"),
execs().with_status(0));
});
}
test!(release_with_build_script {
#[test]
fn release_with_build_script() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -920,9 +939,10 @@ test!(release_with_build_script {
assert_that(p.cargo_process("build").arg("-v").arg("--release"),
execs().with_status(0));
});
}
test!(build_script_only {
#[test]
fn build_script_only() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -940,9 +960,10 @@ test!(build_script_only {
Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present"));
});
}
test!(shared_dep_with_a_build_script {
#[test]
fn shared_dep_with_a_build_script() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -980,9 +1001,10 @@ test!(shared_dep_with_a_build_script {
.file("b/src/lib.rs", "");
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}
test!(transitive_dep_host {
#[test]
fn transitive_dep_host() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1022,9 +1044,10 @@ test!(transitive_dep_host {
.file("b/src/lib.rs", "");
assert_that(p.cargo_process("build"),
execs().with_status(0));
});
}
test!(test_a_lib_with_a_build_command {
#[test]
fn test_a_lib_with_a_build_command() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1058,9 +1081,10 @@ test!(test_a_lib_with_a_build_command {
"#);
assert_that(p.cargo_process("test"),
execs().with_status(0));
});
}
test!(test_dev_dep_build_script {
#[test]
fn test_dev_dep_build_script() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1083,9 +1107,10 @@ test!(test_dev_dep_build_script {
.file("a/src/lib.rs", "");
assert_that(p.cargo_process("test"), execs().with_status(0));
});
}
test!(build_script_with_dynamic_native_dependency {
#[test]
fn build_script_with_dynamic_native_dependency() {
let build = project("builder")
.file("Cargo.toml", r#"
[package]
@ -1149,9 +1174,10 @@ test!(build_script_with_dynamic_native_dependency {
assert_that(foo.cargo_process("build").env("SRC", build.root()),
execs().with_status(0));
});
}
test!(profile_and_opt_level_set_correctly {
#[test]
fn profile_and_opt_level_set_correctly() {
let build = project("builder")
.file("Cargo.toml", r#"
[package]
@ -1172,9 +1198,10 @@ test!(profile_and_opt_level_set_correctly {
"#);
assert_that(build.cargo_process("bench"),
execs().with_status(0));
});
}
test!(build_script_with_lto {
#[test]
fn build_script_with_lto() {
let build = project("builder")
.file("Cargo.toml", r#"
[package]
@ -1193,9 +1220,10 @@ test!(build_script_with_lto {
"#);
assert_that(build.cargo_process("build"),
execs().with_status(0));
});
}
test!(test_duplicate_deps {
#[test]
fn test_duplicate_deps() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1227,9 +1255,10 @@ test!(test_duplicate_deps {
.file("bar/src/lib.rs", "pub fn do_nothing() {}");
assert_that(p.cargo_process("build"), execs().with_status(0));
});
}
test!(cfg_feedback {
#[test]
fn cfg_feedback() {
let build = project("builder")
.file("Cargo.toml", r#"
[package]
@ -1249,9 +1278,10 @@ test!(cfg_feedback {
"#);
assert_that(build.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}
test!(cfg_override {
#[test]
fn cfg_override() {
let target = ::rustc_host();
let p = project("foo")
@ -1275,9 +1305,10 @@ test!(cfg_override {
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}
test!(cfg_test {
#[test]
fn cfg_test() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1346,9 +1377,10 @@ test foo_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(cfg_doc {
#[test]
fn cfg_doc() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1390,9 +1422,10 @@ test!(cfg_doc {
assert_that(&p.root().join("target/doc"), existing_dir());
assert_that(&p.root().join("target/doc/foo/fn.foo.html"), existing_file());
assert_that(&p.root().join("target/doc/bar/fn.bar.html"), existing_file());
});
}
test!(cfg_override_test {
#[test]
fn cfg_override_test() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1460,9 +1493,10 @@ test foo_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(cfg_override_doc {
#[test]
fn cfg_override_doc() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1504,9 +1538,10 @@ test!(cfg_override_doc {
assert_that(&p.root().join("target/doc"), existing_dir());
assert_that(&p.root().join("target/doc/foo/fn.foo.html"), existing_file());
assert_that(&p.root().join("target/doc/bar/fn.bar.html"), existing_file());
});
}
test!(flags_go_into_tests {
#[test]
fn flags_go_into_tests() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1575,9 +1610,10 @@ running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(diamond_passes_args_only_once {
#[test]
fn diamond_passes_args_only_once() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1637,9 +1673,10 @@ test!(diamond_passes_args_only_once {
[COMPILING] foo v0.5.0 ([..]
[RUNNING] `[..]rlib -L native=test`
"));
});
}
test!(adding_an_override_invalidates {
#[test]
fn adding_an_override_invalidates() {
let target = ::rustc_host();
let p = project("foo")
.file("Cargo.toml", r#"
@ -1676,9 +1713,10 @@ test!(adding_an_override_invalidates {
[COMPILING] foo v0.5.0 ([..]
[RUNNING] `rustc [..] -L native=bar`
"));
});
}
test!(changing_an_override_invalidates {
#[test]
fn changing_an_override_invalidates() {
let target = ::rustc_host();
let p = project("foo")
.file("Cargo.toml", r#"
@ -1712,9 +1750,10 @@ test!(changing_an_override_invalidates {
[COMPILING] foo v0.5.0 ([..]
[RUNNING] `rustc [..] -L native=bar`
"));
});
}
test!(rebuild_only_on_explicit_paths {
#[test]
fn rebuild_only_on_explicit_paths() {
let p = project("a")
.file("Cargo.toml", r#"
[project]
@ -1792,10 +1831,11 @@ test!(rebuild_only_on_explicit_paths {
[RUNNING] `[..]build-script-build[..]`
[RUNNING] `rustc src[..]lib.rs [..]`
"));
});
}
test!(doctest_recieves_build_link_args {
#[test]
fn doctest_recieves_build_link_args() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1826,9 +1866,10 @@ test!(doctest_recieves_build_link_args {
.with_stderr_contains("\
[RUNNING] `rustdoc --test [..] --crate-name foo [..]-L native=bar[..]`
"));
});
}
test!(please_respect_the_dag {
#[test]
fn please_respect_the_dag() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1866,9 +1907,10 @@ test!(please_respect_the_dag {
.with_stderr_contains("\
[RUNNING] `rustc [..] -L native=foo -L native=bar[..]`
"));
});
}
test!(non_utf8_output {
#[test]
fn non_utf8_output() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1899,9 +1941,10 @@ test!(non_utf8_output {
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}
test!(custom_target_dir {
#[test]
fn custom_target_dir() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1929,9 +1972,10 @@ test!(custom_target_dir {
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}
test!(panic_abort_with_build_scripts {
#[test]
fn panic_abort_with_build_scripts() {
if !::is_nightly() {
return
}
@ -1971,4 +2015,4 @@ test!(panic_abort_with_build_scripts {
assert_that(p.cargo_process("build").arg("-v").arg("--release"),
execs().with_status(0));
});
}

View File

@ -8,10 +8,8 @@ use support::paths::{self, CargoPathExt};
use hamcrest::{assert_that,existing_file};
use cargo::util::process;
fn setup() {
}
test!(cargo_compile_simple_git_dep {
#[test]
fn cargo_compile_simple_git_dep() {
let project = project("foo");
let git_project = git::new("dep1", |project| {
project
@ -68,9 +66,10 @@ test!(cargo_compile_simple_git_dep {
assert_that(
process(&project.bin("foo")),
execs().with_stdout("hello world\n"));
});
}
test!(cargo_compile_git_dep_branch {
#[test]
fn cargo_compile_git_dep_branch() {
let project = project("foo");
let git_project = git::new("dep1", |project| {
project
@ -134,9 +133,10 @@ test!(cargo_compile_git_dep_branch {
assert_that(
process(&project.bin("foo")),
execs().with_stdout("hello world\n"));
});
}
test!(cargo_compile_git_dep_tag {
#[test]
fn cargo_compile_git_dep_tag() {
let project = project("foo");
let git_project = git::new("dep1", |project| {
project
@ -205,9 +205,10 @@ test!(cargo_compile_git_dep_tag {
assert_that(project.cargo("build"),
execs().with_status(0));
});
}
test!(cargo_compile_with_nested_paths {
#[test]
fn cargo_compile_with_nested_paths() {
let git_project = git::new("dep1", |project| {
project
.file("Cargo.toml", r#"
@ -279,9 +280,10 @@ test!(cargo_compile_with_nested_paths {
assert_that(process(&p.bin("parent")),
execs().with_stdout("hello world\n"));
});
}
test!(cargo_compile_with_meta_package {
#[test]
fn cargo_compile_with_meta_package() {
let git_project = git::new("meta-dep", |project| {
project
.file("dep1/Cargo.toml", r#"
@ -351,9 +353,10 @@ test!(cargo_compile_with_meta_package {
assert_that(process(&p.bin("parent")),
execs().with_stdout("this is dep1 this is dep2\n"));
});
}
test!(cargo_compile_with_short_ssh_git {
#[test]
fn cargo_compile_with_short_ssh_git() {
let url = "git@github.com:a/dep";
let project = project("project")
@ -383,9 +386,10 @@ test!(cargo_compile_with_short_ssh_git {
Caused by:
invalid url `{}`: relative URL without a base
", url)));
});
}
test!(two_revs_same_deps {
#[test]
fn two_revs_same_deps() {
let bar = git::new("meta-dep", |project| {
project.file("Cargo.toml", r#"
[package]
@ -452,9 +456,10 @@ test!(two_revs_same_deps {
execs().with_status(0));
assert_that(&foo.bin("foo"), existing_file());
assert_that(foo.process(&foo.bin("foo")), execs().with_status(0));
});
}
test!(recompilation {
#[test]
fn recompilation() {
let git_project = git::new("bar", |project| {
project
.file("Cargo.toml", r#"
@ -551,9 +556,10 @@ test!(recompilation {
assert_that(p.cargo("build"),
execs().with_stderr(&format!("[COMPILING] foo v0.5.0 ({})\n",
p.url())));
});
}
test!(update_with_shared_deps {
#[test]
fn update_with_shared_deps() {
let git_project = git::new("bar", |project| {
project
.file("Cargo.toml", r#"
@ -680,9 +686,10 @@ To learn more, run the command again with --verbose.
assert_that(p.cargo("update").arg("-p").arg("bar"),
execs().with_stderr(&format!("[UPDATING] git repository `{}`",
git_project.url())));
});
}
test!(dep_with_submodule {
#[test]
fn dep_with_submodule() {
let project = project("foo");
let git_project = git::new("dep1", |project| {
project
@ -724,9 +731,10 @@ test!(dep_with_submodule {
[UPDATING] git repository [..]
[COMPILING] dep1 [..]
[COMPILING] foo [..]").with_status(0));
});
}
test!(two_deps_only_update_one {
#[test]
fn two_deps_only_update_one() {
let project = project("foo");
let git1 = git::new("dep1", |project| {
project
@ -786,9 +794,10 @@ test!(two_deps_only_update_one {
.with_stderr(&format!("[UPDATING] git repository `{}`\n\
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]\n\
", git1.url())));
});
}
test!(stale_cached_version {
#[test]
fn stale_cached_version() {
let bar = git::new("meta-dep", |project| {
project.file("Cargo.toml", r#"
[package]
@ -856,9 +865,10 @@ test!(stale_cached_version {
[COMPILING] foo v0.0.0 ({foo})
", bar = bar.url(), foo = foo.url())));
assert_that(foo.process(&foo.bin("foo")), execs().with_status(0));
});
}
test!(dep_with_changed_submodule {
#[test]
fn dep_with_changed_submodule() {
let project = project("foo");
let git_project = git::new("dep1", |project| {
project
@ -947,9 +957,10 @@ test!(dep_with_changed_submodule {
[RUNNING] `target[..]foo[..]`\n")
.with_stdout("project3\n")
.with_status(0));
});
}
test!(dev_deps_with_testing {
#[test]
fn dev_deps_with_testing() {
let p2 = git::new("bar", |project| {
project.file("Cargo.toml", r#"
[package]
@ -1006,9 +1017,10 @@ test tests::foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(git_build_cmd_freshness {
#[test]
fn git_build_cmd_freshness() {
let foo = git::new("foo", |project| {
project.file("Cargo.toml", r#"
[package]
@ -1045,9 +1057,10 @@ test!(git_build_cmd_freshness {
assert_that(foo.cargo("build"),
execs().with_status(0)
.with_stdout(""));
});
}
test!(git_name_not_always_needed {
#[test]
fn git_name_not_always_needed() {
let p2 = git::new("bar", |project| {
project.file("Cargo.toml", r#"
[package]
@ -1084,9 +1097,10 @@ test!(git_name_not_always_needed {
[UPDATING] git repository `{bar}`
[COMPILING] foo v0.5.0 ({url})
", url = p.url(), bar = p2.url())));
});
}
test!(git_repo_changing_no_rebuild {
#[test]
fn git_repo_changing_no_rebuild() {
let bar = git::new("bar", |project| {
project.file("Cargo.toml", r#"
[package]
@ -1149,9 +1163,10 @@ test!(git_repo_changing_no_rebuild {
// even though the git repo has changed.
assert_that(p1.cargo("build"),
execs().with_stdout(""));
});
}
test!(git_dep_build_cmd {
#[test]
fn git_dep_build_cmd() {
let p = git::new("foo", |project| {
project.file("Cargo.toml", r#"
[project]
@ -1211,9 +1226,10 @@ test!(git_dep_build_cmd {
assert_that(process(&p.bin("foo")),
execs().with_stdout("1\n"));
});
}
test!(fetch_downloads {
#[test]
fn fetch_downloads() {
let bar = git::new("bar", |project| {
project.file("Cargo.toml", r#"
[package]
@ -1241,9 +1257,10 @@ test!(fetch_downloads {
assert_that(p.cargo("fetch"),
execs().with_status(0).with_stdout(""));
});
}
test!(warnings_in_git_dep {
#[test]
fn warnings_in_git_dep() {
let bar = git::new("bar", |project| {
project.file("Cargo.toml", r#"
[package]
@ -1273,9 +1290,10 @@ test!(warnings_in_git_dep {
bar.url(),
bar.url(),
p.url())));
});
}
test!(update_ambiguous {
#[test]
fn update_ambiguous() {
let foo1 = git::new("foo1", |project| {
project.file("Cargo.toml", r#"
[package]
@ -1332,9 +1350,10 @@ following:
foo:0.[..].0
foo:0.[..].0
"));
});
}
test!(update_one_dep_in_repo_with_many_deps {
#[test]
fn update_one_dep_in_repo_with_many_deps() {
let foo = git::new("foo", |project| {
project.file("Cargo.toml", r#"
[package]
@ -1372,9 +1391,10 @@ test!(update_one_dep_in_repo_with_many_deps {
.with_stderr(&format!("\
[UPDATING] git repository `{}`
", foo.url())));
});
}
test!(switch_deps_does_not_update_transitive {
#[test]
fn switch_deps_does_not_update_transitive() {
let transitive = git::new("transitive", |project| {
project.file("Cargo.toml", r#"
[package]
@ -1449,9 +1469,10 @@ test!(switch_deps_does_not_update_transitive {
[COMPILING] dep [..]
[COMPILING] project [..]
", dep2.url())));
});
}
test!(update_one_source_updates_all_packages_in_that_git_source {
#[test]
fn update_one_source_updates_all_packages_in_that_git_source() {
let dep = git::new("dep", |project| {
project.file("Cargo.toml", r#"
[package]
@ -1504,9 +1525,10 @@ test!(update_one_source_updates_all_packages_in_that_git_source {
.read_to_string(&mut lockfile).unwrap();
assert!(!lockfile.contains(&rev1.to_string()),
"{} in {}", rev1, lockfile);
});
}
test!(switch_sources {
#[test]
fn switch_sources() {
let a1 = git::new("a1", |project| {
project.file("Cargo.toml", r#"
[package]
@ -1573,9 +1595,10 @@ test!(switch_sources {
[COMPILING] b v0.5.0 ([..])
[COMPILING] project v0.5.0 ([..])
"));
});
}
test!(dont_require_submodules_are_checked_out {
#[test]
fn dont_require_submodules_are_checked_out() {
let project = project("foo");
let git1 = git::new("dep1", |p| {
p.file("Cargo.toml", r#"
@ -1603,9 +1626,10 @@ test!(dont_require_submodules_are_checked_out {
assert_that(git1.cargo("build").arg("-v").cwd(&dst),
execs().with_status(0));
});
}
test!(doctest_same_name {
#[test]
fn doctest_same_name() {
let a2 = git::new("a2", |p| {
p.file("Cargo.toml", r#"
[project]
@ -1645,9 +1669,10 @@ test!(doctest_same_name {
assert_that(p.cargo_process("test").arg("-v"),
execs().with_status(0));
});
}
test!(lints_are_suppressed {
#[test]
fn lints_are_suppressed() {
let a = git::new("a", |p| {
p.file("Cargo.toml", r#"
[project]
@ -1678,9 +1703,10 @@ test!(lints_are_suppressed {
[COMPILING] a v0.5.0 ([..])
[COMPILING] foo v0.0.1 ([..])
"));
});
}
test!(denied_lints_are_allowed {
#[test]
fn denied_lints_are_allowed() {
let enabled = super::RUSTC.with(|r| r.cap_lints);
if !enabled { return }
@ -1715,9 +1741,10 @@ test!(denied_lints_are_allowed {
[COMPILING] a v0.5.0 ([..])
[COMPILING] foo v0.0.1 ([..])
"));
});
}
test!(add_a_git_dep {
#[test]
fn add_a_git_dep() {
let git = git::new("git", |p| {
p.file("Cargo.toml", r#"
[project]
@ -1761,4 +1788,4 @@ test!(add_a_git_dep {
"#, git.url()).as_bytes()).unwrap();
assert_that(p.cargo("build"), execs().with_status(0));
});
}

View File

@ -6,10 +6,8 @@ use support::paths::{self, CargoPathExt};
use hamcrest::{assert_that, existing_file};
use cargo::util::process;
fn setup() {
}
test!(cargo_compile_with_nested_deps_shorthand {
#[test]
fn cargo_compile_with_nested_deps_shorthand() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -99,9 +97,10 @@ test!(cargo_compile_with_nested_deps_shorthand {
[COMPILING] foo v0.5.0 ({})\n",
p.url(),
p.url())));
});
}
test!(cargo_compile_with_root_dev_deps {
#[test]
fn cargo_compile_with_root_dev_deps() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -137,9 +136,10 @@ test!(cargo_compile_with_root_dev_deps {
p2.build();
assert_that(p.cargo_process("build"),
execs().with_status(101))
});
}
test!(cargo_compile_with_root_dev_deps_with_testing {
#[test]
fn cargo_compile_with_root_dev_deps_with_testing() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -184,9 +184,10 @@ running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(cargo_compile_with_transitive_dev_deps {
#[test]
fn cargo_compile_with_transitive_dev_deps() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -237,9 +238,10 @@ test!(cargo_compile_with_transitive_dev_deps {
assert_that(process(&p.bin("foo")),
execs().with_stdout("zoidberg\n"));
});
}
test!(no_rebuild_dependency {
#[test]
fn no_rebuild_dependency() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
@ -285,9 +287,10 @@ test!(no_rebuild_dependency {
[COMPILING] foo v0.5.0 ({})\n",
p.url(),
p.url())));
});
}
test!(deep_dependencies_trigger_rebuild {
#[test]
fn deep_dependencies_trigger_rebuild() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
@ -373,9 +376,10 @@ test!(deep_dependencies_trigger_rebuild {
p.url(),
p.url())));
});
}
test!(no_rebuild_two_deps {
#[test]
fn no_rebuild_two_deps() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
@ -435,9 +439,10 @@ test!(no_rebuild_two_deps {
assert_that(p.cargo("build"),
execs().with_stdout(""));
assert_that(&p.bin("foo"), existing_file());
});
}
test!(nested_deps_recompile {
#[test]
fn nested_deps_recompile() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -486,9 +491,10 @@ test!(nested_deps_recompile {
assert_that(p.cargo("build"),
execs().with_stderr(&format!("[COMPILING] foo v0.5.0 ({})\n",
p.url())));
});
}
test!(error_message_for_missing_manifest {
#[test]
fn error_message_for_missing_manifest() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -519,9 +525,10 @@ Caused by:
[..] (os error [..])
"));
});
}
test!(override_relative {
#[test]
fn override_relative() {
let bar = project("bar")
.file("Cargo.toml", r#"
[package]
@ -551,9 +558,10 @@ test!(override_relative {
bar.build();
assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0));
});
}
test!(override_self {
#[test]
fn override_self() {
let bar = project("bar")
.file("Cargo.toml", r#"
[package]
@ -587,9 +595,10 @@ test!(override_self {
bar.build();
assert_that(p.cargo_process("build"), execs().with_status(0));
});
}
test!(override_path_dep {
#[test]
fn override_path_dep() {
let bar = project("bar")
.file("p1/Cargo.toml", r#"
[package]
@ -631,9 +640,10 @@ test!(override_path_dep {
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
});
}
test!(path_dep_build_cmd {
#[test]
fn path_dep_build_cmd() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -703,9 +713,10 @@ test!(path_dep_build_cmd {
assert_that(process(&p.bin("foo")),
execs().with_stdout("1\n"));
});
}
test!(dev_deps_no_rebuild_lib {
#[test]
fn dev_deps_no_rebuild_lib() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -751,9 +762,10 @@ running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(custom_target_no_rebuild {
#[test]
fn custom_target_no_rebuild() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -795,9 +807,10 @@ test!(custom_target_no_rebuild {
.with_stderr("\
[COMPILING] b v0.5.0 ([..])
"));
});
}
test!(override_and_depend {
#[test]
fn override_and_depend() {
let p = project("foo")
.file("a/a1/Cargo.toml", r#"
[project]
@ -836,9 +849,10 @@ test!(override_and_depend {
[COMPILING] a1 v0.5.0 ([..])
[COMPILING] b v0.5.0 ([..])
"));
});
}
test!(missing_path_dependency {
#[test]
fn missing_path_dependency() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -863,4 +877,4 @@ Caused by:
Caused by:
[..] (os error [..])
"));
});
}

View File

@ -4,10 +4,8 @@ use std::env;
use support::{project, execs};
use hamcrest::assert_that;
fn setup() {
}
test!(plugin_to_the_max {
#[test]
fn plugin_to_the_max() {
if !::is_nightly() { return }
let foo = project("foo")
@ -82,9 +80,10 @@ test!(plugin_to_the_max {
execs().with_status(0));
assert_that(foo.cargo("doc"),
execs().with_status(0));
});
}
test!(plugin_with_dynamic_native_dependency {
#[test]
fn plugin_with_dynamic_native_dependency() {
if !::is_nightly() { return }
let build = project("builder")
@ -166,9 +165,10 @@ test!(plugin_with_dynamic_native_dependency {
assert_that(foo.cargo_process("build").env("SRC", &lib).arg("-v"),
execs().with_status(0));
});
}
test!(plugin_integration {
#[test]
fn plugin_integration() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -188,9 +188,10 @@ test!(plugin_integration {
assert_that(p.cargo_process("test").arg("-v"),
execs().with_status(0));
});
}
test!(doctest_a_plugin {
#[test]
fn doctest_a_plugin() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -221,10 +222,11 @@ test!(doctest_a_plugin {
assert_that(p.cargo_process("test").arg("-v"),
execs().with_status(0));
});
}
// See #1515
test!(native_plugin_dependency_with_custom_ar_linker {
#[test]
fn native_plugin_dependency_with_custom_ar_linker() {
let target = ::rustc_host();
let foo = project("foo")
@ -267,4 +269,4 @@ test!(native_plugin_dependency_with_custom_ar_linker {
[RUNNING] `rustc [..] -C ar=nonexistent-ar -C linker=nonexistent-linker [..]`
[ERROR] could not exec the linker [..]
"));
});
}

View File

@ -3,10 +3,8 @@ use std::fs::{self, File};
use support::{project, execs, paths};
use hamcrest::assert_that;
fn setup() {
}
test!(env_rustflags_normal_source {
#[test]
fn env_rustflags_normal_source() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -37,9 +35,10 @@ test!(env_rustflags_normal_source {
execs().with_status(101));
assert_that(p.cargo("bench").env("RUSTFLAGS", "-Z bogus"),
execs().with_status(101));
});
}
test!(env_rustflags_build_script {
#[test]
fn env_rustflags_build_script() {
// RUSTFLAGS should be passed to rustc for build scripts
// when --target is not specified.
// In this test if --cfg foo is passed the build will fail.
@ -60,9 +59,10 @@ test!(env_rustflags_build_script {
assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"),
execs().with_status(0));
});
}
test!(env_rustflags_build_script_dep {
#[test]
fn env_rustflags_build_script_dep() {
// RUSTFLAGS should be passed to rustc for build scripts
// when --target is not specified.
// In this test if --cfg foo is not passed the build will fail.
@ -96,9 +96,10 @@ test!(env_rustflags_build_script_dep {
assert_that(foo.cargo("build").env("RUSTFLAGS", "--cfg foo"),
execs().with_status(0));
});
}
test!(env_rustflags_plugin {
#[test]
fn env_rustflags_plugin() {
// RUSTFLAGS should be passed to rustc for plugins
// when --target is not specified.
// In this test if --cfg foo is not passed the build will fail.
@ -121,9 +122,10 @@ test!(env_rustflags_plugin {
assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"),
execs().with_status(0));
});
}
test!(env_rustflags_plugin_dep {
#[test]
fn env_rustflags_plugin_dep() {
// RUSTFLAGS should be passed to rustc for plugins
// when --target is not specified.
// In this test if --cfg foo is not passed the build will fail.
@ -162,9 +164,10 @@ test!(env_rustflags_plugin_dep {
assert_that(foo.cargo("build").env("RUSTFLAGS", "--cfg foo"),
execs().with_status(0));
});
}
test!(env_rustflags_normal_source_with_target {
#[test]
fn env_rustflags_normal_source_with_target() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -199,9 +202,10 @@ test!(env_rustflags_normal_source_with_target {
assert_that(p.cargo("bench").env("RUSTFLAGS", "-Z bogus")
.arg("--target").arg(host),
execs().with_status(101));
});
}
test!(env_rustflags_build_script_with_target {
#[test]
fn env_rustflags_build_script_with_target() {
// RUSTFLAGS should not be passed to rustc for build scripts
// when --target is specified.
// In this test if --cfg foo is passed the build will fail.
@ -224,9 +228,10 @@ test!(env_rustflags_build_script_with_target {
assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo")
.arg("--target").arg(host),
execs().with_status(0));
});
}
test!(env_rustflags_build_script_dep_with_target {
#[test]
fn env_rustflags_build_script_dep_with_target() {
// RUSTFLAGS should not be passed to rustc for build scripts
// when --target is specified.
// In this test if --cfg foo is passed the build will fail.
@ -262,9 +267,10 @@ test!(env_rustflags_build_script_dep_with_target {
assert_that(foo.cargo("build").env("RUSTFLAGS", "--cfg foo")
.arg("--target").arg(host),
execs().with_status(0));
});
}
test!(env_rustflags_plugin_with_target {
#[test]
fn env_rustflags_plugin_with_target() {
// RUSTFLAGS should not be passed to rustc for plugins
// when --target is specified.
// In this test if --cfg foo is passed the build will fail.
@ -289,9 +295,10 @@ test!(env_rustflags_plugin_with_target {
assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo")
.arg("--target").arg(host),
execs().with_status(0));
});
}
test!(env_rustflags_plugin_dep_with_target {
#[test]
fn env_rustflags_plugin_dep_with_target() {
// RUSTFLAGS should not be passed to rustc for plugins
// when --target is specified.
// In this test if --cfg foo is passed the build will fail.
@ -332,9 +339,10 @@ test!(env_rustflags_plugin_dep_with_target {
assert_that(foo.cargo("build").env("RUSTFLAGS", "--cfg foo")
.arg("--target").arg(host),
execs().with_status(0));
});
}
test!(env_rustflags_recompile {
#[test]
fn env_rustflags_recompile() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -349,9 +357,10 @@ test!(env_rustflags_recompile {
// Setting RUSTFLAGS forces a recompile
assert_that(p.cargo("build").env("RUSTFLAGS", "-Z bogus"),
execs().with_status(101));
});
}
test!(env_rustflags_recompile2 {
#[test]
fn env_rustflags_recompile2() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -366,9 +375,10 @@ test!(env_rustflags_recompile2 {
// Setting RUSTFLAGS forces a recompile
assert_that(p.cargo("build").env("RUSTFLAGS", "-Z bogus"),
execs().with_status(101));
});
}
test!(env_rustflags_no_recompile {
#[test]
fn env_rustflags_no_recompile() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -382,9 +392,10 @@ test!(env_rustflags_no_recompile {
execs().with_status(0));
assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"),
execs().with_stdout("").with_status(0));
});
}
test!(build_rustflags_normal_source {
#[test]
fn build_rustflags_normal_source() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -418,9 +429,10 @@ test!(build_rustflags_normal_source {
execs().with_status(101));
assert_that(p.cargo("bench"),
execs().with_status(101));
});
}
test!(build_rustflags_build_script {
#[test]
fn build_rustflags_build_script() {
// RUSTFLAGS should be passed to rustc for build scripts
// when --target is not specified.
// In this test if --cfg foo is passed the build will fail.
@ -445,9 +457,10 @@ test!(build_rustflags_build_script {
assert_that(p.cargo("build"),
execs().with_status(0));
});
}
test!(build_rustflags_build_script_dep {
#[test]
fn build_rustflags_build_script_dep() {
// RUSTFLAGS should be passed to rustc for build scripts
// when --target is not specified.
// In this test if --cfg foo is not passed the build will fail.
@ -485,9 +498,10 @@ test!(build_rustflags_build_script_dep {
assert_that(foo.cargo("build"),
execs().with_status(0));
});
}
test!(build_rustflags_plugin {
#[test]
fn build_rustflags_plugin() {
// RUSTFLAGS should be passed to rustc for plugins
// when --target is not specified.
// In this test if --cfg foo is not passed the build will fail.
@ -514,9 +528,10 @@ test!(build_rustflags_plugin {
assert_that(p.cargo("build"),
execs().with_status(0));
});
}
test!(build_rustflags_plugin_dep {
#[test]
fn build_rustflags_plugin_dep() {
// RUSTFLAGS should be passed to rustc for plugins
// when --target is not specified.
// In this test if --cfg foo is not passed the build will fail.
@ -559,9 +574,10 @@ test!(build_rustflags_plugin_dep {
assert_that(foo.cargo("build"),
execs().with_status(0));
});
}
test!(build_rustflags_normal_source_with_target {
#[test]
fn build_rustflags_normal_source_with_target() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -600,9 +616,10 @@ test!(build_rustflags_normal_source_with_target {
assert_that(p.cargo("bench")
.arg("--target").arg(host),
execs().with_status(101));
});
}
test!(build_rustflags_build_script_with_target {
#[test]
fn build_rustflags_build_script_with_target() {
// RUSTFLAGS should not be passed to rustc for build scripts
// when --target is specified.
// In this test if --cfg foo is passed the build will fail.
@ -629,9 +646,10 @@ test!(build_rustflags_build_script_with_target {
assert_that(p.cargo("build")
.arg("--target").arg(host),
execs().with_status(0));
});
}
test!(build_rustflags_build_script_dep_with_target {
#[test]
fn build_rustflags_build_script_dep_with_target() {
// RUSTFLAGS should not be passed to rustc for build scripts
// when --target is specified.
// In this test if --cfg foo is passed the build will fail.
@ -671,9 +689,10 @@ test!(build_rustflags_build_script_dep_with_target {
assert_that(foo.cargo("build")
.arg("--target").arg(host),
execs().with_status(0));
});
}
test!(build_rustflags_plugin_with_target {
#[test]
fn build_rustflags_plugin_with_target() {
// RUSTFLAGS should not be passed to rustc for plugins
// when --target is specified.
// In this test if --cfg foo is passed the build will fail.
@ -702,9 +721,10 @@ test!(build_rustflags_plugin_with_target {
assert_that(p.cargo("build")
.arg("--target").arg(host),
execs().with_status(0));
});
}
test!(build_rustflags_plugin_dep_with_target {
#[test]
fn build_rustflags_plugin_dep_with_target() {
// RUSTFLAGS should not be passed to rustc for plugins
// when --target is specified.
// In this test if --cfg foo is passed the build will fail.
@ -749,9 +769,10 @@ test!(build_rustflags_plugin_dep_with_target {
assert_that(foo.cargo("build")
.arg("--target").arg(host),
execs().with_status(0));
});
}
test!(build_rustflags_recompile {
#[test]
fn build_rustflags_recompile() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -776,9 +797,10 @@ test!(build_rustflags_recompile {
assert_that(p.cargo("build"),
execs().with_status(101));
});
}
test!(build_rustflags_recompile2 {
#[test]
fn build_rustflags_recompile2() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -803,9 +825,10 @@ test!(build_rustflags_recompile2 {
assert_that(p.cargo("build"),
execs().with_status(101));
});
}
test!(build_rustflags_no_recompile {
#[test]
fn build_rustflags_no_recompile() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -823,4 +846,4 @@ test!(build_rustflags_no_recompile {
execs().with_status(0));
assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"),
execs().with_stdout("").with_status(0));
});
}

View File

@ -13,15 +13,14 @@ use support::git;
use support::registry::Package;
use test_cargo_install::{cargo_home, has_installed_exe};
fn setup() {}
fn pkg(name: &str, vers: &str) {
Package::new(name, vers)
.file("src/main.rs", "fn main() {{}}")
.publish();
}
test!(multiple_installs {
#[test]
fn multiple_installs() {
let p = project("foo")
.file("a/Cargo.toml", r#"
[package]
@ -56,9 +55,10 @@ test!(multiple_installs {
assert_that(cargo_home(), has_installed_exe("foo"));
assert_that(cargo_home(), has_installed_exe("bar"));
});
}
test!(concurrent_installs {
#[test]
fn concurrent_installs() {
const LOCKED_BUILD: &'static str = "waiting for file lock on build directory";
pkg("foo", "0.0.1");
@ -84,9 +84,10 @@ test!(concurrent_installs {
assert_that(cargo_home(), has_installed_exe("foo"));
assert_that(cargo_home(), has_installed_exe("bar"));
});
}
test!(one_install_should_be_bad {
#[test]
fn one_install_should_be_bad() {
let p = project("foo")
.file("a/Cargo.toml", r#"
[package]
@ -125,9 +126,10 @@ warning: be sure to add `[..]` to your PATH [..]
"));
assert_that(cargo_home(), has_installed_exe("foo"));
});
}
test!(multiple_registry_fetches {
#[test]
fn multiple_registry_fetches() {
let mut pkg = Package::new("bar", "1.0.2");
for i in 0..10 {
let name = format!("foo{}", i);
@ -179,9 +181,10 @@ test!(multiple_registry_fetches {
existing_file());
assert_that(&p.root().join("b/target/debug").join(format!("bar{}", suffix)),
existing_file());
});
}
test!(git_same_repo_different_tags {
#[test]
fn git_same_repo_different_tags() {
let a = git::new("dep", |project| {
project.file("Cargo.toml", r#"
[project]
@ -237,9 +240,10 @@ test!(git_same_repo_different_tags {
assert_that(a, execs().with_status(0));
assert_that(b, execs().with_status(0));
});
}
test!(git_same_branch_different_revs {
#[test]
fn git_same_branch_different_revs() {
let a = git::new("dep", |project| {
project.file("Cargo.toml", r#"
[project]
@ -301,9 +305,10 @@ test!(git_same_branch_different_revs {
assert_that(a, execs().with_status(0));
assert_that(b, execs().with_status(0));
});
}
test!(same_project {
#[test]
fn same_project() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -329,11 +334,12 @@ test!(same_project {
assert_that(a, execs().with_status(0));
assert_that(b, execs().with_status(0));
});
}
// Make sure that if Cargo dies while holding a lock that it's released and the
// next Cargo to come in will take over cleanly.
test!(killing_cargo_releases_the_lock {
#[test]
fn killing_cargo_releases_the_lock() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -383,9 +389,10 @@ test!(killing_cargo_releases_the_lock {
// We killed `a`, so it shouldn't succeed, but `b` should have succeeded.
assert!(!a.status.success());
assert_that(b, execs().with_status(0));
});
}
test!(debug_release_ok {
#[test]
fn debug_release_ok() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -415,4 +422,4 @@ test!(debug_release_ok {
assert_that(b, execs().with_status(0).with_stderr("\
[COMPILING] foo v0.0.0 [..]
"));
});
}

View File

@ -1,10 +1,8 @@
use support::{project, execs};
use hamcrest::assert_that;
fn setup() {
}
test!(read_env_vars_for_config {
#[test]
fn read_env_vars_for_config() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -23,4 +21,4 @@ test!(read_env_vars_for_config {
assert_that(p.cargo_process("build").env("CARGO_BUILD_JOBS", "100"),
execs().with_status(0));
});
}

View File

@ -4,9 +4,6 @@ use support::{project, execs, basic_bin_manifest};
use hamcrest::{assert_that, existing_file};
use cargo::util::process;
fn setup() {
}
fn disabled() -> bool {
// First, disable if ./configure requested so
match env::var("CFG_DISABLE_CROSS_TESTS") {
@ -60,7 +57,8 @@ fn host() -> String {
format!("{}-{}", arch, platform)
}
test!(simple_cross {
#[test]
fn simple_cross() {
if disabled() { return }
let p = project("foo")
@ -90,9 +88,10 @@ test!(simple_cross {
assert_that(process(&p.target_bin(&target, "foo")),
execs().with_status(0));
});
}
test!(simple_cross_config {
#[test]
fn simple_cross_config() {
if disabled() { return }
let p = project("foo")
@ -126,9 +125,10 @@ test!(simple_cross_config {
assert_that(process(&p.target_bin(&target, "foo")),
execs().with_status(0));
});
}
test!(simple_deps {
#[test]
fn simple_deps() {
if disabled() { return }
let p = project("foo")
@ -162,9 +162,10 @@ test!(simple_deps {
assert_that(process(&p.target_bin(&target, "foo")),
execs().with_status(0));
});
}
test!(plugin_deps {
#[test]
fn plugin_deps() {
if disabled() { return }
if !::is_nightly() { return }
@ -239,9 +240,10 @@ test!(plugin_deps {
assert_that(process(&foo.target_bin(&target, "foo")),
execs().with_status(0));
});
}
test!(plugin_to_the_max {
#[test]
fn plugin_to_the_max() {
if disabled() { return }
if !::is_nightly() { return }
@ -324,9 +326,10 @@ test!(plugin_to_the_max {
assert_that(process(&foo.target_bin(&target, "foo")),
execs().with_status(0));
});
}
test!(linker_and_ar {
#[test]
fn linker_and_ar() {
if disabled() { return }
let target = alternate();
@ -361,9 +364,10 @@ test!(linker_and_ar {
url = p.url(),
target = target,
)));
});
}
test!(plugin_with_extra_dylib_dep {
#[test]
fn plugin_with_extra_dylib_dep() {
if disabled() { return }
if !::is_nightly() { return }
@ -428,9 +432,10 @@ test!(plugin_with_extra_dylib_dep {
let target = alternate();
assert_that(foo.cargo_process("build").arg("--target").arg(&target),
execs().with_status(0));
});
}
test!(cross_tests {
#[test]
fn cross_tests() {
if disabled() { return }
let p = project("foo")
@ -477,9 +482,10 @@ test test_foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(no_cross_doctests {
#[test]
fn no_cross_doctests() {
if disabled() { return }
let p = project("foo")
@ -521,9 +527,10 @@ test!(no_cross_doctests {
[COMPILING] foo v0.0.0 ({foo})
[RUNNING] target[..]{triple}[..]foo-[..]
", foo = p.url(), triple = target)));
});
}
test!(simple_cargo_run {
#[test]
fn simple_cargo_run() {
if disabled() { return }
let p = project("foo")
@ -543,9 +550,10 @@ test!(simple_cargo_run {
let target = alternate();
assert_that(p.cargo_process("run").arg("--target").arg(&target),
execs().with_status(0));
});
}
test!(cross_with_a_build_script {
#[test]
fn cross_with_a_build_script() {
if disabled() { return }
let target = alternate();
@ -588,9 +596,10 @@ test!(cross_with_a_build_script {
[RUNNING] `rustc src[..]main.rs [..] --target {target} [..]`
", target = target,
dir = p.root().display())));
});
}
test!(build_script_needed_for_host_and_target {
#[test]
fn build_script_needed_for_host_and_target() {
if disabled() { return }
let target = alternate();
@ -673,9 +682,10 @@ test!(build_script_needed_for_host_and_target {
.with_stderr_contains(&format!("\
[RUNNING] `rustc src[..]main.rs [..] --target {target} [..] \
-L /path/to/{target}`", target = target)));
});
}
test!(build_deps_for_the_right_arch {
#[test]
fn build_deps_for_the_right_arch() {
if disabled() { return }
let p = project("foo")
@ -714,9 +724,10 @@ test!(build_deps_for_the_right_arch {
let target = alternate();
assert_that(p.cargo_process("build").arg("--target").arg(&target).arg("-v"),
execs().with_status(0));
});
}
test!(build_script_only_host {
#[test]
fn build_script_only_host() {
if disabled() { return }
let p = project("foo")
@ -755,9 +766,10 @@ test!(build_script_only_host {
let target = alternate();
assert_that(p.cargo_process("build").arg("--target").arg(&target).arg("-v"),
execs().with_status(0));
});
}
test!(plugin_build_script_right_arch {
#[test]
fn plugin_build_script_right_arch() {
if disabled() { return }
let p = project("foo")
.file("Cargo.toml", r#"
@ -782,9 +794,10 @@ test!(plugin_build_script_right_arch {
[RUNNING] `[..]build-script-build[..]`
[RUNNING] `rustc src[..]lib.rs [..]`
"));
});
}
test!(build_script_with_platform_specific_dependencies {
#[test]
fn build_script_with_platform_specific_dependencies() {
if disabled() { return }
let target = alternate();
@ -832,9 +845,10 @@ test!(build_script_with_platform_specific_dependencies {
[RUNNING] `{dir}[..]target[..]build[..]foo-[..]build-script-build`
[RUNNING] `rustc src[..]lib.rs [..] --target {target} [..]`
", dir = p.root().display(), target = target)));
});
}
test!(platform_specific_dependencies_do_not_leak {
#[test]
fn platform_specific_dependencies_do_not_leak() {
if disabled() { return }
let target = alternate();
@ -877,9 +891,10 @@ test!(platform_specific_dependencies_do_not_leak {
execs().with_status(101)
.with_stderr_contains("\
[..] error: can't find crate for `d2`[..]"));
});
}
test!(platform_specific_variables_reflected_in_build_scripts {
#[test]
fn platform_specific_variables_reflected_in_build_scripts() {
if disabled() { return }
let target = alternate();
@ -944,4 +959,4 @@ test!(platform_specific_variables_reflected_in_build_scripts {
assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0));
assert_that(p.cargo_process("build").arg("-v").arg("--target").arg(&target),
execs().with_status(0));
});
}

View File

@ -4,8 +4,6 @@ use std::process::{Stdio, Child};
use support::project;
fn setup() {}
#[cfg(unix)]
fn enabled() -> bool {
true
@ -46,7 +44,8 @@ fn enabled() -> bool {
}
}
test!(ctrl_c_kills_everyone {
#[test]
fn ctrl_c_kills_everyone() {
if !enabled() {
return
}
@ -90,7 +89,7 @@ test!(ctrl_c_kills_everyone {
Ok(n) => assert_eq!(n, 0),
Err(e) => assert_eq!(e.kind(), io::ErrorKind::ConnectionReset),
}
});
}
#[cfg(unix)]
fn ctrl_c(child: &mut Child) {

View File

@ -4,10 +4,8 @@ use std::fs;
use support::{project, execs, path2url};
use hamcrest::{assert_that, existing_file, existing_dir, is_not};
fn setup() {
}
test!(simple {
#[test]
fn simple() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -29,9 +27,10 @@ test!(simple {
dir = path2url(p.root()))));
assert_that(&p.root().join("target/doc"), existing_dir());
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
});
}
test!(doc_no_libs {
#[test]
fn doc_no_libs() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -49,9 +48,10 @@ test!(doc_no_libs {
assert_that(p.cargo_process("doc"),
execs().with_status(0));
});
}
test!(doc_twice {
#[test]
fn doc_twice() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -71,9 +71,10 @@ test!(doc_twice {
assert_that(p.cargo("doc"),
execs().with_status(0).with_stdout(""))
});
}
test!(doc_deps {
#[test]
fn doc_deps() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -117,9 +118,10 @@ test!(doc_deps {
assert_that(&p.root().join("target/doc"), existing_dir());
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
assert_that(&p.root().join("target/doc/bar/index.html"), existing_file());
});
}
test!(doc_no_deps {
#[test]
fn doc_no_deps() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -154,9 +156,10 @@ test!(doc_no_deps {
assert_that(&p.root().join("target/doc"), existing_dir());
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
assert_that(&p.root().join("target/doc/bar/index.html"), is_not(existing_file()));
});
}
test!(doc_only_bin {
#[test]
fn doc_only_bin() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -187,9 +190,10 @@ test!(doc_only_bin {
assert_that(&p.root().join("target/doc"), existing_dir());
assert_that(&p.root().join("target/doc/bar/index.html"), existing_file());
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
});
}
test!(doc_lib_bin_same_name {
#[test]
fn doc_lib_bin_same_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -206,9 +210,10 @@ test!(doc_lib_bin_same_name {
[ERROR] cannot document a package where a library and a binary have the same name. \
Consider renaming one or marking the target as `doc = false`
"));
});
}
test!(doc_dash_p {
#[test]
fn doc_dash_p() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -245,9 +250,10 @@ test!(doc_dash_p {
[..] b v0.0.1 (file://[..])
[DOCUMENTING] a v0.0.1 (file://[..])
"));
});
}
test!(doc_same_name {
#[test]
fn doc_same_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -262,9 +268,10 @@ test!(doc_same_name {
assert_that(p.cargo_process("doc"),
execs().with_status(0));
});
}
test!(doc_target {
#[test]
fn doc_target() {
const TARGET: &'static str = "arm-unknown-linux-gnueabihf";
if !::is_nightly() { return }
@ -289,9 +296,10 @@ test!(doc_target {
execs().with_status(0));
assert_that(&p.root().join(&format!("target/{}/doc", TARGET)), existing_dir());
assert_that(&p.root().join(&format!("target/{}/doc/foo/index.html", TARGET)), existing_file());
});
}
test!(target_specific_not_documented {
#[test]
fn target_specific_not_documented() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -313,9 +321,10 @@ test!(target_specific_not_documented {
assert_that(p.cargo_process("doc"),
execs().with_status(0));
});
}
test!(output_not_captured {
#[test]
fn output_not_captured() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -345,9 +354,10 @@ test!(output_not_captured {
let stderr = str::from_utf8(&output.stderr).unwrap();
assert!(stderr.contains(""), "no snowman\n{}", stderr);
assert!(stderr.contains("unknown start of token"), "no message\n{}", stderr);
});
}
test!(target_specific_documented {
#[test]
fn target_specific_documented() {
let p = project("foo")
.file("Cargo.toml", &format!(r#"
[package]
@ -379,9 +389,10 @@ test!(target_specific_documented {
assert_that(p.cargo_process("doc"),
execs().with_status(0));
});
}
test!(no_document_build_deps {
#[test]
fn no_document_build_deps() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -410,9 +421,10 @@ test!(no_document_build_deps {
assert_that(p.cargo_process("doc"),
execs().with_status(0));
});
}
test!(doc_release {
#[test]
fn doc_release() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -430,9 +442,10 @@ test!(doc_release {
[DOCUMENTING] foo v0.0.1 ([..])
[RUNNING] `rustdoc src[..]lib.rs [..]`
"));
});
}
test!(doc_multiple_deps {
#[test]
fn doc_multiple_deps() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -478,9 +491,10 @@ test!(doc_multiple_deps {
assert_that(&p.root().join("target/doc"), existing_dir());
assert_that(&p.root().join("target/doc/bar/index.html"), existing_file());
assert_that(&p.root().join("target/doc/baz/index.html"), existing_file());
});
}
test!(features {
#[test]
fn features() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -521,9 +535,10 @@ test!(features {
assert_that(&p.root().join("target/doc"), existing_dir());
assert_that(&p.root().join("target/doc/foo/fn.foo.html"), existing_file());
assert_that(&p.root().join("target/doc/bar/fn.bar.html"), existing_file());
});
}
test!(rerun_when_dir_removed {
#[test]
fn rerun_when_dir_removed() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -544,9 +559,10 @@ test!(rerun_when_dir_removed {
assert_that(p.cargo_process("doc"),
execs().with_status(0));
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
});
}
test!(document_only_lib {
#[test]
fn document_only_lib() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -568,4 +584,4 @@ test!(document_only_lib {
assert_that(p.cargo_process("doc").arg("--lib"),
execs().with_status(0));
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
});
}

View File

@ -5,10 +5,8 @@ use support::{project, execs};
use support::paths::CargoPathExt;
use hamcrest::assert_that;
fn setup() {
}
test!(invalid1 {
#[test]
fn invalid1() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -28,9 +26,10 @@ test!(invalid1 {
Caused by:
Feature `bar` includes `baz` which is neither a dependency nor another feature
"));
});
}
test!(invalid2 {
#[test]
fn invalid2() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -53,9 +52,10 @@ test!(invalid2 {
Caused by:
Features and dependencies cannot have the same name: `bar`
"));
});
}
test!(invalid3 {
#[test]
fn invalid3() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -79,9 +79,10 @@ Caused by:
Feature `bar` depends on `baz` which is not an optional dependency.
Consider adding `optional = true` to the dependency
"));
});
}
test!(invalid4 {
#[test]
fn invalid4() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -118,9 +119,10 @@ test!(invalid4 {
execs().with_status(101).with_stderr("\
[ERROR] Package `foo v0.0.1 ([..])` does not have these features: `test`
"));
});
}
test!(invalid5 {
#[test]
fn invalid5() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -141,9 +143,10 @@ test!(invalid5 {
Caused by:
Dev-dependencies are not allowed to be optional: `bar`
"));
});
}
test!(invalid6 {
#[test]
fn invalid6() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -163,9 +166,10 @@ test!(invalid6 {
Caused by:
Feature `foo` requires `bar` which is not an optional dependency
"));
});
}
test!(invalid7 {
#[test]
fn invalid7() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -186,9 +190,10 @@ test!(invalid7 {
Caused by:
Feature `foo` requires `bar` which is not an optional dependency
"));
});
}
test!(invalid8 {
#[test]
fn invalid8() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -213,9 +218,10 @@ test!(invalid8 {
execs().with_status(101).with_stderr("\
[ERROR] features in dependencies cannot enable features in other dependencies: `foo/bar`
"));
});
}
test!(no_feature_doesnt_build {
#[test]
fn no_feature_doesnt_build() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -257,9 +263,10 @@ test!(no_feature_doesnt_build {
", dir = p.url())));
assert_that(p.process(&p.bin("foo")),
execs().with_status(0).with_stdout("bar\n"));
});
}
test!(default_feature_pulled_in {
#[test]
fn default_feature_pulled_in() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -304,9 +311,10 @@ test!(default_feature_pulled_in {
", dir = p.url())));
assert_that(p.process(&p.bin("foo")),
execs().with_status(0).with_stdout(""));
});
}
test!(cyclic_feature {
#[test]
fn cyclic_feature() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -323,9 +331,10 @@ test!(cyclic_feature {
execs().with_status(101).with_stderr("\
[ERROR] Cyclic feature dependency: feature `default` depends on itself
"));
});
}
test!(cyclic_feature2 {
#[test]
fn cyclic_feature2() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -343,9 +352,10 @@ test!(cyclic_feature2 {
execs().with_status(101).with_stderr("\
[ERROR] Cyclic feature dependency: feature `[..]` depends on itself
"));
});
}
test!(groups_on_groups_on_groups {
#[test]
fn groups_on_groups_on_groups() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -397,9 +407,10 @@ test!(groups_on_groups_on_groups {
[COMPILING] ba[..] v0.0.1 ({dir}/ba[..])
[COMPILING] foo v0.0.1 ({dir})
", dir = p.url())));
});
}
test!(many_cli_features {
#[test]
fn many_cli_features() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -441,9 +452,10 @@ test!(many_cli_features {
[COMPILING] ba[..] v0.0.1 ({dir}/ba[..])
[COMPILING] foo v0.0.1 ({dir})
", dir = p.url())));
});
}
test!(union_features {
#[test]
fn union_features() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -502,9 +514,10 @@ test!(union_features {
[COMPILING] d1 v0.0.1 ({dir}/d1)
[COMPILING] foo v0.0.1 ({dir})
", dir = p.url())));
});
}
test!(many_features_no_rebuilds {
#[test]
fn many_features_no_rebuilds() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -542,10 +555,11 @@ test!(many_features_no_rebuilds {
[FRESH] a v0.1.0 ([..]/a)
[FRESH] b v0.1.0 ([..])
"));
});
}
// Tests that all cmd lines work with `--features ""`
test!(empty_features {
#[test]
fn empty_features() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -557,10 +571,11 @@ test!(empty_features {
assert_that(p.cargo_process("build").arg("--features").arg(""),
execs().with_status(0));
});
}
// Tests that all cmd lines work with `--features ""`
test!(transitive_features {
#[test]
fn transitive_features() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -594,9 +609,10 @@ test!(transitive_features {
assert_that(p.cargo_process("build").arg("--features").arg("foo"),
execs().with_status(0));
});
}
test!(everything_in_the_lockfile {
#[test]
fn everything_in_the_lockfile() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -653,9 +669,10 @@ test!(everything_in_the_lockfile {
assert!(lockfile.contains(r#"name = "d1""#), "d1 not found\n{}", lockfile);
assert!(lockfile.contains(r#"name = "d2""#), "d2 not found\n{}", lockfile);
assert!(lockfile.contains(r#"name = "d3""#), "d3 not found\n{}", lockfile);
});
}
test!(no_rebuild_when_frobbing_default_feature {
#[test]
fn no_rebuild_when_frobbing_default_feature() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -693,9 +710,10 @@ test!(no_rebuild_when_frobbing_default_feature {
assert_that(p.cargo_process("build"), execs().with_status(0));
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
});
}
test!(unions_work_with_no_default_features {
#[test]
fn unions_work_with_no_default_features() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -739,9 +757,10 @@ test!(unions_work_with_no_default_features {
assert_that(p.cargo_process("build"), execs().with_status(0));
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
});
}
test!(optional_and_dev_dep {
#[test]
fn optional_and_dev_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -767,9 +786,10 @@ test!(optional_and_dev_dep {
execs().with_status(0).with_stderr("\
[COMPILING] test v0.1.0 ([..])
"));
});
}
test!(activating_feature_activates_dep {
#[test]
fn activating_feature_activates_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -805,4 +825,4 @@ test!(activating_feature_activates_dep {
assert_that(p.cargo_process("build").arg("--features").arg("a").arg("-v"),
execs().with_status(0));
});
}

View File

@ -1,9 +1,8 @@
use support::{project, execs};
use hamcrest::assert_that;
fn setup() {}
test!(no_deps {
#[test]
fn no_deps() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -18,4 +17,4 @@ test!(no_deps {
assert_that(p.cargo_process("fetch"),
execs().with_status(0).with_stdout(""));
});
}

View File

@ -5,9 +5,8 @@ use support::{project, execs, path2url};
use support::paths::CargoPathExt;
use hamcrest::{assert_that, existing_file};
fn setup() {}
test!(modifying_and_moving {
#[test]
fn modifying_and_moving() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -40,9 +39,10 @@ test!(modifying_and_moving {
fs::rename(&p.root().join("src/a.rs"), &p.root().join("src/b.rs")).unwrap();
assert_that(p.cargo("build"),
execs().with_status(101));
});
}
test!(modify_only_some_files {
#[test]
fn modify_only_some_files() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -82,9 +82,10 @@ test!(modify_only_some_files {
[COMPILING] foo v0.0.1 ({dir})
", dir = path2url(p.root()))));
assert_that(&p.bin("foo"), existing_file());
});
}
test!(rebuild_sub_package_then_while_package {
#[test]
fn rebuild_sub_package_then_while_package() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -133,9 +134,10 @@ test!(rebuild_sub_package_then_while_package {
assert_that(p.cargo("build"),
execs().with_status(0));
});
}
test!(changing_features_is_ok {
#[test]
fn changing_features_is_ok() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -169,9 +171,10 @@ test!(changing_features_is_ok {
assert_that(p.cargo("build"),
execs().with_status(0)
.with_stdout(""));
});
}
test!(rebuild_tests_if_lib_changes {
#[test]
fn rebuild_tests_if_lib_changes() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -199,9 +202,10 @@ test!(rebuild_tests_if_lib_changes {
execs().with_status(0));
assert_that(p.cargo("test").arg("-v"),
execs().with_status(101));
});
}
test!(no_rebuild_transitive_target_deps {
#[test]
fn no_rebuild_transitive_target_deps() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -253,9 +257,10 @@ test!(no_rebuild_transitive_target_deps {
[COMPILING] b v0.0.1 ([..])
[COMPILING] foo v0.0.1 ([..])
"));
});
}
test!(rerun_if_changed_in_dep {
#[test]
fn rerun_if_changed_in_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -285,9 +290,10 @@ test!(rerun_if_changed_in_dep {
execs().with_status(0));
assert_that(p.cargo("build"),
execs().with_status(0).with_stdout(""));
});
}
test!(same_build_dir_cached_packages {
#[test]
fn same_build_dir_cached_packages() {
let p = project("foo")
.file("a1/Cargo.toml", r#"
[package]
@ -349,4 +355,4 @@ test!(same_build_dir_cached_packages {
execs().with_status(0).with_stderr(&format!("\
[COMPILING] a2 v0.0.1 ({dir}/a2)
", dir = p.url())));
});
}

View File

@ -4,9 +4,8 @@ use std::io::prelude::*;
use support::{project, execs};
use hamcrest::{assert_that, existing_file, is_not};
fn setup() {}
test!(adding_and_removing_packages {
#[test]
fn adding_and_removing_packages() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -74,9 +73,10 @@ test!(adding_and_removing_packages {
let mut lock4 = String::new();
File::open(&lockfile).unwrap().read_to_string(&mut lock4).unwrap();
assert_eq!(lock1, lock4);
});
}
test!(preserve_metadata {
#[test]
fn preserve_metadata() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -122,9 +122,10 @@ foo = "bar"
let mut lock = String::new();
File::open(&lockfile).unwrap().read_to_string(&mut lock).unwrap();
assert!(lock.contains(metadata.trim()), "{}", lock);
});
}
test!(preserve_line_endings_issue_2076 {
#[test]
fn preserve_line_endings_issue_2076() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -171,9 +172,10 @@ test!(preserve_line_endings_issue_2076 {
assert!(lock2.starts_with("[root]\r\n"));
assert_eq!(lock1, lock2);
});
}
test!(cargo_update_generate_lockfile {
#[test]
fn cargo_update_generate_lockfile() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -194,4 +196,4 @@ test!(cargo_update_generate_lockfile {
assert_that(p.cargo("update"), execs().with_status(0).with_stdout(""));
assert_that(&lockfile, existing_file());
});
}

View File

@ -7,16 +7,14 @@ use hamcrest::{assert_that, existing_file, existing_dir, is_not};
use cargo::util::{process, ProcessBuilder};
fn setup() {
}
fn cargo_process(s: &str) -> ProcessBuilder {
let mut p = process(&cargo_dir().join("cargo"));
p.arg(s).cwd(&paths::root()).env("HOME", &paths::home());
return p;
}
test!(simple_lib {
#[test]
fn simple_lib() {
assert_that(cargo_process("init").arg("--vcs").arg("none")
.env("USER", "foo"),
execs().with_status(0));
@ -27,9 +25,10 @@ test!(simple_lib {
assert_that(cargo_process("build"),
execs().with_status(0));
});
}
test!(simple_bin {
#[test]
fn simple_bin() {
let path = paths::root().join("foo");
fs::create_dir(&path).unwrap();
assert_that(cargo_process("init").arg("--bin").arg("--vcs").arg("none")
@ -44,7 +43,7 @@ test!(simple_bin {
assert_that(&paths::root().join(&format!("foo/target/debug/foo{}",
env::consts::EXE_SUFFIX)),
existing_file());
});
}
fn bin_already_exists(explicit: bool, rellocation: &str) {
let path = paths::root().join("foo");
@ -79,31 +78,38 @@ fn bin_already_exists(explicit: bool, rellocation: &str) {
assert_eq!(Vec::from(content as &[u8]), new_content);
}
test!(bin_already_exists_explicit {
#[test]
fn bin_already_exists_explicit() {
bin_already_exists(true, "src/main.rs")
});
}
test!(bin_already_exists_implicit {
#[test]
fn bin_already_exists_implicit() {
bin_already_exists(false, "src/main.rs")
});
}
test!(bin_already_exists_explicit_nosrc {
#[test]
fn bin_already_exists_explicit_nosrc() {
bin_already_exists(true, "main.rs")
});
}
test!(bin_already_exists_implicit_nosrc {
#[test]
fn bin_already_exists_implicit_nosrc() {
bin_already_exists(false, "main.rs")
});
}
test!(bin_already_exists_implicit_namenosrc {
#[test]
fn bin_already_exists_implicit_namenosrc() {
bin_already_exists(false, "foo.rs")
});
}
test!(bin_already_exists_implicit_namesrc {
#[test]
fn bin_already_exists_implicit_namesrc() {
bin_already_exists(false, "src/foo.rs")
});
}
test!(confused_by_multiple_lib_files {
#[test]
fn confused_by_multiple_lib_files() {
let path = paths::root().join("foo");
fs::create_dir_all(&path.join("src")).unwrap();
@ -130,10 +136,11 @@ test!(confused_by_multiple_lib_files {
"));
assert_that(&paths::root().join("foo/Cargo.toml"), is_not(existing_file()));
});
}
test!(multibin_project_name_clash {
#[test]
fn multibin_project_name_clash() {
let path = paths::root().join("foo");
fs::create_dir(&path).unwrap();
@ -163,7 +170,7 @@ cannot automatically generate Cargo.toml as the main target would be ambiguous
"));
assert_that(&paths::root().join("foo/Cargo.toml"), is_not(existing_file()));
});
}
fn lib_already_exists(rellocation: &str) {
let path = paths::root().join("foo");
@ -190,15 +197,18 @@ fn lib_already_exists(rellocation: &str) {
assert_eq!(Vec::from(content as &[u8]), new_content);
}
test!(lib_already_exists_src {
#[test]
fn lib_already_exists_src() {
lib_already_exists("src/lib.rs")
});
}
test!(lib_already_exists_nosrc {
#[test]
fn lib_already_exists_nosrc() {
lib_already_exists("lib.rs")
});
}
test!(simple_git {
#[test]
fn simple_git() {
assert_that(cargo_process("init").arg("--vcs").arg("git")
.env("USER", "foo"),
execs().with_status(0));
@ -207,9 +217,10 @@ test!(simple_git {
assert_that(&paths::root().join("src/lib.rs"), existing_file());
assert_that(&paths::root().join(".git"), existing_dir());
assert_that(&paths::root().join(".gitignore"), existing_file());
});
}
test!(auto_git {
#[test]
fn auto_git() {
let td = TempDir::new("cargo").unwrap();
let foo = &td.path().join("foo");
fs::create_dir_all(&foo).unwrap();
@ -221,9 +232,10 @@ test!(auto_git {
assert_that(&foo.join("src/lib.rs"), existing_file());
assert_that(&foo.join(".git"), existing_dir());
assert_that(&foo.join(".gitignore"), existing_file());
});
}
test!(invalid_dir_name {
#[test]
fn invalid_dir_name() {
let foo = &paths::root().join("foo.bar");
fs::create_dir_all(&foo).unwrap();
assert_that(cargo_process("init").cwd(foo.clone())
@ -234,9 +246,10 @@ use --name to override crate name
"));
assert_that(&foo.join("Cargo.toml"), is_not(existing_file()));
});
}
test!(reserved_name {
#[test]
fn reserved_name() {
let test = &paths::root().join("test");
fs::create_dir_all(&test).unwrap();
assert_that(cargo_process("init").cwd(test.clone())
@ -247,9 +260,10 @@ use --name to override crate name
"));
assert_that(&test.join("Cargo.toml"), is_not(existing_file()));
});
}
test!(git_autodetect {
#[test]
fn git_autodetect() {
fs::create_dir(&paths::root().join(".git")).unwrap();
assert_that(cargo_process("init")
@ -261,10 +275,11 @@ test!(git_autodetect {
assert_that(&paths::root().join("src/lib.rs"), existing_file());
assert_that(&paths::root().join(".git"), existing_dir());
assert_that(&paths::root().join(".gitignore"), existing_file());
});
}
test!(mercurial_autodetect {
#[test]
fn mercurial_autodetect() {
fs::create_dir(&paths::root().join(".hg")).unwrap();
assert_that(cargo_process("init")
@ -276,9 +291,10 @@ test!(mercurial_autodetect {
assert_that(&paths::root().join("src/lib.rs"), existing_file());
assert_that(&paths::root().join(".git"), is_not(existing_dir()));
assert_that(&paths::root().join(".hgignore"), existing_file());
});
}
test!(gitignore_appended_not_replaced {
#[test]
fn gitignore_appended_not_replaced() {
fs::create_dir(&paths::root().join(".git")).unwrap();
File::create(&paths::root().join(".gitignore")).unwrap().write_all(b"qqqqqq\n").unwrap();
@ -296,9 +312,10 @@ test!(gitignore_appended_not_replaced {
let mut contents = String::new();
File::open(&paths::root().join(".gitignore")).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"qqqqqq"#));
});
}
test!(cargo_lock_gitignored_if_lib1 {
#[test]
fn cargo_lock_gitignored_if_lib1() {
fs::create_dir(&paths::root().join(".git")).unwrap();
assert_that(cargo_process("init").arg("--vcs").arg("git")
@ -310,9 +327,10 @@ test!(cargo_lock_gitignored_if_lib1 {
let mut contents = String::new();
File::open(&paths::root().join(".gitignore")).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"Cargo.lock"#));
});
}
test!(cargo_lock_gitignored_if_lib2 {
#[test]
fn cargo_lock_gitignored_if_lib2() {
fs::create_dir(&paths::root().join(".git")).unwrap();
File::create(&paths::root().join("lib.rs")).unwrap().write_all(br#""#).unwrap();
@ -326,9 +344,10 @@ test!(cargo_lock_gitignored_if_lib2 {
let mut contents = String::new();
File::open(&paths::root().join(".gitignore")).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"Cargo.lock"#));
});
}
test!(cargo_lock_not_gitignored_if_bin1 {
#[test]
fn cargo_lock_not_gitignored_if_bin1() {
fs::create_dir(&paths::root().join(".git")).unwrap();
assert_that(cargo_process("init").arg("--vcs").arg("git")
@ -341,9 +360,10 @@ test!(cargo_lock_not_gitignored_if_bin1 {
let mut contents = String::new();
File::open(&paths::root().join(".gitignore")).unwrap().read_to_string(&mut contents).unwrap();
assert!(!contents.contains(r#"Cargo.lock"#));
});
}
test!(cargo_lock_not_gitignored_if_bin2 {
#[test]
fn cargo_lock_not_gitignored_if_bin2() {
fs::create_dir(&paths::root().join(".git")).unwrap();
File::create(&paths::root().join("main.rs")).unwrap().write_all(br#""#).unwrap();
@ -357,17 +377,19 @@ test!(cargo_lock_not_gitignored_if_bin2 {
let mut contents = String::new();
File::open(&paths::root().join(".gitignore")).unwrap().read_to_string(&mut contents).unwrap();
assert!(!contents.contains(r#"Cargo.lock"#));
});
}
test!(with_argument {
#[test]
fn with_argument() {
assert_that(cargo_process("init").arg("foo").arg("--vcs").arg("none")
.env("USER", "foo"),
execs().with_status(0));
assert_that(&paths::root().join("foo/Cargo.toml"), existing_file());
});
}
test!(unknown_flags {
#[test]
fn unknown_flags() {
assert_that(cargo_process("init").arg("foo").arg("--flag"),
execs().with_status(1)
.with_stderr("\
@ -377,13 +399,14 @@ Usage:
cargo init [options] [<path>]
cargo init -h | --help
"));
});
}
#[cfg(not(windows))]
test!(no_filename {
#[test]
fn no_filename() {
assert_that(cargo_process("init").arg("/"),
execs().with_status(101)
.with_stderr(&format!("\
[ERROR] cannot auto-detect project name from path \"/\" ; use --name to override
")));
});
}

View File

@ -14,9 +14,6 @@ use support::git;
pub use self::InstalledExe as has_installed_exe;
fn setup() {
}
fn cargo_process(s: &str) -> ProcessBuilder {
let mut p = ::cargo_process();
p.arg(s);
@ -56,7 +53,8 @@ impl fmt::Display for InstalledExe {
}
}
test!(simple {
#[test]
fn simple() {
pkg("foo", "0.0.1");
assert_that(cargo_process("install").arg("foo"),
@ -76,9 +74,10 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina
",
home = cargo_home().display())));
assert_that(cargo_home(), is_not(has_installed_exe("foo")));
});
}
test!(pick_max_version {
#[test]
fn pick_max_version() {
pkg("foo", "0.0.1");
pkg("foo", "0.0.2");
@ -92,27 +91,30 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina
",
home = cargo_home().display())));
assert_that(cargo_home(), has_installed_exe("foo"));
});
}
test!(missing {
#[test]
fn missing() {
pkg("foo", "0.0.1");
assert_that(cargo_process("install").arg("bar"),
execs().with_status(101).with_stderr("\
[UPDATING] registry [..]
[ERROR] could not find `bar` in `registry file://[..]`
"));
});
}
test!(bad_version {
#[test]
fn bad_version() {
pkg("foo", "0.0.1");
assert_that(cargo_process("install").arg("foo").arg("--vers=0.2.0"),
execs().with_status(101).with_stderr("\
[UPDATING] registry [..]
[ERROR] could not find `foo` in `registry file://[..]` with version `0.2.0`
"));
});
}
test!(no_crate {
#[test]
fn no_crate() {
assert_that(cargo_process("install"),
execs().with_status(101).with_stderr("\
[ERROR] `[..]` is not a crate root; specify a crate to install [..]
@ -123,9 +125,10 @@ Caused by:
Caused by:
[..] (os error [..])
"));
});
}
test!(install_location_precedence {
#[test]
fn install_location_precedence() {
pkg("foo", "0.0.1");
let root = paths::root();
@ -171,9 +174,10 @@ test!(install_location_precedence {
assert_that(cargo_process("install").arg("foo"),
execs().with_status(0));
assert_that(&t4, has_installed_exe("foo"));
});
}
test!(install_path {
#[test]
fn install_path() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -192,9 +196,10 @@ test!(install_path {
[ERROR] binary `foo[..]` already exists in destination as part of `foo v0.1.0 [..]`
Add --force to overwrite
"));
});
}
test!(multiple_crates_error {
#[test]
fn multiple_crates_error() {
let p = git::repo(&paths::root().join("foo"))
.file("Cargo.toml", r#"
[package]
@ -217,9 +222,10 @@ test!(multiple_crates_error {
[UPDATING] git repository [..]
[ERROR] multiple packages with binaries found: bar, foo
"));
});
}
test!(multiple_crates_select {
#[test]
fn multiple_crates_select() {
let p = git::repo(&paths::root().join("foo"))
.file("Cargo.toml", r#"
[package]
@ -247,9 +253,10 @@ test!(multiple_crates_select {
.arg("bar"),
execs().with_status(0));
assert_that(cargo_home(), has_installed_exe("bar"));
});
}
test!(multiple_crates_auto_binaries {
#[test]
fn multiple_crates_auto_binaries() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -273,9 +280,10 @@ test!(multiple_crates_auto_binaries {
assert_that(cargo_process("install").arg("--path").arg(p.root()),
execs().with_status(0));
assert_that(cargo_home(), has_installed_exe("foo"));
});
}
test!(multiple_crates_auto_examples {
#[test]
fn multiple_crates_auto_examples() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -305,9 +313,10 @@ test!(multiple_crates_auto_examples {
.arg("--example=foo"),
execs().with_status(0));
assert_that(cargo_home(), has_installed_exe("foo"));
});
}
test!(no_binaries_or_examples {
#[test]
fn no_binaries_or_examples() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -332,9 +341,10 @@ test!(no_binaries_or_examples {
execs().with_status(101).with_stderr("\
[ERROR] no packages found with binaries or examples
"));
});
}
test!(no_binaries {
#[test]
fn no_binaries() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -350,9 +360,10 @@ test!(no_binaries {
execs().with_status(101).with_stderr("\
[ERROR] specified package has no binaries
"));
});
}
test!(examples {
#[test]
fn examples() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -368,9 +379,10 @@ test!(examples {
.arg("--example=foo"),
execs().with_status(0));
assert_that(cargo_home(), has_installed_exe("foo"));
});
}
test!(install_twice {
#[test]
fn install_twice() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -390,9 +402,10 @@ test!(install_twice {
binary `foo-bin2[..]` already exists in destination as part of `foo v0.1.0 ([..])`
Add --force to overwrite
"));
});
}
test!(install_force {
#[test]
fn install_force() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -429,9 +442,10 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina
foo v0.2.0 ([..]):
foo[..]
"));
});
}
test!(install_force_partial_overlap {
#[test]
fn install_force_partial_overlap() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -474,9 +488,10 @@ foo v0.2.0 ([..]):
foo-bin2[..]
foo-bin3[..]
"));
});
}
test!(install_force_bin {
#[test]
fn install_force_bin() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -521,9 +536,10 @@ foo v0.1.0 ([..]):
foo v0.2.0 ([..]):
foo-bin2[..]
"));
});
}
test!(compile_failure {
#[test]
fn compile_failure() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -547,9 +563,10 @@ Caused by:
To learn more, run the command again with --verbose.
"));
});
}
test!(git_repo {
#[test]
fn git_repo() {
let p = git::repo(&paths::root().join("foo"))
.file("Cargo.toml", r#"
[package]
@ -570,9 +587,10 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina
home = cargo_home().display())));
assert_that(cargo_home(), has_installed_exe("foo"));
assert_that(cargo_home(), has_installed_exe("foo"));
});
}
test!(list {
#[test]
fn list() {
pkg("foo", "0.0.1");
pkg("bar", "0.2.1");
pkg("bar", "0.2.2");
@ -591,16 +609,18 @@ bar v0.2.1 (registry [..]):
foo v0.0.1 (registry [..]):
foo[..]
"));
});
}
test!(uninstall_pkg_does_not_exist {
#[test]
fn uninstall_pkg_does_not_exist() {
assert_that(cargo_process("uninstall").arg("foo"),
execs().with_status(101).with_stderr("\
[ERROR] package id specification `foo` matched no packages
"));
});
}
test!(uninstall_bin_does_not_exist {
#[test]
fn uninstall_bin_does_not_exist() {
pkg("foo", "0.0.1");
assert_that(cargo_process("install").arg("foo"),
@ -609,9 +629,10 @@ test!(uninstall_bin_does_not_exist {
execs().with_status(101).with_stderr("\
[ERROR] binary `bar[..]` not installed as part of `foo v0.0.1 ([..])`
"));
});
}
test!(uninstall_piecemeal {
#[test]
fn uninstall_piecemeal() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -646,9 +667,10 @@ test!(uninstall_piecemeal {
execs().with_status(101).with_stderr("\
[ERROR] package id specification `foo` matched no packages
"));
});
}
test!(subcommand_works_out_of_the_box {
#[test]
fn subcommand_works_out_of_the_box() {
Package::new("cargo-foo", "1.0.0")
.file("src/main.rs", r#"
fn main() {
@ -662,9 +684,10 @@ test!(subcommand_works_out_of_the_box {
execs().with_status(0).with_stdout("bar\n"));
assert_that(cargo_process("--list"),
execs().with_status(0).with_stdout_contains(" foo\n"));
});
}
test!(installs_from_cwd_by_default {
#[test]
fn installs_from_cwd_by_default() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -678,9 +701,10 @@ test!(installs_from_cwd_by_default {
assert_that(cargo_process("install").cwd(p.root()),
execs().with_status(0));
assert_that(cargo_home(), has_installed_exe("foo"));
});
}
test!(do_not_rebuilds_on_local_install {
#[test]
fn do_not_rebuilds_on_local_install() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -701,9 +725,10 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina
assert!(p.build_dir().c_exists());
assert!(p.release_bin("foo").c_exists());
assert_that(cargo_home(), has_installed_exe("foo"));
});
}
test!(reports_unsuccessful_subcommand_result {
#[test]
fn reports_unsuccessful_subcommand_result() {
Package::new("cargo-fail", "1.0.0")
.file("src/main.rs", r#"
fn main() {
@ -719,9 +744,10 @@ test!(reports_unsuccessful_subcommand_result {
execs().with_status(101).with_stderr_contains("\
thread '<main>' panicked at 'explicit panic', [..]
"));
});
}
test!(git_with_lockfile {
#[test]
fn git_with_lockfile() {
let p = git::repo(&paths::root().join("foo"))
.file("Cargo.toml", r#"
[package]
@ -754,9 +780,10 @@ test!(git_with_lockfile {
assert_that(cargo_process("install").arg("--git").arg(p.url().to_string()),
execs().with_status(0));
});
}
test!(q_silences_warnings {
#[test]
fn q_silences_warnings() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -769,9 +796,10 @@ test!(q_silences_warnings {
assert_that(cargo_process("install").arg("-q").arg("--path").arg(p.root()),
execs().with_status(0).with_stderr(""));
});
}
test!(readonly_dir {
#[test]
fn readonly_dir() {
pkg("foo", "0.0.1");
let root = paths::root();
@ -784,4 +812,4 @@ test!(readonly_dir {
assert_that(cargo_process("install").arg("foo").cwd(dir),
execs().with_status(0));
assert_that(cargo_home(), has_installed_exe("foo"));
});
}

View File

@ -3,9 +3,8 @@ use support::registry::Package;
use support::{project, execs, basic_bin_manifest, main_file};
fn setup() {}
test!(cargo_metadata_simple {
#[test]
fn cargo_metadata_simple() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"));
@ -42,10 +41,11 @@ test!(cargo_metadata_simple {
},
"version": 1
}"#));
});
}
test!(cargo_metadata_with_deps_and_version {
#[test]
fn cargo_metadata_with_deps_and_version() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -170,9 +170,10 @@ test!(cargo_metadata_with_deps_and_version {
},
"version": 1
}"#));
});
}
test!(cargo_metadata_with_invalid_manifest {
#[test]
fn cargo_metadata_with_invalid_manifest() {
let p = project("foo")
.file("Cargo.toml", "");
@ -182,7 +183,7 @@ test!(cargo_metadata_with_invalid_manifest {
Caused by:
no `package` or `project` section found."))
});
}
const MANIFEST_OUTPUT: &'static str=
r#"
@ -205,7 +206,8 @@ const MANIFEST_OUTPUT: &'static str=
"version": 1
}"#;
test!(cargo_metadata_no_deps_path_to_cargo_toml_relative {
#[test]
fn cargo_metadata_no_deps_path_to_cargo_toml_relative() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -215,9 +217,10 @@ test!(cargo_metadata_no_deps_path_to_cargo_toml_relative {
.cwd(p.root().parent().unwrap()),
execs().with_status(0)
.with_json(MANIFEST_OUTPUT));
});
}
test!(cargo_metadata_no_deps_path_to_cargo_toml_absolute {
#[test]
fn cargo_metadata_no_deps_path_to_cargo_toml_absolute() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -227,9 +230,10 @@ test!(cargo_metadata_no_deps_path_to_cargo_toml_absolute {
.cwd(p.root().parent().unwrap()),
execs().with_status(0)
.with_json(MANIFEST_OUTPUT));
});
}
test!(cargo_metadata_no_deps_path_to_cargo_toml_parent_relative {
#[test]
fn cargo_metadata_no_deps_path_to_cargo_toml_parent_relative() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -240,9 +244,10 @@ test!(cargo_metadata_no_deps_path_to_cargo_toml_parent_relative {
execs().with_status(101)
.with_stderr("[ERROR] the manifest-path must be \
a path to a Cargo.toml file"));
});
}
test!(cargo_metadata_no_deps_path_to_cargo_toml_parent_absolute {
#[test]
fn cargo_metadata_no_deps_path_to_cargo_toml_parent_absolute() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -253,9 +258,10 @@ test!(cargo_metadata_no_deps_path_to_cargo_toml_parent_absolute {
execs().with_status(101)
.with_stderr("[ERROR] the manifest-path must be \
a path to a Cargo.toml file"));
});
}
test!(cargo_metadata_no_deps_cwd {
#[test]
fn cargo_metadata_no_deps_cwd() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -264,9 +270,10 @@ test!(cargo_metadata_no_deps_cwd {
.cwd(p.root()),
execs().with_status(0)
.with_json(MANIFEST_OUTPUT));
});
}
test!(carg_metadata_bad_version {
#[test]
fn carg_metadata_bad_version() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -276,4 +283,4 @@ test!(carg_metadata_bad_version {
.cwd(p.root()),
execs().with_status(101)
.with_stderr("[ERROR] metadata version 2 not supported, only 1 is currently supported"));
});
}

View File

@ -1,9 +1,8 @@
use support::{project, execs};
use hamcrest::assert_that;
fn setup() {}
test!(net_retry_loads_from_config {
#[test]
fn net_retry_loads_from_config() {
let p = project("foo")
.file("Cargo.toml", &format!(r#"
[project]
@ -25,9 +24,10 @@ test!(net_retry_loads_from_config {
execs().with_status(101)
.with_stderr_contains(&format!("[WARNING] spurious network error \
(1 tries remaining): [2/-1] [..]")));
});
}
test!(net_retry_git_outputs_warning{
#[test]
fn net_retry_git_outputs_warning() {
let p = project("foo")
.file("Cargo.toml", &format!(r#"
[project]
@ -50,4 +50,4 @@ test!(net_retry_git_outputs_warning{
(2 tries remaining): [2/-1] [..]"))
.with_stderr_contains(&format!("\
[WARNING] spurious network error (1 tries remaining): [2/-1] [..]")));
});
}

View File

@ -9,16 +9,14 @@ use hamcrest::{assert_that, existing_file, existing_dir, is_not};
use cargo::util::ProcessBuilder;
fn setup() {
}
fn cargo_process(s: &str) -> ProcessBuilder {
let mut p = ::cargo_process();
p.arg(s);
return p;
}
test!(simple_lib {
#[test]
fn simple_lib() {
assert_that(cargo_process("new").arg("foo").arg("--vcs").arg("none")
.env("USER", "foo"),
execs().with_status(0));
@ -30,9 +28,10 @@ test!(simple_lib {
assert_that(cargo_process("build").cwd(&paths::root().join("foo")),
execs().with_status(0));
});
}
test!(simple_bin {
#[test]
fn simple_bin() {
assert_that(cargo_process("new").arg("foo").arg("--bin")
.env("USER", "foo"),
execs().with_status(0));
@ -46,9 +45,10 @@ test!(simple_bin {
assert_that(&paths::root().join(&format!("foo/target/debug/foo{}",
env::consts::EXE_SUFFIX)),
existing_file());
});
}
test!(simple_git {
#[test]
fn simple_git() {
let td = TempDir::new("cargo").unwrap();
assert_that(cargo_process("new").arg("foo").cwd(td.path().clone())
.env("USER", "foo"),
@ -62,9 +62,10 @@ test!(simple_git {
assert_that(cargo_process("build").cwd(&td.path().clone().join("foo")),
execs().with_status(0));
});
}
test!(no_argument {
#[test]
fn no_argument() {
assert_that(cargo_process("new"),
execs().with_status(1)
.with_stderr("\
@ -74,42 +75,47 @@ Usage:
cargo new [options] <path>
cargo new -h | --help
"));
});
}
test!(existing {
#[test]
fn existing() {
let dst = paths::root().join("foo");
fs::create_dir(&dst).unwrap();
assert_that(cargo_process("new").arg("foo"),
execs().with_status(101)
.with_stderr(format!("[ERROR] destination `{}` already exists\n",
dst.display())));
});
}
test!(invalid_characters {
#[test]
fn invalid_characters() {
assert_that(cargo_process("new").arg("foo.rs"),
execs().with_status(101)
.with_stderr("\
[ERROR] Invalid character `.` in crate name: `foo.rs`
use --name to override crate name"));
});
}
test!(reserved_name {
#[test]
fn reserved_name() {
assert_that(cargo_process("new").arg("test"),
execs().with_status(101)
.with_stderr("\
[ERROR] The name `test` cannot be used as a crate name\n\
use --name to override crate name"));
});
}
test!(keyword_name {
#[test]
fn keyword_name() {
assert_that(cargo_process("new").arg("pub"),
execs().with_status(101)
.with_stderr("\
[ERROR] The name `pub` cannot be used as a crate name\n\
use --name to override crate name"));
});
}
test!(rust_prefix_stripped {
#[test]
fn rust_prefix_stripped() {
assert_that(cargo_process("new").arg("rust-foo").env("USER", "foo"),
execs().with_status(0)
.with_stdout("note: package will be named `foo`; use --name to override"));
@ -117,27 +123,30 @@ test!(rust_prefix_stripped {
let mut contents = String::new();
File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"name = "foo""#));
});
}
test!(bin_disables_stripping {
#[test]
fn bin_disables_stripping() {
assert_that(cargo_process("new").arg("rust-foo").arg("--bin").env("USER", "foo"),
execs().with_status(0));
let toml = paths::root().join("rust-foo/Cargo.toml");
let mut contents = String::new();
File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"name = "rust-foo""#));
});
}
test!(explicit_name_not_stripped {
#[test]
fn explicit_name_not_stripped() {
assert_that(cargo_process("new").arg("foo").arg("--name").arg("rust-bar").env("USER", "foo"),
execs().with_status(0));
let toml = paths::root().join("foo/Cargo.toml");
let mut contents = String::new();
File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"name = "rust-bar""#));
});
}
test!(finds_author_user {
#[test]
fn finds_author_user() {
// Use a temp dir to make sure we don't pick up .cargo/config somewhere in
// the hierarchy
let td = TempDir::new("cargo").unwrap();
@ -149,9 +158,10 @@ test!(finds_author_user {
let mut contents = String::new();
File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"authors = ["foo"]"#));
});
}
test!(finds_author_user_escaped {
#[test]
fn finds_author_user_escaped() {
// Use a temp dir to make sure we don't pick up .cargo/config somewhere in
// the hierarchy
let td = TempDir::new("cargo").unwrap();
@ -163,9 +173,10 @@ test!(finds_author_user_escaped {
let mut contents = String::new();
File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"authors = ["foo \"bar\""]"#));
});
}
test!(finds_author_username {
#[test]
fn finds_author_username() {
// Use a temp dir to make sure we don't pick up .cargo/config somewhere in
// the hierarchy
let td = TempDir::new("cargo").unwrap();
@ -179,9 +190,10 @@ test!(finds_author_username {
let mut contents = String::new();
File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"authors = ["foo"]"#));
});
}
test!(finds_author_priority {
#[test]
fn finds_author_priority() {
// Use a temp dir to make sure we don't pick up .cargo/config somewhere in
// the hierarchy
let td = TempDir::new("cargo").unwrap();
@ -197,9 +209,10 @@ test!(finds_author_priority {
let mut contents = String::new();
File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"authors = ["bar <baz>"]"#));
});
}
test!(finds_author_email {
#[test]
fn finds_author_email() {
// Use a temp dir to make sure we don't pick up .cargo/config somewhere in
// the hierarchy
let td = TempDir::new("cargo").unwrap();
@ -213,9 +226,10 @@ test!(finds_author_email {
let mut contents = String::new();
File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"authors = ["bar <baz>"]"#));
});
}
test!(finds_author_git {
#[test]
fn finds_author_git() {
::process("git").args(&["config", "--global", "user.name", "bar"])
.exec().unwrap();
::process("git").args(&["config", "--global", "user.email", "baz"])
@ -227,9 +241,10 @@ test!(finds_author_git {
let mut contents = String::new();
File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"authors = ["bar <baz>"]"#));
});
}
test!(finds_git_email{
#[test]
fn finds_git_email() {
let td = TempDir::new("cargo").unwrap();
assert_that(cargo_process("new").arg("foo")
.env("GIT_AUTHOR_NAME", "foo")
@ -241,10 +256,11 @@ test!(finds_git_email{
let mut contents = String::new();
File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"authors = ["foo <gitfoo>"]"#), contents);
});
}
test!(finds_git_author{
#[test]
fn finds_git_author() {
// Use a temp dir to make sure we don't pick up .cargo/config somewhere in
// the hierarchy
let td = TempDir::new("cargo").unwrap();
@ -258,9 +274,10 @@ test!(finds_git_author{
let mut contents = String::new();
File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"authors = ["gitfoo"]"#));
});
}
test!(author_prefers_cargo {
#[test]
fn author_prefers_cargo() {
::process("git").args(&["config", "--global", "user.name", "foo"])
.exec().unwrap();
::process("git").args(&["config", "--global", "user.email", "bar"])
@ -282,9 +299,10 @@ test!(author_prefers_cargo {
File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(r#"authors = ["new-foo <new-bar>"]"#));
assert!(!root.join("foo/.gitignore").c_exists());
});
}
test!(git_prefers_command_line {
#[test]
fn git_prefers_command_line() {
let root = paths::root();
let td = TempDir::new("cargo").unwrap();
fs::create_dir(&root.join(".cargo")).unwrap();
@ -300,9 +318,10 @@ test!(git_prefers_command_line {
.env("USER", "foo"),
execs().with_status(0));
assert!(td.path().join("foo/.gitignore").c_exists());
});
}
test!(subpackage_no_git {
#[test]
fn subpackage_no_git() {
assert_that(cargo_process("new").arg("foo").env("USER", "foo"),
execs().with_status(0));
@ -316,9 +335,10 @@ test!(subpackage_no_git {
is_not(existing_file()));
assert_that(&paths::root().join("foo/components/subcomponent/.gitignore"),
is_not(existing_file()));
});
}
test!(subpackage_git_with_vcs_arg {
#[test]
fn subpackage_git_with_vcs_arg() {
assert_that(cargo_process("new").arg("foo").env("USER", "foo"),
execs().with_status(0));
@ -333,9 +353,10 @@ test!(subpackage_git_with_vcs_arg {
existing_dir());
assert_that(&paths::root().join("foo/components/subcomponent/.gitignore"),
existing_file());
});
}
test!(unknown_flags {
#[test]
fn unknown_flags() {
assert_that(cargo_process("new").arg("foo").arg("--flag"),
execs().with_status(1)
.with_stderr("\
@ -345,4 +366,4 @@ Usage:
cargo new [..]
cargo new [..]
"));
});
}

View File

@ -5,9 +5,8 @@ use support::{execs, project};
use support::git;
use support::paths;
fn setup() {}
test!(override_simple {
#[test]
fn override_simple() {
Package::new("foo", "0.1.0").publish();
let foo = git::repo(&paths::root().join("override"))
@ -47,9 +46,10 @@ test!(override_simple {
[COMPILING] foo v0.1.0 (file://[..])
[COMPILING] local v0.0.1 (file://[..])
"));
});
}
test!(missing_version {
#[test]
fn missing_version() {
let p = project("local")
.file("Cargo.toml", r#"
[package]
@ -72,9 +72,10 @@ error: failed to parse manifest at `[..]`
Caused by:
replacements must specify a version to replace, but `foo` does not
"));
});
}
test!(different_version {
#[test]
fn different_version() {
Package::new("foo", "0.2.0").publish();
Package::new("foo", "0.1.0").publish();
@ -100,9 +101,10 @@ error: failed to parse manifest at `[..]`
Caused by:
replacements cannot specify a version requirement, but found one for [..]
"));
});
}
test!(transitive {
#[test]
fn transitive() {
Package::new("foo", "0.1.0").publish();
Package::new("bar", "0.2.0")
.dep("foo", "0.1.0")
@ -145,9 +147,10 @@ test!(transitive {
"));
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
});
}
test!(persists_across_rebuilds {
#[test]
fn persists_across_rebuilds() {
Package::new("foo", "0.1.0").publish();
let foo = git::repo(&paths::root().join("override"))
@ -190,9 +193,10 @@ test!(persists_across_rebuilds {
assert_that(p.cargo("build"),
execs().with_status(0).with_stdout(""));
});
}
test!(replace_registry_with_path {
#[test]
fn replace_registry_with_path() {
Package::new("foo", "0.1.0").publish();
project("foo")
@ -231,9 +235,10 @@ test!(replace_registry_with_path {
[COMPILING] foo v0.1.0 (file://[..])
[COMPILING] local v0.0.1 (file://[..])
"));
});
}
test!(use_a_spec_to_select {
#[test]
fn use_a_spec_to_select() {
Package::new("foo", "0.1.1")
.file("src/lib.rs", "pub fn foo1() {}")
.publish();
@ -291,9 +296,10 @@ test!(use_a_spec_to_select {
[COMPILING] [..]
[COMPILING] local v0.0.1 (file://[..])
"));
});
}
test!(override_adds_some_deps {
#[test]
fn override_adds_some_deps() {
Package::new("foo", "0.1.1").publish();
Package::new("bar", "0.1.0").publish();
@ -348,9 +354,10 @@ test!(override_adds_some_deps {
"));
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
});
}
test!(locked_means_locked_yes_no_seriously_i_mean_locked {
#[test]
fn locked_means_locked_yes_no_seriously_i_mean_locked() {
// this in theory exercises #2041
Package::new("foo", "0.1.0").publish();
Package::new("foo", "0.2.0").publish();
@ -390,9 +397,10 @@ test!(locked_means_locked_yes_no_seriously_i_mean_locked {
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
});
}
test!(override_wrong_name {
#[test]
fn override_wrong_name() {
Package::new("foo", "0.1.0").publish();
let foo = git::repo(&paths::root().join("override"))
@ -428,9 +436,10 @@ error: no matching package for override `foo:0.1.0` found
location searched: file://[..]
version required: = 0.1.0
"));
});
}
test!(override_with_nothing {
#[test]
fn override_with_nothing() {
Package::new("foo", "0.1.0").publish();
let foo = git::repo(&paths::root().join("override"))
@ -461,9 +470,10 @@ error: Unable to update file://[..]
Caused by:
Could not find Cargo.toml in `[..]`
"));
});
}
test!(override_wrong_version {
#[test]
fn override_wrong_version() {
let p = project("local")
.file("Cargo.toml", r#"
[package]
@ -483,9 +493,10 @@ error: failed to parse manifest at `[..]`
Caused by:
replacements cannot specify a version requirement, but found one for `foo:0.1.0`
"));
});
}
test!(multiple_specs {
#[test]
fn multiple_specs() {
Package::new("foo", "0.1.0").publish();
let foo = git::repo(&paths::root().join("override"))
@ -525,9 +536,10 @@ error: overlapping replacement specifications found:
both specifications match: foo v0.1.0 ([..])
"));
});
}
test!(test_override_dep {
#[test]
fn test_override_dep() {
Package::new("foo", "0.1.0").publish();
let foo = git::repo(&paths::root().join("override"))
@ -563,4 +575,4 @@ Please re-run this command with [..]
[..]#foo:0.1.0
[..]#foo:0.1.0
"));
});
}

View File

@ -9,10 +9,8 @@ use tar::Archive;
use support::{project, execs, paths, git, path2url};
use hamcrest::{assert_that, existing_file};
fn setup() {
}
test!(simple {
#[test]
fn simple() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -58,9 +56,10 @@ src[..]main.rs
fname == b"foo-0.0.1/src/main.rs",
"unexpected filename: {:?}", f.header().path())
}
});
}
test!(metadata_warning {
#[test]
fn metadata_warning() {
let p = project("all")
.file("Cargo.toml", r#"
[project]
@ -123,9 +122,10 @@ http://doc.crates.io/manifest.html#package-metadata for more info.
[COMPILING] foo v0.0.1 ({dir}[..])
",
dir = p.url())));
});
}
test!(package_verbose {
#[test]
fn package_verbose() {
let root = paths::root().join("all");
let p = git::repo(&root)
.file("Cargo.toml", r#"
@ -167,9 +167,10 @@ test!(package_verbose {
[ARCHIVING] [..]
[ARCHIVING] [..]
"));
});
}
test!(package_verification {
#[test]
fn package_verification() {
let p = project("all")
.file("Cargo.toml", r#"
[project]
@ -190,9 +191,10 @@ test!(package_verification {
[COMPILING] foo v0.0.1 ({dir}[..])
",
dir = p.url())));
});
}
test!(exclude {
#[test]
fn exclude() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -214,9 +216,10 @@ test!(exclude {
[ARCHIVING] [..]
[ARCHIVING] [..]
"));
});
}
test!(include {
#[test]
fn include() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -240,9 +243,10 @@ test!(include {
[ARCHIVING] [..]
[ARCHIVING] [..]
"));
});
}
test!(package_lib_with_bin {
#[test]
fn package_lib_with_bin() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -258,9 +262,10 @@ test!(package_lib_with_bin {
assert_that(p.cargo_process("package").arg("-v"),
execs().with_status(0));
});
}
test!(package_new_git_repo {
#[test]
fn package_new_git_repo() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -279,9 +284,10 @@ test!(package_new_git_repo {
[ARCHIVING] [..]
[ARCHIVING] [..]
"));
});
}
test!(package_git_submodule {
#[test]
fn package_git_submodule() {
let project = git::new("foo", |project| {
project.file("Cargo.toml", r#"
[project]
@ -310,9 +316,10 @@ test!(package_git_submodule {
assert_that(::cargo_process().arg("package").cwd(project.root())
.arg("--no-verify").arg("-v"),
execs().with_status(0).with_stderr_contains("[ARCHIVING] bar/Makefile"));
});
}
test!(no_duplicates_from_modified_tracked_files {
#[test]
fn no_duplicates_from_modified_tracked_files() {
let root = paths::root().join("all");
let p = git::repo(&root)
.file("Cargo.toml", r#"
@ -336,9 +343,10 @@ test!(no_duplicates_from_modified_tracked_files {
Cargo.toml
src/main.rs
"));
});
}
test!(ignore_nested {
#[test]
fn ignore_nested() {
let cargo_toml = r#"
[project]
name = "nested"
@ -388,10 +396,11 @@ src[..]main.rs
fname == b"nested-0.0.1/src/main.rs",
"unexpected filename: {:?}", f.header().path())
}
});
}
#[cfg(unix)] // windows doesn't allow these characters in filenames
test!(package_weird_characters {
#[test]
fn package_weird_characters() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -413,4 +422,4 @@ warning: [..]
Caused by:
cannot package a filename with a special character `:`: src/:foo
"));
});
}

View File

@ -4,10 +4,8 @@ use std::path::MAIN_SEPARATOR as SEP;
use support::{project, execs};
use hamcrest::assert_that;
fn setup() {
}
test!(profile_overrides {
#[test]
fn profile_overrides() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
@ -38,9 +36,10 @@ test!(profile_overrides {
dir = p.root().display(),
url = p.url(),
)));
});
}
test!(top_level_overrides_deps {
#[test]
fn top_level_overrides_deps() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
@ -104,4 +103,4 @@ test!(top_level_overrides_deps {
sep = SEP,
prefix = env::consts::DLL_PREFIX,
suffix = env::consts::DLL_SUFFIX)));
});
}

View File

@ -36,7 +36,10 @@ fn setup() {
.build();
}
test!(simple {
#[test]
fn simple() {
setup();
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -82,9 +85,12 @@ test!(simple {
fname == b"foo-0.0.1/src/main.rs",
"unexpected filename: {:?}", file.header().path());
}
});
}
#[test]
fn git_deps() {
setup();
test!(git_deps {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -105,9 +111,12 @@ test!(git_deps {
[ERROR] all dependencies must come from the same source.
dependency `foo` comes from git://path/to/nowhere instead
"));
});
}
#[test]
fn path_dependency_no_version() {
setup();
test!(path_dependency_no_version {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -135,9 +144,12 @@ test!(path_dependency_no_version {
[ERROR] all path dependencies must have a version specified when publishing.
dependency `bar` does not specify a version
"));
});
}
#[test]
fn unpublishable_crate() {
setup();
test!(unpublishable_crate {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -155,4 +167,4 @@ test!(unpublishable_crate {
[ERROR] some crates cannot be published.
`foo` is marked as unpublishable
"));
});
}

View File

@ -1,8 +1,6 @@
use support::{project, execs, main_file, basic_bin_manifest};
use hamcrest::{assert_that};
fn setup() {}
fn remove_all_whitespace(s: &str) -> String {
s.split_whitespace().collect()
}
@ -25,7 +23,8 @@ fn read_manifest_output() -> String {
}"#)
}
test!(cargo_read_manifest_path_to_cargo_toml_relative {
#[test]
fn cargo_read_manifest_path_to_cargo_toml_relative() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -35,9 +34,10 @@ test!(cargo_read_manifest_path_to_cargo_toml_relative {
.cwd(p.root().parent().unwrap()),
execs().with_status(0)
.with_stdout(read_manifest_output()));
});
}
test!(cargo_read_manifest_path_to_cargo_toml_absolute {
#[test]
fn cargo_read_manifest_path_to_cargo_toml_absolute() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -47,9 +47,10 @@ test!(cargo_read_manifest_path_to_cargo_toml_absolute {
.cwd(p.root().parent().unwrap()),
execs().with_status(0)
.with_stdout(read_manifest_output()));
});
}
test!(cargo_read_manifest_path_to_cargo_toml_parent_relative {
#[test]
fn cargo_read_manifest_path_to_cargo_toml_parent_relative() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -60,9 +61,10 @@ test!(cargo_read_manifest_path_to_cargo_toml_parent_relative {
execs().with_status(101)
.with_stderr("[ERROR] the manifest-path must be \
a path to a Cargo.toml file"));
});
}
test!(cargo_read_manifest_path_to_cargo_toml_parent_absolute {
#[test]
fn cargo_read_manifest_path_to_cargo_toml_parent_absolute() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -73,9 +75,10 @@ test!(cargo_read_manifest_path_to_cargo_toml_parent_absolute {
execs().with_status(101)
.with_stderr("[ERROR] the manifest-path must be \
a path to a Cargo.toml file"));
});
}
test!(cargo_read_manifest_cwd {
#[test]
fn cargo_read_manifest_cwd() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -84,4 +87,4 @@ test!(cargo_read_manifest_cwd {
.cwd(p.root()),
execs().with_status(0)
.with_stdout(read_manifest_output()));
});
}

View File

@ -8,10 +8,8 @@ use support::git;
use hamcrest::assert_that;
fn setup() {
}
test!(simple {
#[test]
fn simple() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -45,9 +43,10 @@ test!(simple {
",
dir = p.url(),
reg = registry::registry())));
});
}
test!(deps {
#[test]
fn deps() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -74,9 +73,10 @@ test!(deps {
",
dir = p.url(),
reg = registry::registry())));
});
}
test!(nonexistent {
#[test]
fn nonexistent() {
Package::new("init", "0.0.1").publish();
let p = project("foo")
@ -98,9 +98,10 @@ test!(nonexistent {
location searched: registry file://[..]
version required: >= 0.0.0
"));
});
}
test!(wrong_version {
#[test]
fn wrong_version() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -134,9 +135,10 @@ location searched: registry file://[..]
version required: >= 1.0.0
versions found: 0.0.4, 0.0.3, 0.0.2, ...
"));
});
}
test!(bad_cksum {
#[test]
fn bad_cksum() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -165,9 +167,10 @@ Caused by:
Caused by:
failed to verify the checksum of `bad-cksum v0.0.1 (registry file://[..])`
"));
});
}
test!(update_registry {
#[test]
fn update_registry() {
Package::new("init", "0.0.1").publish();
let p = project("foo")
@ -200,9 +203,10 @@ version required: >= 0.0.0
",
dir = p.url(),
reg = registry::registry())));
});
}
test!(package_with_path_deps {
#[test]
fn package_with_path_deps() {
Package::new("init", "0.0.1").publish();
let p = project("foo")
@ -250,9 +254,10 @@ version required: ^0.0.1
[COMPILING] notyet v0.0.1 (registry file://[..])
[COMPILING] foo v0.0.1 ({dir}[..])
", dir = p.url())));
});
}
test!(lockfile_locks {
#[test]
fn lockfile_locks() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -282,9 +287,10 @@ test!(lockfile_locks {
assert_that(p.cargo("build"),
execs().with_status(0).with_stdout(""));
});
}
test!(lockfile_locks_transitively {
#[test]
fn lockfile_locks_transitively() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -318,9 +324,10 @@ test!(lockfile_locks_transitively {
assert_that(p.cargo("build"),
execs().with_status(0).with_stdout(""));
});
}
test!(yanks_are_not_used {
#[test]
fn yanks_are_not_used() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -349,9 +356,10 @@ test!(yanks_are_not_used {
[COMPILING] foo v0.0.1 ({dir})
",
dir = p.url())));
});
}
test!(relying_on_a_yank_is_bad {
#[test]
fn relying_on_a_yank_is_bad() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -376,9 +384,10 @@ location searched: registry file://[..]
version required: = 0.0.2
versions found: 0.0.1
"));
});
}
test!(yanks_in_lockfiles_are_ok {
#[test]
fn yanks_in_lockfiles_are_ok() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -410,9 +419,10 @@ test!(yanks_in_lockfiles_are_ok {
location searched: registry file://[..]
version required: *
"));
});
}
test!(update_with_lockfile_if_packages_missing {
#[test]
fn update_with_lockfile_if_packages_missing() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -437,9 +447,10 @@ test!(update_with_lockfile_if_packages_missing {
[UPDATING] registry `[..]`
[DOWNLOADING] bar v0.0.1 (registry file://[..])
"));
});
}
test!(update_lockfile {
#[test]
fn update_lockfile() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -515,9 +526,10 @@ test!(update_lockfile {
[UPDATING] bar v0.0.4 (registry file://[..]) -> v0.0.5
[REMOVING] spam v0.2.5 (registry file://[..])
"));
});
}
test!(dev_dependency_not_used {
#[test]
fn dev_dependency_not_used() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -542,16 +554,18 @@ test!(dev_dependency_not_used {
[COMPILING] foo v0.0.1 ({dir})
",
dir = p.url())));
});
}
test!(login_with_no_cargo_dir {
#[test]
fn login_with_no_cargo_dir() {
let home = paths::home().join("new-home");
fs::create_dir(&home).unwrap();
assert_that(::cargo_process().arg("login").arg("foo").arg("-v"),
execs().with_status(0));
});
}
test!(bad_license_file {
#[test]
fn bad_license_file() {
Package::new("foo", "1.0.0").publish();
let p = project("all")
.file("Cargo.toml", r#"
@ -570,9 +584,10 @@ test!(bad_license_file {
execs().with_status(101)
.with_stderr_contains("\
[ERROR] the license file `foo` does not exist"));
});
}
test!(updating_a_dep {
#[test]
fn updating_a_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -629,9 +644,10 @@ test!(updating_a_dep {
[COMPILING] foo v0.0.1 ({dir})
",
dir = p.url())));
});
}
test!(git_and_registry_dep {
#[test]
fn git_and_registry_dep() {
let b = git::repo(&paths::root().join("b"))
.file("Cargo.toml", r#"
[project]
@ -678,9 +694,10 @@ test!(git_and_registry_dep {
println!("second");
assert_that(p.cargo("build"),
execs().with_status(0).with_stdout(""));
});
}
test!(update_publish_then_update {
#[test]
fn update_publish_then_update() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -718,9 +735,10 @@ test!(update_publish_then_update {
",
dir = p.url())));
});
}
test!(fetch_downloads {
#[test]
fn fetch_downloads() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -742,9 +760,10 @@ test!(fetch_downloads {
[UPDATING] registry `[..]`
[DOWNLOADING] a v0.1.0 (registry [..])
"));
});
}
test!(update_transitive_dependency {
#[test]
fn update_transitive_dependency() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -781,9 +800,10 @@ test!(update_transitive_dependency {
[COMPILING] a v0.1.0 (registry [..])
[COMPILING] foo v0.5.0 ([..])
"));
});
}
test!(update_backtracking_ok {
#[test]
fn update_backtracking_ok() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -817,9 +837,10 @@ test!(update_backtracking_ok {
.with_stderr("\
[UPDATING] registry `[..]`
"));
});
}
test!(update_multiple_packages {
#[test]
fn update_multiple_packages() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -877,9 +898,10 @@ test!(update_multiple_packages {
[COMPILING] c v0.1.1 (registry [..])")
.with_stderr_contains("\
[COMPILING] foo v0.5.0 ([..])"));
});
}
test!(bundled_crate_in_registry {
#[test]
fn bundled_crate_in_registry() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -917,9 +939,10 @@ test!(bundled_crate_in_registry {
.publish();
assert_that(p.cargo("run"), execs().with_status(0));
});
}
test!(update_same_prefix_oh_my_how_was_this_a_bug {
#[test]
fn update_same_prefix_oh_my_how_was_this_a_bug() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -941,9 +964,10 @@ test!(update_same_prefix_oh_my_how_was_this_a_bug {
assert_that(p.cargo("generate-lockfile"), execs().with_status(0));
assert_that(p.cargo("update").arg("-pfoobar").arg("--precise=0.2.0"),
execs().with_status(0));
});
}
test!(use_semver {
#[test]
fn use_semver() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -960,9 +984,10 @@ test!(use_semver {
Package::new("foo", "1.2.3-alpha.0").publish();
assert_that(p.cargo("build"), execs().with_status(0));
});
}
test!(only_download_relevant {
#[test]
fn only_download_relevant() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -991,9 +1016,10 @@ test!(only_download_relevant {
[COMPILING] baz v0.1.0 ([..])
[COMPILING] bar v0.5.0 ([..])
"));
});
}
test!(resolve_and_backtracking {
#[test]
fn resolve_and_backtracking() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1014,4 +1040,4 @@ test!(resolve_and_backtracking {
assert_that(p.cargo("build"),
execs().with_status(0));
});
}

View File

@ -3,10 +3,8 @@ use std::path::MAIN_SEPARATOR as SEP;
use support::{project, execs, path2url};
use hamcrest::{assert_that, existing_file};
fn setup() {
}
test!(simple {
#[test]
fn simple() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -27,9 +25,10 @@ test!(simple {
hello
"));
assert_that(&p.bin("foo"), existing_file());
});
}
test!(simple_quiet {
#[test]
fn simple_quiet() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -46,9 +45,10 @@ test!(simple_quiet {
hello
")
);
});
}
test!(simple_quiet_and_verbose {
#[test]
fn simple_quiet_and_verbose() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -64,9 +64,10 @@ test!(simple_quiet_and_verbose {
execs().with_status(101).with_stderr("\
[ERROR] cannot set both --verbose and --quiet
"));
});
}
test!(quiet_and_verbose_config {
#[test]
fn quiet_and_verbose_config() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -84,9 +85,10 @@ test!(quiet_and_verbose_config {
assert_that(p.cargo_process("run").arg("-q"),
execs().with_status(0));
});
}
test!(simple_with_args {
#[test]
fn simple_with_args() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -103,9 +105,10 @@ test!(simple_with_args {
assert_that(p.cargo_process("run").arg("hello").arg("world"),
execs().with_status(0));
});
}
test!(exit_code {
#[test]
fn exit_code() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -124,9 +127,10 @@ test!(exit_code {
[RUNNING] `target[..]`
[ERROR] Process didn't exit successfully: `target[..]foo[..]` (exit code: 2)
"));
});
}
test!(exit_code_verbose {
#[test]
fn exit_code_verbose() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -146,9 +150,10 @@ test!(exit_code_verbose {
[RUNNING] `target[..]`
[ERROR] Process didn't exit successfully: `target[..]foo[..]` (exit code: 2)
"));
});
}
test!(no_main_file {
#[test]
fn no_main_file() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -162,9 +167,10 @@ test!(no_main_file {
execs().with_status(101)
.with_stderr("[ERROR] a bin target must be available \
for `cargo run`\n"));
});
}
test!(too_many_bins {
#[test]
fn too_many_bins() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -181,9 +187,10 @@ test!(too_many_bins {
.with_stderr("[ERROR] `cargo run` requires that a project only \
have one executable; use the `--bin` option \
to specify which one to run\n"));
});
}
test!(specify_name {
#[test]
fn specify_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -221,9 +228,10 @@ hello a.rs
.with_stdout("\
hello b.rs
"));
});
}
test!(run_example {
#[test]
fn run_example() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -247,9 +255,10 @@ test!(run_example {
.with_stdout("\
example
"));
});
}
test!(run_with_filename {
#[test]
fn run_with_filename() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -285,9 +294,10 @@ Did you mean `a`?"));
[ERROR] no example target named `a.rs`
Did you mean `a`?"));
});
}
test!(either_name_or_example {
#[test]
fn either_name_or_example() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -307,9 +317,10 @@ test!(either_name_or_example {
.with_stderr("[ERROR] `cargo run` can run at most one \
executable, but multiple were \
specified"));
});
}
test!(one_bin_multiple_examples {
#[test]
fn one_bin_multiple_examples() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -336,9 +347,10 @@ test!(one_bin_multiple_examples {
.with_stdout("\
hello main.rs
"));
});
}
test!(example_with_release_flag {
#[test]
fn example_with_release_flag() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -438,9 +450,10 @@ fast2"));
.with_stdout("\
slow1
slow2"));
});
}
test!(run_dylib_dep {
#[test]
fn run_dylib_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -469,9 +482,10 @@ test!(run_dylib_dep {
assert_that(p.cargo_process("run").arg("hello").arg("world"),
execs().with_status(0));
});
}
test!(release_works {
#[test]
fn release_works() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -491,9 +505,10 @@ test!(release_works {
dir = path2url(p.root()),
sep = SEP)));
assert_that(&p.release_bin("foo"), existing_file());
});
}
test!(run_bin_different_name {
#[test]
fn run_bin_different_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -509,9 +524,10 @@ test!(run_bin_different_name {
"#);
assert_that(p.cargo_process("run"), execs().with_status(0));
});
}
test!(dashes_are_forwarded {
#[test]
fn dashes_are_forwarded() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -533,9 +549,10 @@ test!(dashes_are_forwarded {
assert_that(p.cargo_process("run").arg("--").arg("a").arg("--").arg("b"),
execs().with_status(0));
});
}
test!(run_from_executable_folder {
#[test]
fn run_from_executable_folder() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -557,4 +574,4 @@ test!(run_from_executable_folder {
.with_stdout("\
hello
"));
});
}

View File

@ -4,14 +4,12 @@ use support::{execs, project};
use hamcrest::assert_that;
fn setup() {
}
const CARGO_RUSTC_ERROR: &'static str =
"[ERROR] extra arguments to `rustc` can only be passed to one target, consider filtering
the package by passing e.g. `--lib` or `--bin NAME` to specify a single target";
test!(build_lib_for_foo {
#[test]
fn build_lib_for_foo() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -36,9 +34,10 @@ test!(build_lib_for_foo {
-L dependency={dir}{sep}target{sep}debug{sep}deps`
", sep = SEP,
dir = p.root().display(), url = p.url())));
});
}
test!(lib {
#[test]
fn lib() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -65,9 +64,10 @@ test!(lib {
-L dependency={dir}{sep}target{sep}debug{sep}deps`
", sep = SEP,
dir = p.root().display(), url = p.url())))
});
}
test!(build_main_and_allow_unstable_options {
#[test]
fn build_main_and_allow_unstable_options() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -101,9 +101,10 @@ test!(build_main_and_allow_unstable_options {
", sep = SEP,
dir = p.root().display(), url = p.url(),
name = "foo", version = "0.0.1")));
});
}
test!(fails_when_trying_to_build_main_and_lib_with_args {
#[test]
fn fails_when_trying_to_build_main_and_lib_with_args() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -121,9 +122,10 @@ test!(fails_when_trying_to_build_main_and_lib_with_args {
execs()
.with_status(101)
.with_stderr(CARGO_RUSTC_ERROR));
});
}
test!(build_with_args_to_one_of_multiple_binaries {
#[test]
fn build_with_args_to_one_of_multiple_binaries() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -154,9 +156,10 @@ test!(build_with_args_to_one_of_multiple_binaries {
-C debug-assertions [..]`
", sep = SEP,
dir = p.root().display(), url = p.url())));
});
}
test!(fails_with_args_to_all_binaries {
#[test]
fn fails_with_args_to_all_binaries() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -180,9 +183,10 @@ test!(fails_with_args_to_all_binaries {
execs()
.with_status(101)
.with_stderr(CARGO_RUSTC_ERROR));
});
}
test!(build_with_args_to_one_of_multiple_tests {
#[test]
fn build_with_args_to_one_of_multiple_tests() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -207,9 +211,10 @@ test!(build_with_args_to_one_of_multiple_tests {
-C debug-assertions [..]--test[..]`
", sep = SEP,
dir = p.root().display(), url = p.url())));
});
}
test!(build_foo_with_bar_dependency {
#[test]
fn build_foo_with_bar_dependency() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -248,9 +253,10 @@ test!(build_foo_with_bar_dependency {
[RUNNING] `[..] -g -C debug-assertions [..]`
",
url = foo.url())));
});
}
test!(build_only_bar_dependency {
#[test]
fn build_only_bar_dependency() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -287,9 +293,10 @@ test!(build_only_bar_dependency {
[COMPILING] bar v0.1.0 ([..])
[RUNNING] `[..]--crate-name bar --crate-type lib [..] -C debug-assertions [..]`
"));
});
}
test!(fail_with_multiple_packages {
#[test]
fn fail_with_multiple_packages() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -343,9 +350,10 @@ test!(fail_with_multiple_packages {
Usage:
cargo rustc [options] [--] [<opts>...]"));
});
}
test!(rustc_with_other_profile {
#[test]
fn rustc_with_other_profile() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -373,4 +381,4 @@ test!(rustc_with_other_profile {
assert_that(foo.cargo("rustc").arg("--profile").arg("test"),
execs().with_status(0));
});
}

View File

@ -2,11 +2,8 @@ use std::path::MAIN_SEPARATOR as SEP;
use support::{execs, project};
use hamcrest::{assert_that};
fn setup() {
}
test!(rustdoc_simple {
#[test]
fn rustdoc_simple() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -27,9 +24,10 @@ test!(rustdoc_simple {
-L dependency={dir}{sep}target{sep}debug{sep}deps`
", sep = SEP,
dir = p.root().display(), url = p.url())));
});
}
test!(rustdoc_args {
#[test]
fn rustdoc_args() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -51,11 +49,12 @@ test!(rustdoc_args {
-L dependency={dir}{sep}target{sep}debug{sep}deps`
", sep = SEP,
dir = p.root().display(), url = p.url())));
});
}
test!(rustdoc_foo_with_bar_dependency {
#[test]
fn rustdoc_foo_with_bar_dependency() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -97,9 +96,10 @@ test!(rustdoc_foo_with_bar_dependency {
--extern [..]`
", sep = SEP,
dir = foo.root().display(), url = foo.url())));
});
}
test!(rustdoc_only_bar_dependency {
#[test]
fn rustdoc_only_bar_dependency() {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
@ -141,10 +141,11 @@ test!(rustdoc_only_bar_dependency {
-L dependency={dir}{sep}target{sep}debug{sep}deps`
", sep = SEP,
dir = foo.root().display())));
});
}
test!(rustdoc_same_name_err {
#[test]
fn rustdoc_same_name_err() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -164,4 +165,4 @@ test!(rustdoc_same_name_err {
.with_stderr("[ERROR] cannot document a package where a library and a \
binary have the same name. Consider renaming one \
or marking the target as `doc = false`"));
});
}

View File

@ -39,7 +39,10 @@ fn cargo_process(s: &str) -> ProcessBuilder {
return b
}
test!(simple {
#[test]
fn simple() {
setup();
let contents = r#"{
"crates": [{
"created_at": "2014-11-16T20:17:35Z",
@ -85,9 +88,12 @@ test!(simple {
[UPDATING] registry `[..]`")
.with_stdout("\
hoare (0.1.1) Design by contract style assertions for Rust"));
});
}
#[test]
fn multiple_query_params() {
setup();
test!(multiple_query_params {
let contents = r#"{
"crates": [{
"created_at": "2014-11-16T20:17:35Z",
@ -133,11 +139,12 @@ test!(multiple_query_params {
[UPDATING] registry `[..]`")
.with_stdout("\
hoare (0.1.1) Design by contract style assertions for Rust"));
});
}
test!(help {
#[test]
fn help() {
assert_that(cargo_process("search").arg("-h"),
execs().with_status(0));
assert_that(cargo_process("help").arg("search"),
execs().with_status(0));
});
}

View File

@ -7,9 +7,8 @@ use support::paths::CargoPathExt;
use hamcrest::{assert_that, existing_file, is_not};
use cargo::util::process;
fn setup() {}
test!(cargo_test_simple {
#[test]
fn cargo_test_simple() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", r#"
@ -43,9 +42,10 @@ test test_hello ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(cargo_test_release {
#[test]
fn cargo_test_release() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -107,9 +107,10 @@ running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(cargo_test_verbose {
#[test]
fn cargo_test_verbose() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", r#"
@ -129,9 +130,10 @@ test test_hello ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(many_similar_names {
#[test]
fn many_similar_names() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -158,9 +160,10 @@ test!(many_similar_names {
assert!(output.contains("test bin_test"), "bin_test missing\n{}", output);
assert!(output.contains("test lib_test"), "lib_test missing\n{}", output);
assert!(output.contains("test test_test"), "test_test missing\n{}", output);
});
}
test!(cargo_test_failing_test {
#[test]
fn cargo_test_failing_test() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", r#"
@ -206,9 +209,10 @@ failures:
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
")
.with_status(101));
});
}
test!(test_with_lib_dep {
#[test]
fn test_with_lib_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -266,9 +270,10 @@ test foo_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"))
});
}
test!(test_with_deep_lib_dep {
#[test]
fn test_with_deep_lib_dep() {
let p = project("bar")
.file("Cargo.toml", r#"
[package]
@ -326,9 +331,10 @@ test bar_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(external_test_explicit {
#[test]
fn external_test_explicit() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -377,9 +383,10 @@ running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
"))
});
}
test!(external_test_implicit {
#[test]
fn external_test_implicit() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -424,9 +431,10 @@ running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
"))
});
}
test!(dont_run_examples {
#[test]
fn dont_run_examples() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -441,9 +449,10 @@ test!(dont_run_examples {
"#);
assert_that(p.cargo_process("test"),
execs().with_status(0));
});
}
test!(pass_through_command_line {
#[test]
fn pass_through_command_line() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -492,11 +501,12 @@ running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
// Regression test for running cargo-test twice with
// tests in an rlib
test!(cargo_test_twice {
#[test]
fn cargo_test_twice() {
let p = project("test_twice")
.file("Cargo.toml", &basic_lib_manifest("test_twice"))
.file("src/test_twice.rs", r#"
@ -512,9 +522,10 @@ test!(cargo_test_twice {
assert_that(p.cargo("test"),
execs().with_status(0));
}
});
}
test!(lib_bin_same_name {
#[test]
fn lib_bin_same_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -561,9 +572,10 @@ running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
"))
});
}
test!(lib_with_standard_name {
#[test]
fn lib_with_standard_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -613,9 +625,10 @@ test foo_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(lib_with_standard_name2 {
#[test]
fn lib_with_standard_name2() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -652,9 +665,10 @@ test test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(lib_without_name {
#[test]
fn lib_without_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -690,9 +704,10 @@ test test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(bin_without_name {
#[test]
fn bin_without_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -726,9 +741,10 @@ test!(bin_without_name {
Caused by:
binary target bin.name is required"));
});
}
test!(bench_without_name {
#[test]
fn bench_without_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -770,9 +786,10 @@ test!(bench_without_name {
Caused by:
bench target bench.name is required"));
});
}
test!(test_without_name {
#[test]
fn test_without_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -813,9 +830,10 @@ test!(test_without_name {
Caused by:
test target test.name is required"));
});
}
test!(example_without_name {
#[test]
fn example_without_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -856,9 +874,10 @@ test!(example_without_name {
Caused by:
example target example.name is required"));
});
}
test!(bin_there_for_integration {
#[test]
fn bin_there_for_integration() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -883,9 +902,10 @@ test!(bin_there_for_integration {
let output = str::from_utf8(&output.stdout).unwrap();
assert!(output.contains("main_test ... ok"), "no main_test\n{}", output);
assert!(output.contains("test_test ... ok"), "no test_test\n{}", output);
});
}
test!(test_dylib {
#[test]
fn test_dylib() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -968,9 +988,10 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(test_twice_with_build_cmd {
#[test]
fn test_twice_with_build_cmd() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1021,9 +1042,10 @@ running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(test_then_build {
#[test]
fn test_then_build() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1058,9 +1080,10 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
assert_that(p.cargo("build"),
execs().with_status(0)
.with_stdout(""));
});
}
test!(test_no_run {
#[test]
fn test_no_run() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1079,9 +1102,10 @@ test!(test_no_run {
[COMPILING] foo v0.0.1 ({dir})
",
dir = p.url())));
});
}
test!(test_run_specific_bin_target {
#[test]
fn test_run_specific_bin_target() {
let prj = project("foo")
.file("Cargo.toml" , r#"
[package]
@ -1112,9 +1136,10 @@ test test2 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(test_run_specific_test_target {
#[test]
fn test_run_specific_test_target() {
let prj = project("foo")
.file("Cargo.toml" , r#"
[package]
@ -1139,9 +1164,10 @@ test test_b ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(test_no_harness {
#[test]
fn test_no_harness() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1168,9 +1194,10 @@ test!(test_no_harness {
[RUNNING] target[..]bar-[..]
",
dir = p.url())));
});
}
test!(selective_testing {
#[test]
fn selective_testing() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1264,9 +1291,10 @@ running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(almost_cyclic_but_not_quite {
#[test]
fn almost_cyclic_but_not_quite() {
let p = project("a")
.file("Cargo.toml", r#"
[package]
@ -1306,9 +1334,10 @@ test!(almost_cyclic_but_not_quite {
assert_that(p.cargo_process("build"), execs().with_status(0));
assert_that(p.cargo("test"),
execs().with_status(0));
});
}
test!(build_then_selective_test {
#[test]
fn build_then_selective_test() {
let p = project("a")
.file("Cargo.toml", r#"
[package]
@ -1333,9 +1362,10 @@ test!(build_then_selective_test {
p.root().move_into_the_past().unwrap();
assert_that(p.cargo("test").arg("-p").arg("b"),
execs().with_status(0));
});
}
test!(example_dev_dep {
#[test]
fn example_dev_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
@ -1378,9 +1408,10 @@ test!(example_dev_dep {
assert_that(p.cargo("run")
.arg("--example").arg("e1").arg("--release").arg("-v"),
execs().with_status(0));
});
}
test!(selective_testing_with_docs {
#[test]
fn selective_testing_with_docs() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1427,9 +1458,10 @@ running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(example_bin_same_name {
#[test]
fn example_bin_same_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1463,9 +1495,10 @@ test!(example_bin_same_name {
bin
"));
assert_that(&p.bin("foo"), existing_file());
});
}
test!(test_with_example_twice {
#[test]
fn test_with_example_twice() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1484,9 +1517,10 @@ test!(test_with_example_twice {
assert_that(p.cargo("test").arg("-v"),
execs().with_status(0));
assert_that(&p.bin("examples/foo"), existing_file());
});
}
test!(example_with_dev_dep {
#[test]
fn example_with_dev_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1521,9 +1555,10 @@ test!(example_with_dev_dep {
[..]
[RUNNING] `rustc [..] --crate-name ex [..] --extern a=[..]`
"));
});
}
test!(bin_is_preserved {
#[test]
fn bin_is_preserved() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1542,9 +1577,10 @@ test!(bin_is_preserved {
assert_that(p.cargo("test").arg("-v"),
execs().with_status(0));
assert_that(&p.bin("foo"), existing_file());
});
}
test!(bad_example {
#[test]
fn bad_example() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1562,9 +1598,10 @@ test!(bad_example {
execs().with_status(101).with_stderr("\
[ERROR] no bin target named `foo`
"));
});
}
test!(doctest_feature {
#[test]
fn doctest_feature() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1600,9 +1637,10 @@ test foo_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"))
});
}
test!(dashes_to_underscores {
#[test]
fn dashes_to_underscores() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1619,9 +1657,10 @@ test!(dashes_to_underscores {
assert_that(p.cargo_process("test").arg("-v"),
execs().with_status(0));
});
}
test!(doctest_dev_dep {
#[test]
fn doctest_dev_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1648,9 +1687,10 @@ test!(doctest_dev_dep {
assert_that(p.cargo_process("test").arg("-v"),
execs().with_status(0));
});
}
test!(filter_no_doc_tests {
#[test]
fn filter_no_doc_tests() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1676,9 +1716,10 @@ running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(dylib_doctest {
#[test]
fn dylib_doctest() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1709,9 +1750,10 @@ test foo_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(dylib_doctest2 {
#[test]
fn dylib_doctest2() {
// can't doctest dylibs as they're statically linked together
let p = project("foo")
.file("Cargo.toml", r#"
@ -1734,9 +1776,10 @@ test!(dylib_doctest2 {
assert_that(p.cargo_process("test"),
execs().with_stdout(""));
});
}
test!(cyclic_dev_dep_doc_test {
#[test]
fn cyclic_dev_dep_doc_test() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1782,9 +1825,10 @@ test _0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"))
});
}
test!(dev_dep_with_build_script {
#[test]
fn dev_dep_with_build_script() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1808,9 +1852,10 @@ test!(dev_dep_with_build_script {
.file("bar/build.rs", "fn main() {}");
assert_that(p.cargo_process("test"),
execs().with_status(0));
});
}
test!(no_fail_fast {
#[test]
fn no_fail_fast() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1885,9 +1930,10 @@ test sub_one_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
"))
});
}
test!(test_multiple_packages {
#[test]
fn test_multiple_packages() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1945,9 +1991,10 @@ running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
"));
});
}
test!(bin_does_not_rebuild_tests {
#[test]
fn bin_does_not_rebuild_tests() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -1974,9 +2021,10 @@ test!(bin_does_not_rebuild_tests {
[RUNNING] `rustc src[..]main.rs [..]`
[RUNNING] `rustc src[..]main.rs [..]`
"));
});
}
test!(selective_test_wonky_profile {
#[test]
fn selective_test_wonky_profile() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -2003,9 +2051,10 @@ test!(selective_test_wonky_profile {
assert_that(p.cargo("test").arg("-v").arg("--no-run").arg("--release")
.arg("-p").arg("foo").arg("-p").arg("a"),
execs().with_status(0));
});
}
test!(selective_test_optional_dep {
#[test]
fn selective_test_optional_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -2033,9 +2082,10 @@ test!(selective_test_optional_dep {
[RUNNING] `rustc a[..]src[..]lib.rs [..]`
[RUNNING] `rustc a[..]src[..]lib.rs [..]`
"));
});
}
test!(only_test_docs {
#[test]
fn only_test_docs() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
@ -2070,9 +2120,10 @@ test bar_0 ... ok
test result: ok.[..]
"));
});
}
test!(test_panic_abort_with_dep {
#[test]
fn test_panic_abort_with_dep() {
if !::is_nightly() {
return
}
@ -2104,4 +2155,4 @@ test!(test_panic_abort_with_dep {
.file("bar/src/lib.rs", "");
assert_that(p.cargo_process("test").arg("-v"),
execs().with_status(0));
});
}

View File

@ -1,10 +1,8 @@
use support::{path2url, project, execs};
use hamcrest::assert_that;
fn setup() {
}
test!(pathless_tools {
#[test]
fn pathless_tools() {
let target = ::rustc_host();
let foo = project("foo")
@ -29,9 +27,10 @@ test!(pathless_tools {
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc [..] -C ar=nonexistent-ar -C linker=nonexistent-linker [..]`
", url = foo.url())))
});
}
test!(absolute_tools {
#[test]
fn absolute_tools() {
let target = ::rustc_host();
// Escaped as they appear within a TOML config file
@ -69,9 +68,10 @@ test!(absolute_tools {
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc [..] -C ar={ar} -C linker={linker} [..]`
", url = foo.url(), ar = output.0, linker = output.1)))
});
}
test!(relative_tools {
#[test]
fn relative_tools() {
let target = ::rustc_host();
// Escaped as they appear within a TOML config file
@ -116,4 +116,4 @@ test!(relative_tools {
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc [..] -C ar={ar} -C linker={linker} [..]`
", url = foo_url, ar = output.0, linker = output.1)))
});
}

View File

@ -1,13 +1,12 @@
use support::{project, execs, main_file, basic_bin_manifest};
use hamcrest::{assert_that};
fn setup() {}
fn verify_project_success_output() -> String {
r#"{"success":"true"}"#.into()
}
test!(cargo_verify_project_path_to_cargo_toml_relative {
#[test]
fn cargo_verify_project_path_to_cargo_toml_relative() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -17,9 +16,10 @@ test!(cargo_verify_project_path_to_cargo_toml_relative {
.cwd(p.root().parent().unwrap()),
execs().with_status(0)
.with_stdout(verify_project_success_output()));
});
}
test!(cargo_verify_project_path_to_cargo_toml_absolute {
#[test]
fn cargo_verify_project_path_to_cargo_toml_absolute() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -29,9 +29,10 @@ test!(cargo_verify_project_path_to_cargo_toml_absolute {
.cwd(p.root().parent().unwrap()),
execs().with_status(0)
.with_stdout(verify_project_success_output()));
});
}
test!(cargo_verify_project_cwd {
#[test]
fn cargo_verify_project_cwd() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
@ -40,4 +41,4 @@ test!(cargo_verify_project_cwd {
.cwd(p.root()),
execs().with_status(0)
.with_stdout(verify_project_success_output()));
});
}

View File

@ -2,9 +2,8 @@ use support::{project, execs};
use hamcrest::assert_that;
use cargo;
fn setup() {}
test!(simple {
#[test]
fn simple() {
let p = project("foo");
assert_that(p.cargo_process("version"),
@ -15,7 +14,7 @@ test!(simple {
execs().with_status(0).with_stdout(&format!("{}\n",
cargo::version())));
});
}
#[derive(RustcDecodable)]
struct FooFlags {
@ -31,7 +30,8 @@ fn real_main(flags: FooFlags, _config: &cargo::Config) ->
}
}
test!(subcommand_with_version_using_exec_main_without_stdin {
#[test]
fn subcommand_with_version_using_exec_main_without_stdin() {
let usage = "
Usage: cargo foo [--version]
@ -44,4 +44,4 @@ Options:
real_main, &cargo::Config::default().unwrap(),
usage, &args, false);
assert_eq!(result.unwrap(), Some("foo <version>".to_string()));
});
}

View File

@ -10,9 +10,6 @@ use cargo::util::CargoResult;
use support::{Tap, execs, shell_writes};
fn setup() {
}
struct Sink(Arc<Mutex<Vec<u8>>>);
impl Write for Sink {
@ -22,7 +19,8 @@ impl Write for Sink {
fn flush(&mut self) -> io::Result<()> { Ok(()) }
}
test!(non_tty {
#[test]
fn non_tty() {
let config = ShellConfig { color_config: Auto, tty: false };
let a = Arc::new(Mutex::new(Vec::new()));
@ -31,9 +29,10 @@ test!(non_tty {
});
let buf = a.lock().unwrap().clone();
assert_that(&buf[..], shell_writes("Hey Alex\n"));
});
}
test!(color_explicitly_disabled {
#[test]
fn color_explicitly_disabled() {
let term = TerminfoTerminal::new(Vec::new());
if term.is_none() { return }
@ -45,9 +44,10 @@ test!(color_explicitly_disabled {
});
let buf = a.lock().unwrap().clone();
assert_that(&buf[..], shell_writes("Hey Alex\n"));
});
}
test!(colored_shell {
#[test]
fn colored_shell() {
let term = TerminfoTerminal::new(Vec::new());
if term.is_none() { return }
@ -61,9 +61,10 @@ test!(colored_shell {
assert_that(&buf[..],
shell_writes(colored_output("Hey Alex\n",
color::RED).unwrap()));
});
}
test!(color_explicitly_enabled {
#[test]
fn color_explicitly_enabled() {
let term = TerminfoTerminal::new(Vec::new());
if term.is_none() { return }
@ -77,13 +78,14 @@ test!(color_explicitly_enabled {
assert_that(&buf[..],
shell_writes(colored_output("Hey Alex\n",
color::RED).unwrap()));
});
}
test!(no_term {
#[test]
fn no_term() {
// Verify that shell creation is successful when $TERM does not exist.
assert_that(::cargo_process().env_remove("TERM"),
execs().with_stderr(""));
});
}
fn colored_output(string: &str, color: color::Color) -> CargoResult<String> {
let mut term = TerminfoTerminal::new(Vec::new()).unwrap();

View File

@ -23,16 +23,6 @@ use std::ffi::OsStr;
use std::time::Duration;
mod support;
macro_rules! test {
($name:ident $expr:expr) => (
#[test]
fn $name() {
::support::paths::setup();
setup();
$expr;
}
)
}
mod test_bad_config;
mod test_bad_manifest_path;