From 6950bbb0b4bb1a56b73a6a5c9c6fd0bdf346ac12 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 25 May 2016 13:55:42 -0700 Subject: [PATCH 1/2] 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. --- tests/support/paths.rs | 37 ++- tests/test_bad_config.rs | 97 +++--- tests/test_bad_manifest_path.rs | 302 ++++++++++-------- tests/test_cargo.rs | 38 +-- tests/test_cargo_bench.rs | 107 ++++--- tests/test_cargo_build_auth.rs | 18 +- tests/test_cargo_build_lib.rs | 18 +- tests/test_cargo_cfg.rs | 37 ++- tests/test_cargo_clean.rs | 38 +-- tests/test_cargo_compile.rs | 373 ++++++++++++++--------- tests/test_cargo_compile_custom_build.rs | 238 +++++++++------ tests/test_cargo_compile_git_deps.rs | 153 ++++++---- tests/test_cargo_compile_path_deps.rs | 88 +++--- tests/test_cargo_compile_plugins.rs | 28 +- tests/test_cargo_compile_rustflags.rs | 133 ++++---- tests/test_cargo_concurrent.rs | 47 +-- tests/test_cargo_config.rs | 8 +- tests/test_cargo_cross_compile.rs | 93 +++--- tests/test_cargo_death.rs | 7 +- tests/test_cargo_doc.rs | 98 +++--- tests/test_cargo_features.rs | 118 ++++--- tests/test_cargo_fetch.rs | 7 +- tests/test_cargo_freshness.rs | 42 +-- tests/test_cargo_generate_lockfile.rs | 22 +- tests/test_cargo_init.rs | 133 ++++---- tests/test_cargo_install.rs | 158 ++++++---- tests/test_cargo_metadata.rs | 47 +-- tests/test_cargo_net_config.rs | 12 +- tests/test_cargo_new.rs | 123 ++++---- tests/test_cargo_overrides.rs | 72 +++-- tests/test_cargo_package.rs | 63 ++-- tests/test_cargo_profiles.rs | 13 +- tests/test_cargo_publish.rs | 28 +- tests/test_cargo_read_manifest.rs | 27 +- tests/test_cargo_registry.rs | 148 +++++---- tests/test_cargo_run.rs | 103 ++++--- tests/test_cargo_rustc.rs | 58 ++-- tests/test_cargo_rustdoc.rs | 29 +- tests/test_cargo_search.rs | 19 +- tests/test_cargo_test.rs | 267 +++++++++------- tests/test_cargo_tool_paths.rs | 18 +- tests/test_cargo_verify_project.rs | 17 +- tests/test_cargo_version.rs | 12 +- tests/test_shell.rs | 28 +- tests/tests.rs | 10 - 45 files changed, 2055 insertions(+), 1477 deletions(-) diff --git a/tests/support/paths.rs b/tests/support/paths.rs index 2a25d93b1f3..837cface05f 100644 --- a/tests/support/paths.rs +++ b/tests/support/paths.rs @@ -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 = 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(); -} diff --git a/tests/test_bad_config.rs b/tests/test_bad_config.rs index 93eaee21310..21c55fd6d6b 100644 --- a/tests/test_bad_config.rs +++ b/tests/test_bad_config.rs @@ -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 ")); -}); +} diff --git a/tests/test_bad_manifest_path.rs b/tests/test_bad_manifest_path.rs index 88ea145d918..ed10ed7cab8 100644 --- a/tests/test_bad_manifest_path.rs +++ b/tests/test_bad_manifest_path.rs @@ -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\"}\ ")); -}); +} diff --git a/tests/test_cargo.rs b/tests/test_cargo.rs index cbc6f9d75d8..512dd956b7f 100644 --- a/tests/test_cargo.rs +++ b/tests/test_cargo.rs @@ -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 { 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 { 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 "]"#)); -}); +} -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)); -}); +} diff --git a/tests/test_cargo_bench.rs b/tests/test_cargo_bench.rs index bdb54784161..1aae2b323eb 100644 --- a/tests/test_cargo_bench.rs +++ b/tests/test_cargo_bench.rs @@ -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 '
' 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 ")); -}); +} diff --git a/tests/test_cargo_build_auth.rs b/tests/test_cargo_build_auth.rs index 1276f2c12f7..050caf2cf2a 100644 --- a/tests/test_cargo_build_auth.rs +++ b/tests/test_cargo_build_auth.rs @@ -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(); -}); +} diff --git a/tests/test_cargo_build_lib.rs b/tests/test_cargo_build_lib.rs index dc263d824d7..ee8e7fc978f 100644 --- a/tests/test_cargo_build_lib.rs +++ b/tests/test_cargo_build_lib.rs @@ -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)); -}); +} diff --git a/tests/test_cargo_cfg.rs b/tests/test_cargo_cfg.rs index 3d45b7fea43..7f85d58a93f 100644 --- a/tests/test_cargo_cfg.rs +++ b/tests/test_cargo_cfg.rs @@ -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)); -}); +} diff --git a/tests/test_cargo_clean.rs b/tests/test_cargo_clean.rs index 3efff07f23b..25f77423b2c 100644 --- a/tests/test_cargo_clean.rs +++ b/tests/test_cargo_clean.rs @@ -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)); -}); +} diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 0bd2d951be3..0daee9e87d1 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -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/.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 [..]")); -}); +} diff --git a/tests/test_cargo_compile_custom_build.rs b/tests/test_cargo_compile_custom_build.rs index f2434f26bad..d51e4cae251 100644 --- a/tests/test_cargo_compile_custom_build.rs +++ b/tests/test_cargo_compile_custom_build.rs @@ -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)); -}); +} diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index c63180dd9ca..14825ba36bc 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -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)); -}); +} diff --git a/tests/test_cargo_compile_path_deps.rs b/tests/test_cargo_compile_path_deps.rs index d411aa18126..e2f2d36e22c 100644 --- a/tests/test_cargo_compile_path_deps.rs +++ b/tests/test_cargo_compile_path_deps.rs @@ -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 [..]) ")); -}); +} diff --git a/tests/test_cargo_compile_plugins.rs b/tests/test_cargo_compile_plugins.rs index afaf83cced7..4c3c3183e89 100644 --- a/tests/test_cargo_compile_plugins.rs +++ b/tests/test_cargo_compile_plugins.rs @@ -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 [..] ")); -}); +} diff --git a/tests/test_cargo_compile_rustflags.rs b/tests/test_cargo_compile_rustflags.rs index a95184cadfd..8984b527a99 100644 --- a/tests/test_cargo_compile_rustflags.rs +++ b/tests/test_cargo_compile_rustflags.rs @@ -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)); -}); +} diff --git a/tests/test_cargo_concurrent.rs b/tests/test_cargo_concurrent.rs index 8c73bdbcd1c..fb74771c7ab 100644 --- a/tests/test_cargo_concurrent.rs +++ b/tests/test_cargo_concurrent.rs @@ -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 [..] ")); -}); +} diff --git a/tests/test_cargo_config.rs b/tests/test_cargo_config.rs index 6de6aad524f..c3aa0563d37 100644 --- a/tests/test_cargo_config.rs +++ b/tests/test_cargo_config.rs @@ -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)); -}); +} diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index da4397e9ced..095aaeba3a8 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -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)); -}); +} diff --git a/tests/test_cargo_death.rs b/tests/test_cargo_death.rs index 3233a5c62cc..097dbdc124e 100644 --- a/tests/test_cargo_death.rs +++ b/tests/test_cargo_death.rs @@ -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) { diff --git a/tests/test_cargo_doc.rs b/tests/test_cargo_doc.rs index aeb77261367..a39fed883df 100644 --- a/tests/test_cargo_doc.rs +++ b/tests/test_cargo_doc.rs @@ -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()); -}); +} diff --git a/tests/test_cargo_features.rs b/tests/test_cargo_features.rs index 404dfd5ea41..a46d51f830a 100644 --- a/tests/test_cargo_features.rs +++ b/tests/test_cargo_features.rs @@ -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)); -}); +} diff --git a/tests/test_cargo_fetch.rs b/tests/test_cargo_fetch.rs index b0bf231df30..d2d53029110 100644 --- a/tests/test_cargo_fetch.rs +++ b/tests/test_cargo_fetch.rs @@ -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("")); -}); +} diff --git a/tests/test_cargo_freshness.rs b/tests/test_cargo_freshness.rs index 5a74a9b714f..e049c26e9e7 100644 --- a/tests/test_cargo_freshness.rs +++ b/tests/test_cargo_freshness.rs @@ -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()))); -}); +} diff --git a/tests/test_cargo_generate_lockfile.rs b/tests/test_cargo_generate_lockfile.rs index ccd5dd73698..b4d7236c2b3 100644 --- a/tests/test_cargo_generate_lockfile.rs +++ b/tests/test_cargo_generate_lockfile.rs @@ -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()); -}); +} diff --git a/tests/test_cargo_init.rs b/tests/test_cargo_init.rs index d2075e3a7e0..b902cb0bf89 100644 --- a/tests/test_cargo_init.rs +++ b/tests/test_cargo_init.rs @@ -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] [] 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 "))); -}); +} diff --git a/tests/test_cargo_install.rs b/tests/test_cargo_install.rs index ad82951c438..bc5be24c0d3 100644 --- a/tests/test_cargo_install.rs +++ b/tests/test_cargo_install.rs @@ -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 '
' 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")); -}); +} diff --git a/tests/test_cargo_metadata.rs b/tests/test_cargo_metadata.rs index 4a370e598dc..eee4486c5ce 100644 --- a/tests/test_cargo_metadata.rs +++ b/tests/test_cargo_metadata.rs @@ -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")); -}); +} diff --git a/tests/test_cargo_net_config.rs b/tests/test_cargo_net_config.rs index b1b22f7cb2f..92389f62587 100644 --- a/tests/test_cargo_net_config.rs +++ b/tests/test_cargo_net_config.rs @@ -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] [..]"))); -}); +} diff --git a/tests/test_cargo_new.rs b/tests/test_cargo_new.rs index c3a4b87d343..fc2d73916ac 100644 --- a/tests/test_cargo_new.rs +++ b/tests/test_cargo_new.rs @@ -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] 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 "]"#)); -}); +} -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 "]"#)); -}); +} -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 "]"#)); -}); +} -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 "]"#), 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 "]"#)); 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 [..] ")); -}); +} diff --git a/tests/test_cargo_overrides.rs b/tests/test_cargo_overrides.rs index d10cbd95928..4a53938cce4 100644 --- a/tests/test_cargo_overrides.rs +++ b/tests/test_cargo_overrides.rs @@ -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 ")); -}); +} diff --git a/tests/test_cargo_package.rs b/tests/test_cargo_package.rs index 68fa3aaad31..1e6a82c2f15 100644 --- a/tests/test_cargo_package.rs +++ b/tests/test_cargo_package.rs @@ -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 ")); -}); +} diff --git a/tests/test_cargo_profiles.rs b/tests/test_cargo_profiles.rs index 3b8d5e5ca27..5b2c268a249 100644 --- a/tests/test_cargo_profiles.rs +++ b/tests/test_cargo_profiles.rs @@ -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))); -}); +} diff --git a/tests/test_cargo_publish.rs b/tests/test_cargo_publish.rs index bba868d4dce..0c3aa6115f0 100644 --- a/tests/test_cargo_publish.rs +++ b/tests/test_cargo_publish.rs @@ -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 ")); -}); +} diff --git a/tests/test_cargo_read_manifest.rs b/tests/test_cargo_read_manifest.rs index f5e72ab3a6e..d239a0f0239 100644 --- a/tests/test_cargo_read_manifest.rs +++ b/tests/test_cargo_read_manifest.rs @@ -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())); -}); +} diff --git a/tests/test_cargo_registry.rs b/tests/test_cargo_registry.rs index 025303e862d..2e2efad35d5 100644 --- a/tests/test_cargo_registry.rs +++ b/tests/test_cargo_registry.rs @@ -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)); -}); +} diff --git a/tests/test_cargo_run.rs b/tests/test_cargo_run.rs index 8a3ab2b29b0..151ee8b09b5 100644 --- a/tests/test_cargo_run.rs +++ b/tests/test_cargo_run.rs @@ -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 ")); -}); +} diff --git a/tests/test_cargo_rustc.rs b/tests/test_cargo_rustc.rs index 3d76f22a6f8..afc132e7f72 100644 --- a/tests/test_cargo_rustc.rs +++ b/tests/test_cargo_rustc.rs @@ -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] [--] [...]")); -}); +} -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)); -}); +} diff --git a/tests/test_cargo_rustdoc.rs b/tests/test_cargo_rustdoc.rs index f8813c7d159..ed9e6fc9b6b 100644 --- a/tests/test_cargo_rustdoc.rs +++ b/tests/test_cargo_rustdoc.rs @@ -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`")); -}); +} diff --git a/tests/test_cargo_search.rs b/tests/test_cargo_search.rs index a58bfa1b29e..181088e0e71 100644 --- a/tests/test_cargo_search.rs +++ b/tests/test_cargo_search.rs @@ -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)); -}); +} diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 1145f91f3dc..953449db1d0 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -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)); -}); +} diff --git a/tests/test_cargo_tool_paths.rs b/tests/test_cargo_tool_paths.rs index e92f84d8b0b..db76b45c216 100644 --- a/tests/test_cargo_tool_paths.rs +++ b/tests/test_cargo_tool_paths.rs @@ -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))) -}); +} diff --git a/tests/test_cargo_verify_project.rs b/tests/test_cargo_verify_project.rs index ca75952271d..64afb1d352d 100644 --- a/tests/test_cargo_verify_project.rs +++ b/tests/test_cargo_verify_project.rs @@ -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())); -}); +} diff --git a/tests/test_cargo_version.rs b/tests/test_cargo_version.rs index debc32e402b..af54662c71d 100644 --- a/tests/test_cargo_version.rs +++ b/tests/test_cargo_version.rs @@ -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 ".to_string())); -}); +} diff --git a/tests/test_shell.rs b/tests/test_shell.rs index 931c7b818ee..039b5c5e1aa 100644 --- a/tests/test_shell.rs +++ b/tests/test_shell.rs @@ -10,9 +10,6 @@ use cargo::util::CargoResult; use support::{Tap, execs, shell_writes}; -fn setup() { -} - struct Sink(Arc>>); 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 { let mut term = TerminfoTerminal::new(Vec::new()).unwrap(); diff --git a/tests/tests.rs b/tests/tests.rs index dc5507f50f7..bad620d9658 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -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; From 763ba535eb2fe8b92ab5fd9584c77f2fe22b8e42 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 25 May 2016 17:06:25 -0700 Subject: [PATCH 2/2] Shared the test suite into multiple binaries Compiling everything in one binary was getting annoying as it just took forever to build, instead shard it all up so we can build just particular test suites at a time. --- Cargo.lock | 22 +++ Cargo.toml | 7 +- tests/{test_bad_config.rs => bad-config.rs} | 7 +- ..._manifest_path.rs => bad-manifest-path.rs} | 5 +- tests/{test_cargo_bench.rs => bench.rs} | 55 +++--- ...test_cargo_build_auth.rs => build-auth.rs} | 11 +- .../{test_cargo_build_lib.rs => build-lib.rs} | 6 +- ...ompile_custom_build.rs => build-script.rs} | 52 +++--- tests/{test_cargo_compile.rs => build.rs} | 28 +-- tests/{test_cargo.rs => cargo.rs} | 13 +- tests/cargotest/Cargo.toml | 24 +++ tests/cargotest/install.rs | 30 ++++ tests/cargotest/lib.rs | 62 +++++++ tests/{ => cargotest}/support/git.rs | 86 ++++----- tests/{ => cargotest}/support/mod.rs | 79 +++------ tests/cargotest/support/paths.rs | 146 +++++++++++++++ tests/{ => cargotest}/support/registry.rs | 47 +++-- tests/{test_cargo_cfg.rs => cfg.rs} | 22 ++- tests/{test_cargo_clean.rs => clean.rs} | 7 +- ...test_cargo_concurrent.rs => concurrent.rs} | 19 +- tests/{test_cargo_config.rs => config.rs} | 5 +- ...argo_cross_compile.rs => cross-compile.rs} | 23 ++- tests/{test_cargo_death.rs => death.rs} | 7 +- tests/{test_cargo_doc.rs => doc.rs} | 10 +- tests/{test_cargo_features.rs => features.rs} | 12 +- tests/{test_cargo_fetch.rs => fetch.rs} | 5 +- .../{test_cargo_freshness.rs => freshness.rs} | 20 ++- ...erate_lockfile.rs => generate-lockfile.rs} | 5 +- ...{test_cargo_compile_git_deps.rs => git.rs} | 31 ++-- tests/{test_cargo_init.rs => init.rs} | 11 +- tests/{test_cargo_install.rs => install.rs} | 50 ++---- tests/{test_cargo_metadata.rs => metadata.rs} | 8 +- ...test_cargo_net_config.rs => net-config.rs} | 5 +- tests/{test_cargo_new.rs => new.rs} | 36 ++-- .../{test_cargo_overrides.rs => overrides.rs} | 12 +- tests/{test_cargo_package.rs => package.rs} | 21 ++- ...est_cargo_compile_path_deps.rs => path.rs} | 21 ++- ...st_cargo_compile_plugins.rs => plugins.rs} | 12 +- tests/{test_cargo_profiles.rs => profiles.rs} | 5 +- tests/{test_cargo_publish.rs => publish.rs} | 16 +- ...argo_read_manifest.rs => read-manifest.rs} | 5 +- tests/{test_cargo_registry.rs => registry.rs} | 32 ++-- tests/{test_cargo_run.rs => run.rs} | 5 +- tests/{test_cargo_rustc.rs => rustc.rs} | 6 +- tests/{test_cargo_rustdoc.rs => rustdoc.rs} | 6 +- ...argo_compile_rustflags.rs => rustflags.rs} | 27 +-- tests/{test_cargo_search.rs => search.rs} | 17 +- tests/{test_shell.rs => shell.rs} | 16 +- tests/support/paths.rs | 166 ------------------ tests/{test_cargo_test.rs => test.rs} | 17 +- tests/tests.rs | 105 ----------- ...test_cargo_tool_paths.rs => tool-paths.rs} | 12 +- ...go_verify_project.rs => verify-project.rs} | 5 +- tests/{test_cargo_version.rs => version.rs} | 8 +- 54 files changed, 793 insertions(+), 677 deletions(-) rename tests/{test_bad_config.rs => bad-config.rs} (98%) rename tests/{test_bad_manifest_path.rs => bad-manifest-path.rs} (98%) rename tests/{test_cargo_bench.rs => bench.rs} (96%) rename tests/{test_cargo_build_auth.rs => build-auth.rs} (97%) rename tests/{test_cargo_build_lib.rs => build-lib.rs} (94%) rename tests/{test_cargo_compile_custom_build.rs => build-script.rs} (98%) rename tests/{test_cargo_compile.rs => build.rs} (99%) rename tests/{test_cargo.rs => cargo.rs} (95%) create mode 100644 tests/cargotest/Cargo.toml create mode 100644 tests/cargotest/install.rs create mode 100644 tests/cargotest/lib.rs rename tests/{ => cargotest}/support/git.rs (52%) rename tests/{ => cargotest}/support/mod.rs (90%) create mode 100644 tests/cargotest/support/paths.rs rename tests/{ => cargotest}/support/registry.rs (83%) rename tests/{test_cargo_cfg.rs => cfg.rs} (96%) rename tests/{test_cargo_clean.rs => clean.rs} (97%) rename tests/{test_cargo_concurrent.rs => concurrent.rs} (96%) rename tests/{test_cargo_config.rs => config.rs} (86%) rename tests/{test_cargo_cross_compile.rs => cross-compile.rs} (98%) rename tests/{test_cargo_death.rs => death.rs} (96%) rename tests/{test_cargo_doc.rs => doc.rs} (98%) rename tests/{test_cargo_features.rs => features.rs} (98%) rename tests/{test_cargo_fetch.rs => fetch.rs} (82%) rename tests/{test_cargo_freshness.rs => freshness.rs} (96%) rename tests/{test_cargo_generate_lockfile.rs => generate-lockfile.rs} (98%) rename tests/{test_cargo_compile_git_deps.rs => git.rs} (98%) rename tests/{test_cargo_init.rs => init.rs} (98%) rename tests/{test_cargo_install.rs => install.rs} (95%) rename tests/{test_cargo_metadata.rs => metadata.rs} (98%) rename tests/{test_cargo_net_config.rs => net-config.rs} (94%) rename tests/{test_cargo_new.rs => new.rs} (94%) rename tests/{test_cargo_overrides.rs => overrides.rs} (98%) rename tests/{test_cargo_package.rs => package.rs} (96%) rename tests/{test_cargo_compile_path_deps.rs => path.rs} (98%) rename tests/{test_cargo_compile_plugins.rs => plugins.rs} (96%) rename tests/{test_cargo_profiles.rs => profiles.rs} (97%) rename tests/{test_cargo_publish.rs => publish.rs} (95%) rename tests/{test_cargo_read_manifest.rs => read-manifest.rs} (96%) rename tests/{test_cargo_registry.rs => registry.rs} (97%) rename tests/{test_cargo_run.rs => run.rs} (99%) rename tests/{test_cargo_rustc.rs => rustc.rs} (99%) rename tests/{test_cargo_rustdoc.rs => rustdoc.rs} (98%) rename tests/{test_cargo_compile_rustflags.rs => rustflags.rs} (98%) rename tests/{test_cargo_search.rs => search.rs} (95%) rename tests/{test_shell.rs => shell.rs} (93%) delete mode 100644 tests/support/paths.rs rename tests/{test_cargo_test.rs => test.rs} (99%) delete mode 100644 tests/tests.rs rename tests/{test_cargo_tool_paths.rs => tool-paths.rs} (94%) rename tests/{test_cargo_verify_project.rs => verify-project.rs} (92%) rename tests/{test_cargo_version.rs => version.rs} (90%) diff --git a/Cargo.lock b/Cargo.lock index aab3cb77dd6..5e86f8e0098 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,6 +4,7 @@ version = "0.11.0" dependencies = [ "advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "bufstream 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cargotest 0.1.0", "crates-io 0.2.0", "crossbeam 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "curl 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -60,6 +61,27 @@ name = "bufstream" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cargotest" +version = "0.1.0" +dependencies = [ + "bufstream 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cargo 0.11.0", + "filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", + "git2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "hamcrest 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", + "tar 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cmake" version = "0.1.16" diff --git a/Cargo.toml b/Cargo.toml index 6560c9ee320..4e6b627602b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,14 +49,9 @@ winapi = "0.2" hamcrest = "0.1" bufstream = "0.1" filetime = "0.1" +cargotest = { path = "tests/cargotest" } [[bin]] name = "cargo" test = false doc = false - -[[test]] -name = "tests" - -[[test]] -name = "resolve" diff --git a/tests/test_bad_config.rs b/tests/bad-config.rs similarity index 98% rename from tests/test_bad_config.rs rename to tests/bad-config.rs index 21c55fd6d6b..b88ea2f6bfe 100644 --- a/tests/test_bad_config.rs +++ b/tests/bad-config.rs @@ -1,5 +1,8 @@ -use support::{project, execs}; -use support::registry::Package; +extern crate cargotest; +extern crate hamcrest; + +use cargotest::support::{project, execs}; +use cargotest::support::registry::Package; use hamcrest::assert_that; #[test] diff --git a/tests/test_bad_manifest_path.rs b/tests/bad-manifest-path.rs similarity index 98% rename from tests/test_bad_manifest_path.rs rename to tests/bad-manifest-path.rs index ed10ed7cab8..cd9a97ef576 100644 --- a/tests/test_bad_manifest_path.rs +++ b/tests/bad-manifest-path.rs @@ -1,4 +1,7 @@ -use support::{project, execs, main_file, basic_bin_manifest}; +extern crate hamcrest; +extern crate cargotest; + +use cargotest::support::{project, execs, main_file, basic_bin_manifest}; use hamcrest::{assert_that}; fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) { diff --git a/tests/test_cargo_bench.rs b/tests/bench.rs similarity index 96% rename from tests/test_cargo_bench.rs rename to tests/bench.rs index 1aae2b323eb..ea8f557400d 100644 --- a/tests/test_cargo_bench.rs +++ b/tests/bench.rs @@ -1,13 +1,18 @@ +extern crate cargotest; +extern crate cargo; +extern crate hamcrest; + use std::str; -use support::{project, execs, basic_bin_manifest, basic_lib_manifest}; -use support::paths::CargoPathExt; -use hamcrest::{assert_that, existing_file}; use cargo::util::process; +use cargotest::is_nightly; +use cargotest::support::paths::CargoPathExt; +use cargotest::support::{project, execs, basic_bin_manifest, basic_lib_manifest}; +use hamcrest::{assert_that, existing_file}; #[test] fn cargo_bench_simple() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", &basic_bin_manifest("foo")) @@ -49,7 +54,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured #[test] fn bench_tarname() { - if !::is_nightly() { return } + if !is_nightly() { return } let prj = project("foo") .file("Cargo.toml" , r#" @@ -84,7 +89,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured #[test] fn cargo_bench_verbose() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", &basic_bin_manifest("foo")) @@ -111,7 +116,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured #[test] fn many_similar_names() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -149,7 +154,7 @@ fn many_similar_names() { #[test] fn cargo_bench_failing_test() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", &basic_bin_manifest("foo")) @@ -192,7 +197,7 @@ thread '
' panicked at 'assertion failed: \ #[test] fn bench_with_lib_dep() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -252,7 +257,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured #[test] fn bench_with_deep_lib_dep() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("bar") .file("Cargo.toml", r#" @@ -308,7 +313,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured #[test] fn external_bench_explicit() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -360,7 +365,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured #[test] fn external_bench_implicit() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -409,7 +414,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured #[test] fn dont_run_examples() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -429,7 +434,7 @@ fn dont_run_examples() { #[test] fn pass_through_command_line() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -476,7 +481,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured // tests in an rlib #[test] fn cargo_bench_twice() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("test_twice") .file("Cargo.toml", &basic_lib_manifest("test_twice")) @@ -500,7 +505,7 @@ fn cargo_bench_twice() { #[test] fn lib_bin_same_name() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -550,7 +555,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured #[test] fn lib_with_standard_name() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -603,7 +608,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured #[test] fn lib_with_standard_name2() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -647,7 +652,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured #[test] fn bench_dylib() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -719,7 +724,7 @@ test foo ... bench: [..] 0 ns/iter (+/- 0) test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured ")); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); assert_that(p.cargo("bench").arg("-v"), execs().with_status(0) .with_stderr(&format!("\ @@ -744,7 +749,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured #[test] fn bench_twice_with_build_cmd() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -790,7 +795,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured #[test] fn bench_with_examples() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("testbench") .file("Cargo.toml", r#" @@ -870,7 +875,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured #[test] fn test_a_bench() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -910,7 +915,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured #[test] fn test_bench_no_run() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -940,7 +945,7 @@ fn test_bench_no_run() { #[test] fn test_bench_multiple_packages() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" diff --git a/tests/test_cargo_build_auth.rs b/tests/build-auth.rs similarity index 97% rename from tests/test_cargo_build_auth.rs rename to tests/build-auth.rs index 050caf2cf2a..6ac2107df7c 100644 --- a/tests/test_cargo_build_auth.rs +++ b/tests/build-auth.rs @@ -1,13 +1,16 @@ +extern crate bufstream; +extern crate git2; +extern crate cargotest; +extern crate hamcrest; + use std::collections::HashSet; use std::io::prelude::*; use std::net::TcpListener; use std::thread; use bufstream::BufStream; -use git2; - -use support::{project, execs}; -use support::paths; +use cargotest::support::paths; +use cargotest::support::{project, execs}; use hamcrest::assert_that; // Test that HTTP auth is offered from `credential.helper` diff --git a/tests/test_cargo_build_lib.rs b/tests/build-lib.rs similarity index 94% rename from tests/test_cargo_build_lib.rs rename to tests/build-lib.rs index ee8e7fc978f..7d4d44f154d 100644 --- a/tests/test_cargo_build_lib.rs +++ b/tests/build-lib.rs @@ -1,5 +1,9 @@ +extern crate cargotest; +extern crate hamcrest; + use std::path::MAIN_SEPARATOR as SEP; -use support::{basic_bin_manifest, execs, project, ProjectBuilder}; + +use cargotest::support::{basic_bin_manifest, execs, project, ProjectBuilder}; use hamcrest::{assert_that}; fn verbose_output_for_lib(p: &ProjectBuilder) -> String { diff --git a/tests/test_cargo_compile_custom_build.rs b/tests/build-script.rs similarity index 98% rename from tests/test_cargo_compile_custom_build.rs rename to tests/build-script.rs index d51e4cae251..9b14cbc370f 100644 --- a/tests/test_cargo_compile_custom_build.rs +++ b/tests/build-script.rs @@ -1,8 +1,12 @@ +extern crate cargotest; +extern crate hamcrest; + use std::fs::{self, File}; use std::io::prelude::*; -use support::{project, execs}; -use support::paths::CargoPathExt; +use cargotest::{rustc_host, is_nightly, sleep_ms}; +use cargotest::support::{project, execs}; +use cargotest::support::paths::CargoPathExt; use hamcrest::{assert_that, existing_file, existing_dir}; #[test] @@ -248,7 +252,7 @@ linked to by one package #[test] fn overrides_and_links() { - let target = ::rustc_host(); + let target = rustc_host(); let p = project("foo") .file("Cargo.toml", r#" @@ -302,7 +306,7 @@ fn overrides_and_links() { #[test] fn unused_overrides() { - let target = ::rustc_host(); + let target = rustc_host(); let p = project("foo") .file("Cargo.toml", r#" @@ -387,10 +391,10 @@ fn only_rerun_build_script() { assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0)); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); File::create(&p.root().join("some-new-file")).unwrap(); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0) @@ -422,7 +426,7 @@ fn rebuild_continues_to_pass_env_vars() { } "#); a.build(); - a.root().move_into_the_past().unwrap(); + a.root().move_into_the_past(); let p = project("foo") .file("Cargo.toml", &format!(r#" @@ -446,10 +450,10 @@ fn rebuild_continues_to_pass_env_vars() { assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0)); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); File::create(&p.root().join("some-new-file")).unwrap(); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0)); @@ -473,10 +477,10 @@ fn testing_and_such() { println!("build"); assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0)); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); File::create(&p.root().join("src/lib.rs")).unwrap(); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); println!("test"); assert_that(p.cargo("test").arg("-vj1"), @@ -522,7 +526,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured #[test] fn propagation_of_l_flags() { - let target = ::rustc_host(); + let target = rustc_host(); let p = project("foo") .file("Cargo.toml", r#" [project] @@ -576,7 +580,7 @@ fn propagation_of_l_flags() { #[test] fn propagation_of_l_flags_new() { - let target = ::rustc_host(); + let target = rustc_host(); let p = project("foo") .file("Cargo.toml", r#" [project] @@ -667,7 +671,7 @@ fn build_deps_simple() { #[test] fn build_deps_not_for_normal() { - let target = ::rustc_host(); + let target = rustc_host(); let p = project("foo") .file("Cargo.toml", r#" [project] @@ -792,7 +796,7 @@ fn out_dir_is_preserved() { // Make the file assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0)); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); // Change to asserting that it's there File::create(&p.root().join("build.rs")).unwrap().write_all(br#" @@ -803,7 +807,7 @@ fn out_dir_is_preserved() { File::open(&Path::new(&out).join("foo")).unwrap(); } "#).unwrap(); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0)); @@ -1282,7 +1286,7 @@ fn cfg_feedback() { #[test] fn cfg_override() { - let target = ::rustc_host(); + let target = rustc_host(); let p = project("foo") .file("Cargo.toml", r#" @@ -1439,7 +1443,7 @@ fn cfg_override_test() { .file(".cargo/config", &format!(r#" [target.{}.a] rustc-cfg = ["foo"] - "#, ::rustc_host())) + "#, rustc_host())) .file("src/lib.rs", r#" /// /// ``` @@ -1514,7 +1518,7 @@ fn cfg_override_doc() { rustc-cfg = ["foo"] [target.{target}.b] rustc-cfg = ["bar"] - "#, target = ::rustc_host())) + "#, target = rustc_host())) .file("build.rs", "") .file("src/lib.rs", r#" #[cfg(foo)] @@ -1677,7 +1681,7 @@ fn diamond_passes_args_only_once() { #[test] fn adding_an_override_invalidates() { - let target = ::rustc_host(); + let target = rustc_host(); let p = project("foo") .file("Cargo.toml", r#" [project] @@ -1717,7 +1721,7 @@ fn adding_an_override_invalidates() { #[test] fn changing_an_override_invalidates() { - let target = ::rustc_host(); + let target = rustc_host(); let p = project("foo") .file("Cargo.toml", r#" [project] @@ -1783,7 +1787,7 @@ fn rebuild_only_on_explicit_paths() { [RUNNING] `rustc src[..]lib.rs [..]` ")); - ::sleep_ms(1000); + sleep_ms(1000); File::create(p.root().join("foo")).unwrap(); File::create(p.root().join("bar")).unwrap(); @@ -1802,7 +1806,7 @@ fn rebuild_only_on_explicit_paths() { [FRESH] a v0.5.0 ([..]) ")); - ::sleep_ms(1000); + sleep_ms(1000); // random other files do not affect freshness println!("run baz"); @@ -1976,7 +1980,7 @@ fn custom_target_dir() { #[test] fn panic_abort_with_build_scripts() { - if !::is_nightly() { + if !is_nightly() { return } let p = project("foo") diff --git a/tests/test_cargo_compile.rs b/tests/build.rs similarity index 99% rename from tests/test_cargo_compile.rs rename to tests/build.rs index 0daee9e87d1..4f632113b10 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/build.rs @@ -1,13 +1,19 @@ +extern crate cargo; +extern crate cargotest; +extern crate hamcrest; +extern crate tempdir; + use std::env; use std::fs::{self, File}; use std::io::prelude::*; -use tempdir::TempDir; -use support::{project, execs, main_file, basic_bin_manifest}; -use support::{ProjectBuilder}; -use hamcrest::{assert_that, existing_file, is_not}; -use support::paths::{CargoPathExt,root}; use cargo::util::process; +use cargotest::{is_nightly, rustc_host, sleep_ms}; +use cargotest::support::paths::{CargoPathExt,root}; +use cargotest::support::{ProjectBuilder}; +use cargotest::support::{project, execs, main_file, basic_bin_manifest}; +use hamcrest::{assert_that, existing_file, is_not}; +use tempdir::TempDir; #[test] fn cargo_compile_simple() { @@ -1449,7 +1455,7 @@ fn freshness_ignores_excluded() { .file("build.rs", "fn main() {}") .file("src/lib.rs", "pub fn bar() -> i32 { 1 }"); foo.build(); - foo.root().move_into_the_past().unwrap(); + foo.root().move_into_the_past(); assert_that(foo.cargo("build"), execs().with_status(0) @@ -1497,7 +1503,7 @@ fn rebuild_preserves_out_dir() { "#) .file("src/lib.rs", "pub fn bar() -> i32 { 1 }"); foo.build(); - foo.root().move_into_the_past().unwrap(); + foo.root().move_into_the_past(); assert_that(foo.cargo("build").env("FIRST", "1"), execs().with_status(0) @@ -1552,7 +1558,7 @@ fn recompile_space_in_name() { "#) .file("src/my lib.rs", ""); assert_that(foo.cargo_process("build"), execs().with_status(0)); - foo.root().move_into_the_past().unwrap(); + foo.root().move_into_the_past(); assert_that(foo.cargo("build"), execs().with_status(0).with_stdout("")); } @@ -1611,7 +1617,7 @@ Caused by: #[test] fn cargo_platform_specific_dependency() { - let host = ::rustc_host(); + let host = rustc_host(); let p = project("foo") .file("Cargo.toml", &format!(r#" [project] @@ -1785,7 +1791,7 @@ fn compile_then_delete() { assert_that(&p.bin("foo"), existing_file()); if cfg!(windows) { // On windows unlinking immediately after running often fails, so sleep - ::sleep_ms(100); + sleep_ms(100); } fs::remove_file(&p.bin("foo")).unwrap(); assert_that(p.cargo("run"), @@ -2202,7 +2208,7 @@ fn manifest_with_bom_is_ok() { #[test] fn panic_abort_compiles_with_panic_abort() { - if !::is_nightly() { + if !is_nightly() { return } let p = project("foo") diff --git a/tests/test_cargo.rs b/tests/cargo.rs similarity index 95% rename from tests/test_cargo.rs rename to tests/cargo.rs index 512dd956b7f..02900030949 100644 --- a/tests/test_cargo.rs +++ b/tests/cargo.rs @@ -1,3 +1,6 @@ +extern crate cargotest; +extern crate hamcrest; + use std::env; use std::ffi::OsString; use std::fs::{self, File}; @@ -5,9 +8,9 @@ use std::io::prelude::*; use std::path::{Path, PathBuf}; use std::str; -use cargo_process; -use support::paths; -use support::{execs, project, mkdir_recursive, ProjectBuilder}; +use cargotest::cargo_process; +use cargotest::support::paths::{self, CargoPathExt}; +use cargotest::support::{execs, project, ProjectBuilder}; use hamcrest::{assert_that}; #[cfg_attr(windows,allow(dead_code))] @@ -21,7 +24,7 @@ enum FakeKind<'a> { fn fake_file(proj: ProjectBuilder, dir: &Path, name: &str, kind: FakeKind) -> ProjectBuilder { let path = proj.root().join(dir).join(&format!("{}{}", name, env::consts::EXE_SUFFIX)); - mkdir_recursive(path.parent().unwrap()).unwrap(); + path.parent().unwrap().mkdir_p(); match kind { FakeKind::Executable => { File::create(&path).unwrap(); @@ -78,7 +81,7 @@ fn list_command_looks_at_path() { #[cfg(unix)] #[test] fn list_command_resolves_symlinks() { - use support::cargo_dir; + use cargotest::support::cargo_dir; let proj = project("list-non-overlapping"); let proj = fake_file(proj, &Path::new("path-test"), "cargo-2", diff --git a/tests/cargotest/Cargo.toml b/tests/cargotest/Cargo.toml new file mode 100644 index 00000000000..5f35c034db3 --- /dev/null +++ b/tests/cargotest/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "cargotest" +version = "0.1.0" +authors = ["Alex Crichton "] + +[lib] +path = "lib.rs" + +[dependencies] +bufstream = "0.1" +cargo = { path = "../.." } +filetime = "0.1" +flate2 = "0.2" +git2 = "0.4" +hamcrest = "0.1" +kernel32-sys = "0.2" +libc = "0.2" +log = "0.3" +rustc-serialize = "0.3" +tar = "0.4" +tempdir = "0.3" +term = "0.4.4" +url = "1.1" +winapi = "0.2" diff --git a/tests/cargotest/install.rs b/tests/cargotest/install.rs new file mode 100644 index 00000000000..12a396972e5 --- /dev/null +++ b/tests/cargotest/install.rs @@ -0,0 +1,30 @@ +use std::fmt; +use std::path::{PathBuf, Path}; + +use hamcrest::{Matcher, MatchResult, existing_file}; +use support::paths; + +pub use self::InstalledExe as has_installed_exe; + +pub fn cargo_home() -> PathBuf { + paths::home().join(".cargo") +} + +pub struct InstalledExe(pub &'static str); + +fn exe(name: &str) -> String { + if cfg!(windows) {format!("{}.exe", name)} else {name.to_string()} +} + +impl> Matcher

for InstalledExe { + fn matches(&self, path: P) -> MatchResult { + let path = path.as_ref().join("bin").join(exe(self.0)); + existing_file().matches(&path) + } +} + +impl fmt::Display for InstalledExe { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "installed exe `{}`", self.0) + } +} diff --git a/tests/cargotest/lib.rs b/tests/cargotest/lib.rs new file mode 100644 index 00000000000..7053f483956 --- /dev/null +++ b/tests/cargotest/lib.rs @@ -0,0 +1,62 @@ +#![deny(warnings)] + +extern crate bufstream; +extern crate cargo; +extern crate filetime; +extern crate flate2; +extern crate git2; +extern crate hamcrest; +extern crate libc; +extern crate rustc_serialize; +extern crate tar; +extern crate tempdir; +extern crate term; +extern crate url; +#[cfg(windows)] extern crate kernel32; +#[cfg(windows)] extern crate winapi; + +#[macro_use] +extern crate log; + +use cargo::util::Rustc; +use std::ffi::OsStr; +use std::time::Duration; + +pub mod support; +pub mod install; + +thread_local!(pub static RUSTC: Rustc = Rustc::new("rustc").unwrap()); + +pub fn rustc_host() -> String { + RUSTC.with(|r| r.host.clone()) +} + +pub fn is_nightly() -> bool { + RUSTC.with(|r| { + r.verbose_version.contains("-nightly") || + r.verbose_version.contains("-dev") + }) +} + +pub fn process>(t: T) -> cargo::util::ProcessBuilder { + let mut p = cargo::util::process(t.as_ref()); + p.cwd(&support::paths::root()) + .env_remove("CARGO_HOME") + .env("HOME", support::paths::home()) + .env("CARGO_HOME", support::paths::home().join(".cargo")) + .env_remove("RUSTC") + .env_remove("RUSTFLAGS") + .env_remove("XDG_CONFIG_HOME") // see #2345 + .env("GIT_CONFIG_NOSYSTEM", "1") // keep trying to sandbox ourselves + .env_remove("CARGO_TARGET_DIR") // we assume 'target' + .env_remove("MSYSTEM"); // assume cmd.exe everywhere on windows + return p +} + +pub fn cargo_process() -> cargo::util::ProcessBuilder { + process(&support::cargo_dir().join("cargo")) +} + +pub fn sleep_ms(ms: u64) { + std::thread::sleep(Duration::from_millis(ms)); +} diff --git a/tests/support/git.rs b/tests/cargotest/support/git.rs similarity index 52% rename from tests/support/git.rs rename to tests/cargotest/support/git.rs index 729c1841363..393157a62b1 100644 --- a/tests/support/git.rs +++ b/tests/cargotest/support/git.rs @@ -17,12 +17,12 @@ pub fn repo(p: &Path) -> RepoBuilder { RepoBuilder::init(p) } impl RepoBuilder { pub fn init(p: &Path) -> RepoBuilder { - fs::create_dir_all(p.parent().unwrap()).unwrap(); - let repo = git2::Repository::init(p).unwrap(); + t!(fs::create_dir_all(p.parent().unwrap())); + let repo = t!(git2::Repository::init(p)); { - let mut config = repo.config().unwrap(); - config.set_str("user.name", "name").unwrap(); - config.set_str("user.email", "email").unwrap(); + let mut config = t!(repo.config()); + t!(config.set_str("user.name", "name")); + t!(config.set_str("user.email", "email")); } RepoBuilder { repo: repo, files: Vec::new() } } @@ -35,22 +35,22 @@ impl RepoBuilder { pub fn nocommit_file(self, path: &str, contents: &str) -> RepoBuilder { let dst = self.repo.workdir().unwrap().join(path); - fs::create_dir_all(dst.parent().unwrap()).unwrap(); - File::create(&dst).unwrap().write_all(contents.as_bytes()).unwrap(); + t!(fs::create_dir_all(dst.parent().unwrap())); + t!(t!(File::create(&dst)).write_all(contents.as_bytes())); self } pub fn build(&self) { - let mut index = self.repo.index().unwrap(); + let mut index = t!(self.repo.index()); for file in self.files.iter() { - index.add_path(file).unwrap(); + t!(index.add_path(file)); } - index.write().unwrap(); - let id = index.write_tree().unwrap(); - let tree = self.repo.find_tree(id).unwrap(); - let sig = self.repo.signature().unwrap(); - self.repo.commit(Some("HEAD"), &sig, &sig, - "Initial commit", &tree, &[]).unwrap(); + t!(index.write()); + let id = t!(index.write_tree()); + let tree = t!(self.repo.find_tree(id)); + let sig = t!(self.repo.signature()); + t!(self.repo.commit(Some("HEAD"), &sig, &sig, + "Initial commit", &tree, &[])); } pub fn root(&self) -> &Path { @@ -69,10 +69,10 @@ pub fn new(name: &str, callback: F) -> Result git_project = callback(git_project); git_project.build(); - let repo = git2::Repository::init(&git_project.root()).unwrap(); - let mut cfg = repo.config().unwrap(); - cfg.set_str("user.email", "foo@bar.com").unwrap(); - cfg.set_str("user.name", "Foo Bar").unwrap(); + let repo = t!(git2::Repository::init(&git_project.root())); + let mut cfg = t!(repo.config()); + t!(cfg.set_str("user.email", "foo@bar.com")); + t!(cfg.set_str("user.name", "Foo Bar")); drop(cfg); add(&repo); commit(&repo); @@ -83,51 +83,51 @@ pub fn add(repo: &git2::Repository) { // FIXME(libgit2/libgit2#2514): apparently add_all will add all submodules // as well, and then fail b/c they're a directory. As a stopgap, we just // ignore all submodules. - let mut s = repo.submodules().unwrap(); + let mut s = t!(repo.submodules()); for submodule in s.iter_mut() { - submodule.add_to_index(false).unwrap(); + t!(submodule.add_to_index(false)); } - let mut index = repo.index().unwrap(); - index.add_all(["*"].iter(), git2::ADD_DEFAULT, + let mut index = t!(repo.index()); + t!(index.add_all(["*"].iter(), git2::ADD_DEFAULT, Some(&mut (|a, _b| { if s.iter().any(|s| a.starts_with(s.path())) {1} else {0} - }))).unwrap(); - index.write().unwrap(); + })))); + t!(index.write()); } pub fn add_submodule<'a>(repo: &'a git2::Repository, url: &str, path: &Path) -> git2::Submodule<'a> { let path = path.to_str().unwrap().replace(r"\", "/"); - let mut s = repo.submodule(url, Path::new(&path), false).unwrap(); - let subrepo = s.open().unwrap(); - subrepo.remote_add_fetch("origin", "refs/heads/*:refs/heads/*").unwrap(); - let mut origin = subrepo.find_remote("origin").unwrap(); - origin.fetch(&[], None, None).unwrap(); - subrepo.checkout_head(None).unwrap(); - s.add_finalize().unwrap(); + let mut s = t!(repo.submodule(url, Path::new(&path), false)); + let subrepo = t!(s.open()); + t!(subrepo.remote_add_fetch("origin", "refs/heads/*:refs/heads/*")); + let mut origin = t!(subrepo.find_remote("origin")); + t!(origin.fetch(&[], None, None)); + t!(subrepo.checkout_head(None)); + t!(s.add_finalize()); return s; } pub fn commit(repo: &git2::Repository) -> git2::Oid { - let tree_id = repo.index().unwrap().write_tree().unwrap(); - let sig = repo.signature().unwrap(); + let tree_id = t!(t!(repo.index()).write_tree()); + let sig = t!(repo.signature()); let mut parents = Vec::new(); match repo.head().ok().map(|h| h.target().unwrap()) { - Some(parent) => parents.push(repo.find_commit(parent).unwrap()), + Some(parent) => parents.push(t!(repo.find_commit(parent))), None => {} } let parents = parents.iter().collect::>(); - repo.commit(Some("HEAD"), &sig, &sig, "test", - &repo.find_tree(tree_id).unwrap(), - &parents).unwrap() + t!(repo.commit(Some("HEAD"), &sig, &sig, "test", + &t!(repo.find_tree(tree_id)), + &parents)) } pub fn tag(repo: &git2::Repository, name: &str) { let head = repo.head().unwrap().target().unwrap(); - repo.tag(name, - &repo.find_object(head, None).unwrap(), - &repo.signature().unwrap(), - "make a new tag", - false).unwrap(); + t!(repo.tag(name, + &t!(repo.find_object(head, None)), + &t!(repo.signature()), + "make a new tag", + false)); } diff --git a/tests/support/mod.rs b/tests/cargotest/support/mod.rs similarity index 90% rename from tests/support/mod.rs rename to tests/cargotest/support/mod.rs index 856a3f954f0..47ae3f4ebd8 100644 --- a/tests/support/mod.rs +++ b/tests/cargotest/support/mod.rs @@ -19,6 +19,14 @@ use cargo::util::process; use support::paths::CargoPathExt; +#[macro_export] +macro_rules! t { + ($e:expr) => (match $e { + Ok(e) => e, + Err(e) => panic!("{} failed with {}", stringify!($e), e), + }) +} + pub mod paths; pub mod git; pub mod registry; @@ -40,17 +48,14 @@ impl FileBuilder { FileBuilder { path: path, body: body.to_string() } } - fn mk(&self) -> Result<(), String> { - try!(mkdir_recursive(&self.dirname())); + fn mk(&self) { + self.dirname().mkdir_p(); - let mut file = try!( - fs::File::create(&self.path) - .with_err_msg(format!("Could not create file; path={}", - self.path.display()))); + let mut file = fs::File::create(&self.path).unwrap_or_else(|e| { + panic!("could not create file {}: {}", self.path.display(), e) + }); - file.write_all(self.body.as_bytes()) - .with_err_msg(format!("Could not write to file; path={}", - self.path.display())) + t!(file.write_all(self.body.as_bytes())); } fn dirname(&self) -> &Path { @@ -70,21 +75,15 @@ impl SymlinkBuilder { } #[cfg(unix)] - fn mk(&self) -> Result<(), String> { - try!(mkdir_recursive(&self.dirname())); - - os::unix::fs::symlink(&self.dst, &self.src) - .with_err_msg(format!("Could not create symlink; dst={} src={}", - self.dst.display(), self.src.display())) + fn mk(&self) { + self.dirname().mkdir_p(); + t!(os::unix::fs::symlink(&self.dst, &self.src)); } #[cfg(windows)] - fn mk(&self) -> Result<(), String> { - try!(mkdir_recursive(&self.dirname())); - - os::windows::fs::symlink_file(&self.dst, &self.src) - .with_err_msg(format!("Could not create symlink; dst={} src={}", - self.dst.display(), self.src.display())) + fn mk(&self) { + self.dirname().mkdir_p(); + t!(os::windows::fs::symlink_file(&self.dst, &self.src)); } fn dirname(&self) -> &Path { @@ -167,36 +166,24 @@ impl ProjectBuilder { // TODO: return something different than a ProjectBuilder pub fn build(&self) -> &ProjectBuilder { - match self.build_with_result() { - Err(e) => panic!(e), - _ => return self - } - } - - pub fn build_with_result(&self) -> Result<(), String> { // First, clean the directory if it already exists - try!(self.rm_root()); + self.rm_root(); // Create the empty directory - try!(mkdir_recursive(&self.root)); + self.root.mkdir_p(); for file in self.files.iter() { - try!(file.mk()); + file.mk(); } for symlink in self.symlinks.iter() { - try!(symlink.mk()); + symlink.mk(); } - - Ok(()) + self } - fn rm_root(&self) -> Result<(), String> { - if self.root.c_exists() { - rmdir_recursive(&self.root) - } else { - Ok(()) - } + fn rm_root(&self) { + self.root.rm_rf() } } @@ -207,18 +194,6 @@ pub fn project(name: &str) -> ProjectBuilder { // === Helpers === -pub fn mkdir_recursive(path: &Path) -> Result<(), String> { - fs::create_dir_all(path) - .with_err_msg(format!("could not create directory; path={}", - path.display())) -} - -pub fn rmdir_recursive(path: &Path) -> Result<(), String> { - path.rm_rf() - .with_err_msg(format!("could not rm directory; path={}", - path.display())) -} - pub fn main_file(println: &str, deps: &[&str]) -> String { let mut buf = String::new(); diff --git a/tests/cargotest/support/paths.rs b/tests/cargotest/support/paths.rs new file mode 100644 index 00000000000..62e3b548d2d --- /dev/null +++ b/tests/cargotest/support/paths.rs @@ -0,0 +1,146 @@ +use std::env; +use std::cell::Cell; +use std::fs; +use std::io::{self, ErrorKind}; +use std::path::{Path, PathBuf}; +use std::sync::{Once, ONCE_INIT}; +use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; + +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)); + +fn init() { + static GLOBAL_INIT: Once = ONCE_INIT; + thread_local!(static LOCAL_INIT: Cell = Cell::new(false)); + GLOBAL_INIT.call_once(|| { + global_root().mkdir_p(); + }); + LOCAL_INIT.with(|i| { + if i.get() { + return + } + i.set(true); + root().rm_rf(); + home().mkdir_p(); + }) +} + +fn global_root() -> PathBuf { + let mut path = t!(env::current_exe()); + path.pop(); // chop off exe name + path.pop(); // chop off 'debug' + + // If `cargo test` is run manually then our path looks like + // `target/debug/foo`, in which case our `path` is already pointing at + // `target`. If, however, `cargo test --target $target` is used then the + // output is `target/$target/debug/foo`, so our path is pointing at + // `target/$target`. Here we conditionally pop the `$target` name. + if path.file_name().and_then(|s| s.to_str()) != Some("target") { + path.pop(); + } + + path.join(CARGO_INTEGRATION_TEST_DIR) +} + +pub fn root() -> PathBuf { + init(); + global_root().join(&TASK_ID.with(|my_id| format!("t{}", my_id))) +} + +pub fn home() -> PathBuf { + root().join("home") +} + +pub trait CargoPathExt { + fn rm_rf(&self); + fn mkdir_p(&self); + fn move_into_the_past(&self); +} + +impl CargoPathExt for Path { + /* Technically there is a potential race condition, but we don't + * care all that much for our tests + */ + fn rm_rf(&self) { + if !self.exists() { + return + } + + for file in t!(fs::read_dir(self)) { + let file = t!(file).path(); + + if file.is_dir() { + file.rm_rf(); + } else { + // On windows we can't remove a readonly file, and git will + // often clone files as readonly. As a result, we have some + // special logic to remove readonly files on windows. + do_op(&file, "remove file", |p| fs::remove_file(p)); + } + } + do_op(self, "remove dir", |p| fs::remove_dir(p)); + } + + fn mkdir_p(&self) { + fs::create_dir_all(self).unwrap_or_else(|e| { + panic!("failed to mkdir_p {}: {}", self.display(), e) + }) + } + + fn move_into_the_past(&self) { + if self.is_file() { + time_travel(self); + } else { + recurse(self, &self.join("target")); + } + + fn recurse(p: &Path, bad: &Path) { + if p.is_file() { + time_travel(p) + } else if !p.starts_with(bad) { + for f in t!(fs::read_dir(p)) { + let f = t!(f).path(); + recurse(&f, bad); + } + } + } + + fn time_travel(path: &Path) { + let stat = t!(path.metadata()); + + let mtime = FileTime::from_last_modification_time(&stat); + let newtime = mtime.seconds_relative_to_1970() - 3600; + let nanos = mtime.nanoseconds(); + let newtime = FileTime::from_seconds_since_1970(newtime, nanos); + + // Sadly change_file_times has a failure mode where a readonly file + // cannot have its times changed on windows. + do_op(path, "set file times", + |path| filetime::set_file_times(path, newtime, newtime)); + } + } +} + +fn do_op(path: &Path, desc: &str, mut f: F) + where F: FnMut(&Path) -> io::Result<()> +{ + match f(path) { + Ok(()) => {} + Err(ref e) if cfg!(windows) && + e.kind() == ErrorKind::PermissionDenied => { + let mut p = t!(path.metadata()).permissions(); + p.set_readonly(false); + t!(fs::set_permissions(path, p)); + f(path).unwrap_or_else(|e| { + panic!("failed to {} {}: {}", desc, path.display(), e); + }) + } + Err(e) => { + panic!("failed to {} {}: {}", desc, path.display(), e); + } + } +} diff --git a/tests/support/registry.rs b/tests/cargotest/support/registry.rs similarity index 83% rename from tests/support/registry.rs rename to tests/cargotest/support/registry.rs index da853244031..a783c6c0b05 100644 --- a/tests/support/registry.rs +++ b/tests/cargotest/support/registry.rs @@ -39,15 +39,15 @@ struct Dependency { fn init() { let config = paths::home().join(".cargo/config"); - fs::create_dir_all(config.parent().unwrap()).unwrap(); + t!(fs::create_dir_all(config.parent().unwrap())); if fs::metadata(&config).is_ok() { return } - File::create(&config).unwrap().write_all(format!(r#" + t!(t!(File::create(&config)).write_all(format!(r#" [registry] index = "{reg}" token = "api-token" - "#, reg = registry()).as_bytes()).unwrap(); + "#, reg = registry()).as_bytes())); // Init a new registry repo(®istry_path()) @@ -135,8 +135,7 @@ impl Package { }).collect::>(); let cksum = { let mut c = Vec::new(); - File::open(&self.archive_dst()).unwrap() - .read_to_end(&mut c).unwrap(); + t!(t!(File::open(&self.archive_dst())).read_to_end(&mut c)); cksum(&c) }; let mut dep = HashMap::new(); @@ -159,25 +158,25 @@ impl Package { let dst = registry_path().join(&file); let mut prev = String::new(); let _ = File::open(&dst).and_then(|mut f| f.read_to_string(&mut prev)); - fs::create_dir_all(dst.parent().unwrap()).unwrap(); - File::create(&dst).unwrap() - .write_all((prev + &line[..] + "\n").as_bytes()).unwrap(); + t!(fs::create_dir_all(dst.parent().unwrap())); + t!(t!(File::create(&dst)) + .write_all((prev + &line[..] + "\n").as_bytes())); // Add the new file to the index - let repo = git2::Repository::open(®istry_path()).unwrap(); - let mut index = repo.index().unwrap(); - index.add_path(Path::new(&file)).unwrap(); - index.write().unwrap(); - let id = index.write_tree().unwrap(); + let repo = t!(git2::Repository::open(®istry_path())); + let mut index = t!(repo.index()); + t!(index.add_path(Path::new(&file))); + t!(index.write()); + let id = t!(index.write_tree()); // Commit this change - let tree = repo.find_tree(id).unwrap(); - let sig = repo.signature().unwrap(); - let parent = repo.refname_to_id("refs/heads/master").unwrap(); - let parent = repo.find_commit(parent).unwrap(); - repo.commit(Some("HEAD"), &sig, &sig, - "Another commit", &tree, - &[&parent]).unwrap(); + let tree = t!(repo.find_tree(id)); + let sig = t!(repo.signature()); + let parent = t!(repo.refname_to_id("refs/heads/master")); + let parent = t!(repo.find_commit(parent)); + t!(repo.commit(Some("HEAD"), &sig, &sig, + "Another commit", &tree, + &[&parent])); } fn make_archive(&self) { @@ -204,8 +203,8 @@ impl Package { } let dst = self.archive_dst(); - fs::create_dir_all(dst.parent().unwrap()).unwrap(); - let f = File::create(&dst).unwrap(); + t!(fs::create_dir_all(dst.parent().unwrap())); + let f = t!(File::create(&dst)); let mut a = Builder::new(GzEncoder::new(f, Default)); self.append(&mut a, "Cargo.toml", &manifest); if self.files.is_empty() { @@ -220,10 +219,10 @@ impl Package { fn append(&self, ar: &mut Builder, file: &str, contents: &str) { let mut header = Header::new_ustar(); header.set_size(contents.len() as u64); - header.set_path(format!("{}-{}/{}", self.name, self.vers, file)).unwrap(); + t!(header.set_path(format!("{}-{}/{}", self.name, self.vers, file))); header.set_cksum(); - ar.append(&header, contents.as_bytes()).unwrap(); + t!(ar.append(&header, contents.as_bytes())); } pub fn archive_dst(&self) -> PathBuf { diff --git a/tests/test_cargo_cfg.rs b/tests/cfg.rs similarity index 96% rename from tests/test_cargo_cfg.rs rename to tests/cfg.rs index 7f85d58a93f..457cab3af28 100644 --- a/tests/test_cargo_cfg.rs +++ b/tests/cfg.rs @@ -1,12 +1,16 @@ +extern crate cargo; +extern crate cargotest; +extern crate hamcrest; + use std::str::FromStr; use std::fmt; use cargo::util::{Cfg, CfgExpr}; +use cargotest::{is_nightly, rustc_host}; +use cargotest::support::registry::Package; +use cargotest::support::{project, execs}; use hamcrest::assert_that; -use support::{project, execs}; -use support::registry::Package; - macro_rules! c { ($a:ident) => ( Cfg::Name(stringify!($a).to_string()) @@ -134,7 +138,7 @@ fn cfg_matches() { #[test] fn cfg_easy() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -162,7 +166,7 @@ fn cfg_easy() { #[test] fn dont_include() { - if !::is_nightly() { return } + if !is_nightly() { return } let other_family = if cfg!(unix) {"windows"} else {"unix"}; let p = project("foo") @@ -191,7 +195,7 @@ fn dont_include() { #[test] fn works_through_the_registry() { - if !::is_nightly() { return } + if !is_nightly() { return } Package::new("foo", "0.1.0").publish(); Package::new("bar", "0.1.0") @@ -276,7 +280,7 @@ Caused by: #[test] fn multiple_match_ok() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", &format!(r#" @@ -298,7 +302,7 @@ fn multiple_match_ok() { [target.{}.dependencies] b = {{ path = 'b' }} - "#, ::rustc_host())) + "#, rustc_host())) .file("src/lib.rs", "extern crate b;") .file("b/Cargo.toml", r#" [package] @@ -313,7 +317,7 @@ fn multiple_match_ok() { #[test] fn any_ok() { - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" diff --git a/tests/test_cargo_clean.rs b/tests/clean.rs similarity index 97% rename from tests/test_cargo_clean.rs rename to tests/clean.rs index 25f77423b2c..ea45ceb5784 100644 --- a/tests/test_cargo_clean.rs +++ b/tests/clean.rs @@ -1,7 +1,10 @@ +extern crate hamcrest; +extern crate cargotest; + use std::env; -use support::{git, project, execs, main_file, basic_bin_manifest}; -use support::registry::Package; +use cargotest::support::{git, project, execs, main_file, basic_bin_manifest}; +use cargotest::support::registry::Package; use hamcrest::{assert_that, existing_dir, existing_file, is_not}; #[test] diff --git a/tests/test_cargo_concurrent.rs b/tests/concurrent.rs similarity index 96% rename from tests/test_cargo_concurrent.rs rename to tests/concurrent.rs index fb74771c7ab..4499f1d3a4c 100644 --- a/tests/test_cargo_concurrent.rs +++ b/tests/concurrent.rs @@ -1,3 +1,8 @@ +extern crate cargo; +extern crate cargotest; +extern crate git2; +extern crate hamcrest; + use std::{env, str}; use std::fs::{self, File}; use std::io::Write; @@ -5,14 +10,12 @@ use std::net::TcpListener; use std::process::Stdio; use std::thread; -use git2; +use cargotest::install::{has_installed_exe, cargo_home}; +use cargotest::support::git; +use cargotest::support::registry::Package; +use cargotest::support::{execs, project}; use hamcrest::{assert_that, existing_file}; -use support::{execs, project}; -use support::git; -use support::registry::Package; -use test_cargo_install::{cargo_home, has_installed_exe}; - fn pkg(name: &str, vers: &str) { Package::new(name, vers) .file("src/main.rs", "fn main() {{}}") @@ -64,8 +67,8 @@ fn concurrent_installs() { pkg("foo", "0.0.1"); pkg("bar", "0.0.1"); - let mut a = ::cargo_process().arg("install").arg("foo").build_command(); - let mut b = ::cargo_process().arg("install").arg("bar").build_command(); + let mut a = cargotest::cargo_process().arg("install").arg("foo").build_command(); + let mut b = cargotest::cargo_process().arg("install").arg("bar").build_command(); a.stdout(Stdio::piped()).stderr(Stdio::piped()); b.stdout(Stdio::piped()).stderr(Stdio::piped()); diff --git a/tests/test_cargo_config.rs b/tests/config.rs similarity index 86% rename from tests/test_cargo_config.rs rename to tests/config.rs index c3aa0563d37..39c85dabd28 100644 --- a/tests/test_cargo_config.rs +++ b/tests/config.rs @@ -1,4 +1,7 @@ -use support::{project, execs}; +extern crate hamcrest; +extern crate cargotest; + +use cargotest::support::{project, execs}; use hamcrest::assert_that; #[test] diff --git a/tests/test_cargo_cross_compile.rs b/tests/cross-compile.rs similarity index 98% rename from tests/test_cargo_cross_compile.rs rename to tests/cross-compile.rs index 095aaeba3a8..7578454d711 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/cross-compile.rs @@ -1,8 +1,13 @@ +extern crate cargo; +extern crate cargotest; +extern crate hamcrest; + use std::env; -use support::{project, execs, basic_bin_manifest}; -use hamcrest::{assert_that, existing_file}; use cargo::util::process; +use cargotest::{is_nightly, rustc_host}; +use cargotest::support::{project, execs, basic_bin_manifest}; +use hamcrest::{assert_that, existing_file}; fn disabled() -> bool { // First, disable if ./configure requested so @@ -167,7 +172,7 @@ fn simple_deps() { #[test] fn plugin_deps() { if disabled() { return } - if !::is_nightly() { return } + if !is_nightly() { return } let foo = project("foo") .file("Cargo.toml", r#" @@ -245,7 +250,7 @@ fn plugin_deps() { #[test] fn plugin_to_the_max() { if disabled() { return } - if !::is_nightly() { return } + if !is_nightly() { return } let foo = project("foo") .file("Cargo.toml", r#" @@ -369,7 +374,7 @@ fn linker_and_ar() { #[test] fn plugin_with_extra_dylib_dep() { if disabled() { return } - if !::is_nightly() { return } + if !is_nightly() { return } let foo = project("foo") .file("Cargo.toml", r#" @@ -603,7 +608,7 @@ fn build_script_needed_for_host_and_target() { if disabled() { return } let target = alternate(); - let host = ::rustc_host(); + let host = rustc_host(); let p = project("foo") .file("Cargo.toml", r#" [package] @@ -801,7 +806,7 @@ fn build_script_with_platform_specific_dependencies() { if disabled() { return } let target = alternate(); - let host = ::rustc_host(); + let host = rustc_host(); let p = project("foo") .file("Cargo.toml", r#" [package] @@ -852,7 +857,7 @@ fn platform_specific_dependencies_do_not_leak() { if disabled() { return } let target = alternate(); - let host = ::rustc_host(); + let host = rustc_host(); let p = project("foo") .file("Cargo.toml", r#" [package] @@ -898,7 +903,7 @@ fn platform_specific_variables_reflected_in_build_scripts() { if disabled() { return } let target = alternate(); - let host = ::rustc_host(); + let host = rustc_host(); let p = project("foo") .file("Cargo.toml", &format!(r#" [package] diff --git a/tests/test_cargo_death.rs b/tests/death.rs similarity index 96% rename from tests/test_cargo_death.rs rename to tests/death.rs index 097dbdc124e..52922a746e1 100644 --- a/tests/test_cargo_death.rs +++ b/tests/death.rs @@ -1,8 +1,13 @@ +extern crate cargotest; +extern crate kernel32; +extern crate libc; +extern crate winapi; + use std::net::TcpListener; use std::io::{self, Read}; use std::process::{Stdio, Child}; -use support::project; +use cargotest::support::project; #[cfg(unix)] fn enabled() -> bool { diff --git a/tests/test_cargo_doc.rs b/tests/doc.rs similarity index 98% rename from tests/test_cargo_doc.rs rename to tests/doc.rs index a39fed883df..9acd0e56f41 100644 --- a/tests/test_cargo_doc.rs +++ b/tests/doc.rs @@ -1,7 +1,11 @@ +extern crate cargotest; +extern crate hamcrest; + use std::str; use std::fs; -use support::{project, execs, path2url}; +use cargotest::{is_nightly, rustc_host}; +use cargotest::support::{project, execs, path2url}; use hamcrest::{assert_that, existing_file, existing_dir, is_not}; #[test] @@ -274,7 +278,7 @@ fn doc_same_name() { fn doc_target() { const TARGET: &'static str = "arm-unknown-linux-gnueabihf"; - if !::is_nightly() { return } + if !is_nightly() { return } let p = project("foo") .file("Cargo.toml", r#" @@ -369,7 +373,7 @@ fn target_specific_documented() { a = {{ path = "a" }} [target.{}.dependencies] a = {{ path = "a" }} - "#, ::rustc_host())) + "#, rustc_host())) .file("src/lib.rs", " extern crate a; diff --git a/tests/test_cargo_features.rs b/tests/features.rs similarity index 98% rename from tests/test_cargo_features.rs rename to tests/features.rs index a46d51f830a..5fcefaae6bb 100644 --- a/tests/test_cargo_features.rs +++ b/tests/features.rs @@ -1,8 +1,12 @@ +#[macro_use] +extern crate cargotest; +extern crate hamcrest; + use std::fs::File; use std::io::prelude::*; -use support::{project, execs}; -use support::paths::CargoPathExt; +use cargotest::support::paths::CargoPathExt; +use cargotest::support::{project, execs}; use hamcrest::assert_that; #[test] @@ -548,7 +552,7 @@ fn many_features_no_rebuilds() { [COMPILING] a v0.1.0 ({dir}/a) [COMPILING] b v0.1.0 ({dir}) ", dir = p.url()))); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); assert_that(p.cargo("build").arg("-v"), execs().with_status(0).with_stderr("\ @@ -665,7 +669,7 @@ fn everything_in_the_lockfile() { assert_that(p.cargo_process("fetch"), execs().with_status(0)); let loc = p.root().join("Cargo.lock"); let mut lockfile = String::new(); - File::open(&loc).unwrap().read_to_string(&mut lockfile).unwrap(); + t!(t!(File::open(&loc)).read_to_string(&mut 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); diff --git a/tests/test_cargo_fetch.rs b/tests/fetch.rs similarity index 82% rename from tests/test_cargo_fetch.rs rename to tests/fetch.rs index d2d53029110..a6ced09f930 100644 --- a/tests/test_cargo_fetch.rs +++ b/tests/fetch.rs @@ -1,4 +1,7 @@ -use support::{project, execs}; +extern crate cargotest; +extern crate hamcrest; + +use cargotest::support::{project, execs}; use hamcrest::assert_that; #[test] diff --git a/tests/test_cargo_freshness.rs b/tests/freshness.rs similarity index 96% rename from tests/test_cargo_freshness.rs rename to tests/freshness.rs index e049c26e9e7..f5173bebcd5 100644 --- a/tests/test_cargo_freshness.rs +++ b/tests/freshness.rs @@ -1,8 +1,12 @@ +extern crate cargotest; +extern crate hamcrest; + use std::fs::{self, File}; use std::io::prelude::*; -use support::{project, execs, path2url}; -use support::paths::CargoPathExt; +use cargotest::sleep_ms; +use cargotest::support::{project, execs, path2url}; +use cargotest::support::paths::CargoPathExt; use hamcrest::{assert_that, existing_file}; #[test] @@ -26,8 +30,8 @@ fn modifying_and_moving() { assert_that(p.cargo("build"), execs().with_status(0).with_stdout("")); - p.root().move_into_the_past().unwrap(); - p.root().join("target").move_into_the_past().unwrap(); + p.root().move_into_the_past(); + p.root().join("target").move_into_the_past(); File::create(&p.root().join("src/a.rs")).unwrap() .write_all(b"#[allow(unused)]fn main() {}").unwrap(); @@ -65,7 +69,7 @@ fn modify_only_some_files() { ", dir = path2url(p.root())))); assert_that(p.cargo("test"), execs().with_status(0)); - ::sleep_ms(1000); + sleep_ms(1000); assert_that(&p.bin("foo"), existing_file()); @@ -74,7 +78,7 @@ fn modify_only_some_files() { File::create(&lib).unwrap().write_all(b"invalid rust code").unwrap(); File::create(&bin).unwrap().write_all(b"#[allow(unused)]fn foo() {}").unwrap(); - lib.move_into_the_past().unwrap(); + lib.move_into_the_past(); // Make sure the binary is rebuilt, not the lib assert_that(p.cargo("build"), @@ -195,8 +199,8 @@ fn rebuild_tests_if_lib_changes() { execs().with_status(0)); File::create(&p.root().join("src/lib.rs")).unwrap(); - p.root().move_into_the_past().unwrap(); - p.root().join("target").move_into_the_past().unwrap(); + p.root().move_into_the_past(); + p.root().join("target").move_into_the_past(); assert_that(p.cargo("build"), execs().with_status(0)); diff --git a/tests/test_cargo_generate_lockfile.rs b/tests/generate-lockfile.rs similarity index 98% rename from tests/test_cargo_generate_lockfile.rs rename to tests/generate-lockfile.rs index b4d7236c2b3..ad4d207f76d 100644 --- a/tests/test_cargo_generate_lockfile.rs +++ b/tests/generate-lockfile.rs @@ -1,7 +1,10 @@ +extern crate cargotest; +extern crate hamcrest; + use std::fs::{self, File}; use std::io::prelude::*; -use support::{project, execs}; +use cargotest::support::{project, execs}; use hamcrest::{assert_that, existing_file, is_not}; #[test] diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/git.rs similarity index 98% rename from tests/test_cargo_compile_git_deps.rs rename to tests/git.rs index 14825ba36bc..ef7f1b0cd39 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/git.rs @@ -1,12 +1,17 @@ +extern crate cargo; +extern crate cargotest; +extern crate git2; +extern crate hamcrest; + use std::fs::{self, File}; use std::io::prelude::*; use std::path::Path; -use git2; -use support::{git, project, execs, main_file, path2url}; -use support::paths::{self, CargoPathExt}; -use hamcrest::{assert_that,existing_file}; use cargo::util::process; +use cargotest::{sleep_ms, RUSTC}; +use cargotest::support::paths::{self, CargoPathExt}; +use cargotest::support::{git, project, execs, main_file, path2url}; +use hamcrest::{assert_that,existing_file}; #[test] fn cargo_compile_simple_git_dep() { @@ -534,7 +539,7 @@ fn recompilation() { println!("compile after commit"); assert_that(p.cargo("build"), execs().with_stdout("")); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); // Update the dependency and carry on! assert_that(p.cargo("update"), @@ -635,7 +640,7 @@ fn update_with_shared_deps() { git::add(&repo); git::commit(&repo); - ::sleep_ms(1000); + sleep_ms(1000); // By default, not transitive updates println!("dep1 update"); @@ -838,7 +843,7 @@ fn stale_cached_version() { git::add(&repo); git::commit(&repo); - ::sleep_ms(1000); + sleep_ms(1000); let rev = repo.revparse_single("HEAD").unwrap().id(); @@ -940,7 +945,7 @@ fn dep_with_changed_submodule() { git::add(&repo); git::commit(&repo); - ::sleep_ms(1000); + sleep_ms(1000); // Update the dependency and carry on! println!("update"); assert_that(project.cargo("update").arg("-v"), @@ -1035,9 +1040,9 @@ fn git_build_cmd_freshness() { src/bar.rs ") }).unwrap(); - foo.root().move_into_the_past().unwrap(); + foo.root().move_into_the_past(); - ::sleep_ms(1000); + sleep_ms(1000); assert_that(foo.cargo("build"), execs().with_status(0) @@ -1125,7 +1130,7 @@ fn git_repo_changing_no_rebuild() { .file("src/main.rs", "fn main() {}") .file("build.rs", "fn main() {}"); p1.build(); - p1.root().move_into_the_past().unwrap(); + p1.root().move_into_the_past(); assert_that(p1.cargo("build"), execs().with_stderr(&format!("\ [UPDATING] git repository `{bar}` @@ -1209,7 +1214,7 @@ fn git_dep_build_cmd() { "#) }).unwrap(); - p.root().join("bar").move_into_the_past().unwrap(); + p.root().join("bar").move_into_the_past(); assert_that(p.cargo("build"), execs().with_status(0)); @@ -1707,7 +1712,7 @@ fn lints_are_suppressed() { #[test] fn denied_lints_are_allowed() { - let enabled = super::RUSTC.with(|r| r.cap_lints); + let enabled = RUSTC.with(|r| r.cap_lints); if !enabled { return } let a = git::new("a", |p| { diff --git a/tests/test_cargo_init.rs b/tests/init.rs similarity index 98% rename from tests/test_cargo_init.rs rename to tests/init.rs index b902cb0bf89..0e180bb45de 100644 --- a/tests/test_cargo_init.rs +++ b/tests/init.rs @@ -1,11 +1,16 @@ +extern crate cargotest; +extern crate cargo; +extern crate tempdir; +extern crate hamcrest; + use std::fs::{self, File}; use std::io::prelude::*; use std::env; -use tempdir::TempDir; -use support::{execs, paths, cargo_dir}; -use hamcrest::{assert_that, existing_file, existing_dir, is_not}; use cargo::util::{process, ProcessBuilder}; +use cargotest::support::{execs, paths, cargo_dir}; +use hamcrest::{assert_that, existing_file, existing_dir, is_not}; +use tempdir::TempDir; fn cargo_process(s: &str) -> ProcessBuilder { let mut p = process(&cargo_dir().join("cargo")); diff --git a/tests/test_cargo_install.rs b/tests/install.rs similarity index 95% rename from tests/test_cargo_install.rs rename to tests/install.rs index bc5be24c0d3..71b61b5e97f 100644 --- a/tests/test_cargo_install.rs +++ b/tests/install.rs @@ -1,21 +1,20 @@ -use std::fmt; +extern crate cargo; +extern crate cargotest; +extern crate hamcrest; + use std::fs::{self, File}; use std::io::prelude::*; -use std::path::{Path, PathBuf}; -use support::paths::CargoPathExt; use cargo::util::ProcessBuilder; -use hamcrest::{assert_that, existing_file, is_not, Matcher, MatchResult}; - -use support::{project, execs}; -use support::paths; -use support::registry::Package; -use support::git; - -pub use self::InstalledExe as has_installed_exe; +use cargotest::install::{cargo_home, has_installed_exe}; +use cargotest::support::git; +use cargotest::support::paths; +use cargotest::support::registry::Package; +use cargotest::support::{project, execs}; +use hamcrest::{assert_that, is_not}; fn cargo_process(s: &str) -> ProcessBuilder { - let mut p = ::cargo_process(); + let mut p = cargotest::cargo_process(); p.arg(s); return p } @@ -30,29 +29,6 @@ fn pkg(name: &str, vers: &str) { .publish() } -fn exe(name: &str) -> String { - if cfg!(windows) {format!("{}.exe", name)} else {name.to_string()} -} - -pub fn cargo_home() -> PathBuf { - paths::home().join(".cargo") -} - -pub struct InstalledExe(pub &'static str); - -impl> Matcher

for InstalledExe { - fn matches(&self, path: P) -> MatchResult { - let path = path.as_ref().join("bin").join(exe(self.0)); - existing_file().matches(&path) - } -} - -impl fmt::Display for InstalledExe { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "installed exe `{}`", self.0) - } -} - #[test] fn simple() { pkg("foo", "0.0.1"); @@ -722,8 +698,8 @@ fn do_not_rebuilds_on_local_install() { warning: be sure to add `[..]` to your PATH to be able to run the installed binaries ")); - assert!(p.build_dir().c_exists()); - assert!(p.release_bin("foo").c_exists()); + assert!(p.build_dir().exists()); + assert!(p.release_bin("foo").exists()); assert_that(cargo_home(), has_installed_exe("foo")); } diff --git a/tests/test_cargo_metadata.rs b/tests/metadata.rs similarity index 98% rename from tests/test_cargo_metadata.rs rename to tests/metadata.rs index eee4486c5ce..478acf883ab 100644 --- a/tests/test_cargo_metadata.rs +++ b/tests/metadata.rs @@ -1,7 +1,9 @@ -use hamcrest::assert_that; -use support::registry::Package; -use support::{project, execs, basic_bin_manifest, main_file}; +extern crate cargotest; +extern crate hamcrest; +use hamcrest::assert_that; +use cargotest::support::registry::Package; +use cargotest::support::{project, execs, basic_bin_manifest, main_file}; #[test] fn cargo_metadata_simple() { diff --git a/tests/test_cargo_net_config.rs b/tests/net-config.rs similarity index 94% rename from tests/test_cargo_net_config.rs rename to tests/net-config.rs index 92389f62587..d4fdb3b1279 100644 --- a/tests/test_cargo_net_config.rs +++ b/tests/net-config.rs @@ -1,4 +1,7 @@ -use support::{project, execs}; +extern crate cargotest; +extern crate hamcrest; + +use cargotest::support::{project, execs}; use hamcrest::assert_that; #[test] diff --git a/tests/test_cargo_new.rs b/tests/new.rs similarity index 94% rename from tests/test_cargo_new.rs rename to tests/new.rs index fc2d73916ac..23b637d3d12 100644 --- a/tests/test_cargo_new.rs +++ b/tests/new.rs @@ -1,16 +1,20 @@ +extern crate cargo; +extern crate cargotest; +extern crate hamcrest; +extern crate tempdir; + use std::fs::{self, File}; use std::io::prelude::*; use std::env; -use tempdir::TempDir; - -use support::{execs, paths}; -use support::paths::CargoPathExt; -use hamcrest::{assert_that, existing_file, existing_dir, is_not}; use cargo::util::ProcessBuilder; +use cargotest::process; +use cargotest::support::{execs, paths}; +use hamcrest::{assert_that, existing_file, existing_dir, is_not}; +use tempdir::TempDir; fn cargo_process(s: &str) -> ProcessBuilder { - let mut p = ::cargo_process(); + let mut p = cargotest::cargo_process(); p.arg(s); return p; } @@ -230,10 +234,10 @@ fn finds_author_email() { #[test] fn finds_author_git() { - ::process("git").args(&["config", "--global", "user.name", "bar"]) - .exec().unwrap(); - ::process("git").args(&["config", "--global", "user.email", "baz"]) - .exec().unwrap(); + process("git").args(&["config", "--global", "user.name", "bar"]) + .exec().unwrap(); + process("git").args(&["config", "--global", "user.email", "baz"]) + .exec().unwrap(); assert_that(cargo_process("new").arg("foo").env("USER", "foo"), execs().with_status(0)); @@ -278,10 +282,10 @@ fn finds_git_author() { #[test] fn author_prefers_cargo() { - ::process("git").args(&["config", "--global", "user.name", "foo"]) - .exec().unwrap(); - ::process("git").args(&["config", "--global", "user.email", "bar"]) - .exec().unwrap(); + process("git").args(&["config", "--global", "user.name", "foo"]) + .exec().unwrap(); + process("git").args(&["config", "--global", "user.email", "bar"]) + .exec().unwrap(); let root = paths::root(); fs::create_dir(&root.join(".cargo")).unwrap(); File::create(&root.join(".cargo/config")).unwrap().write_all(br#" @@ -298,7 +302,7 @@ fn author_prefers_cargo() { let mut contents = String::new(); File::open(&toml).unwrap().read_to_string(&mut contents).unwrap(); assert!(contents.contains(r#"authors = ["new-foo "]"#)); - assert!(!root.join("foo/.gitignore").c_exists()); + assert!(!root.join("foo/.gitignore").exists()); } #[test] @@ -317,7 +321,7 @@ fn git_prefers_command_line() { .cwd(td.path()) .env("USER", "foo"), execs().with_status(0)); - assert!(td.path().join("foo/.gitignore").c_exists()); + assert!(td.path().join("foo/.gitignore").exists()); } #[test] diff --git a/tests/test_cargo_overrides.rs b/tests/overrides.rs similarity index 98% rename from tests/test_cargo_overrides.rs rename to tests/overrides.rs index 4a53938cce4..2f87638f0bb 100644 --- a/tests/test_cargo_overrides.rs +++ b/tests/overrides.rs @@ -1,9 +1,11 @@ -use hamcrest::assert_that; +extern crate cargotest; +extern crate hamcrest; -use support::registry::{registry, Package}; -use support::{execs, project}; -use support::git; -use support::paths; +use cargotest::support::git; +use cargotest::support::paths; +use cargotest::support::registry::{registry, Package}; +use cargotest::support::{execs, project}; +use hamcrest::assert_that; #[test] fn override_simple() { diff --git a/tests/test_cargo_package.rs b/tests/package.rs similarity index 96% rename from tests/test_cargo_package.rs rename to tests/package.rs index 1e6a82c2f15..f9a810fb438 100644 --- a/tests/test_cargo_package.rs +++ b/tests/package.rs @@ -1,13 +1,18 @@ +extern crate cargotest; +extern crate flate2; +extern crate git2; +extern crate hamcrest; +extern crate tar; + use std::fs::File; use std::io::prelude::*; use std::path::Path; +use cargotest::cargo_process; +use cargotest::support::{project, execs, paths, git, path2url}; use flate2::read::GzDecoder; -use git2; -use tar::Archive; - -use support::{project, execs, paths, git, path2url}; use hamcrest::{assert_that, existing_file}; +use tar::Archive; #[test] fn simple() { @@ -145,7 +150,7 @@ fn package_verbose() { "#) .file("a/src/lib.rs", ""); p.build(); - let mut cargo = ::cargo_process(); + let mut cargo = cargo_process(); cargo.cwd(p.root()); assert_that(cargo.clone().arg("build"), execs().with_status(0)); @@ -276,7 +281,7 @@ fn package_new_git_repo() { p.build(); git2::Repository::init(&p.root()).unwrap(); - assert_that(::cargo_process().arg("package").cwd(p.root()) + assert_that(cargo_process().arg("package").cwd(p.root()) .arg("--no-verify").arg("-v"), execs().with_status(0).with_stderr("\ [WARNING] manifest has no description[..] @@ -313,7 +318,7 @@ fn package_git_submodule() { repository.reset(&repository.revparse_single("HEAD").unwrap(), git2::ResetType::Hard, None).unwrap(); - assert_that(::cargo_process().arg("package").cwd(project.root()) + assert_that(cargo_process().arg("package").cwd(project.root()) .arg("--no-verify").arg("-v"), execs().with_status(0).with_stderr_contains("[ARCHIVING] bar/Makefile")); } @@ -335,7 +340,7 @@ fn no_duplicates_from_modified_tracked_files() { File::create(p.root().join("src/main.rs")).unwrap().write_all(r#" fn main() { println!("A change!"); } "#.as_bytes()).unwrap(); - let mut cargo = ::cargo_process(); + let mut cargo = cargo_process(); cargo.cwd(p.root()); assert_that(cargo.clone().arg("build"), execs().with_status(0)); assert_that(cargo.arg("package").arg("--list"), diff --git a/tests/test_cargo_compile_path_deps.rs b/tests/path.rs similarity index 98% rename from tests/test_cargo_compile_path_deps.rs rename to tests/path.rs index e2f2d36e22c..97cc213225a 100644 --- a/tests/test_cargo_compile_path_deps.rs +++ b/tests/path.rs @@ -1,10 +1,15 @@ +extern crate cargo; +extern crate cargotest; +extern crate hamcrest; + use std::fs::{self, File}; use std::io::prelude::*; -use support::{project, execs, main_file}; -use support::paths::{self, CargoPathExt}; -use hamcrest::{assert_that, existing_file}; use cargo::util::process; +use cargotest::sleep_ms; +use cargotest::support::paths::{self, CargoPathExt}; +use cargotest::support::{project, execs, main_file}; +use hamcrest::{assert_that, existing_file}; #[test] fn cargo_compile_with_nested_deps_shorthand() { @@ -279,7 +284,7 @@ fn no_rebuild_dependency() { // This time we shouldn't compile bar assert_that(p.cargo("build"), execs().with_stdout("")); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); p.build(); // rebuild the files (rewriting them in the process) assert_that(p.cargo("build"), @@ -352,7 +357,7 @@ fn deep_dependencies_trigger_rebuild() { // // We base recompilation off mtime, so sleep for at least a second to ensure // that this write will change the mtime. - ::sleep_ms(1000); + sleep_ms(1000); File::create(&p.root().join("baz/src/baz.rs")).unwrap().write_all(br#" pub fn baz() { println!("hello!"); } "#).unwrap(); @@ -365,7 +370,7 @@ fn deep_dependencies_trigger_rebuild() { p.url()))); // Make sure an update to bar doesn't trigger baz - ::sleep_ms(1000); + sleep_ms(1000); File::create(&p.root().join("bar/src/bar.rs")).unwrap().write_all(br#" extern crate baz; pub fn bar() { println!("hello!"); baz::baz(); } @@ -481,7 +486,7 @@ fn nested_deps_recompile() { [COMPILING] foo v0.5.0 ({})\n", bar, p.url()))); - ::sleep_ms(1000); + sleep_ms(1000); File::create(&p.root().join("src/foo.rs")).unwrap().write_all(br#" fn main() {} @@ -686,7 +691,7 @@ fn path_dep_build_cmd() { "#); p.build(); - p.root().join("bar").move_into_the_past().unwrap(); + p.root().join("bar").move_into_the_past(); assert_that(p.cargo("build"), execs().with_stderr(&format!("[COMPILING] bar v0.5.0 ({}/bar)\n\ diff --git a/tests/test_cargo_compile_plugins.rs b/tests/plugins.rs similarity index 96% rename from tests/test_cargo_compile_plugins.rs rename to tests/plugins.rs index 4c3c3183e89..7adffed9edf 100644 --- a/tests/test_cargo_compile_plugins.rs +++ b/tests/plugins.rs @@ -1,12 +1,16 @@ +extern crate cargotest; +extern crate hamcrest; + use std::fs; use std::env; -use support::{project, execs}; +use cargotest::{is_nightly, rustc_host}; +use cargotest::support::{project, execs}; use hamcrest::assert_that; #[test] fn plugin_to_the_max() { - if !::is_nightly() { return } + if !is_nightly() { return } let foo = project("foo") .file("Cargo.toml", r#" @@ -84,7 +88,7 @@ fn plugin_to_the_max() { #[test] fn plugin_with_dynamic_native_dependency() { - if !::is_nightly() { return } + if !is_nightly() { return } let build = project("builder") .file("Cargo.toml", r#" @@ -227,7 +231,7 @@ fn doctest_a_plugin() { // See #1515 #[test] fn native_plugin_dependency_with_custom_ar_linker() { - let target = ::rustc_host(); + let target = rustc_host(); let foo = project("foo") .file("Cargo.toml", r#" diff --git a/tests/test_cargo_profiles.rs b/tests/profiles.rs similarity index 97% rename from tests/test_cargo_profiles.rs rename to tests/profiles.rs index 5b2c268a249..6edecf46514 100644 --- a/tests/test_cargo_profiles.rs +++ b/tests/profiles.rs @@ -1,7 +1,10 @@ +extern crate cargotest; +extern crate hamcrest; + use std::env; use std::path::MAIN_SEPARATOR as SEP; -use support::{project, execs}; +use cargotest::support::{project, execs}; use hamcrest::assert_that; #[test] diff --git a/tests/test_cargo_publish.rs b/tests/publish.rs similarity index 95% rename from tests/test_cargo_publish.rs rename to tests/publish.rs index 0c3aa6115f0..37299bc0d66 100644 --- a/tests/test_cargo_publish.rs +++ b/tests/publish.rs @@ -1,18 +1,22 @@ +extern crate cargotest; +extern crate flate2; +extern crate hamcrest; +extern crate tar; +extern crate url; + use std::io::prelude::*; use std::fs::{self, File}; use std::io::SeekFrom; use std::path::PathBuf; +use cargotest::support::git::repo; +use cargotest::support::paths; +use cargotest::support::{project, execs}; use flate2::read::GzDecoder; +use hamcrest::assert_that; use tar::Archive; use url::Url; -use support::{project, execs}; -use support::paths; -use support::git::repo; - -use hamcrest::assert_that; - fn registry_path() -> PathBuf { paths::root().join("registry") } fn registry() -> Url { Url::from_file_path(&*registry_path()).ok().unwrap() } fn upload_path() -> PathBuf { paths::root().join("upload") } diff --git a/tests/test_cargo_read_manifest.rs b/tests/read-manifest.rs similarity index 96% rename from tests/test_cargo_read_manifest.rs rename to tests/read-manifest.rs index d239a0f0239..cc24f3f6c87 100644 --- a/tests/test_cargo_read_manifest.rs +++ b/tests/read-manifest.rs @@ -1,4 +1,7 @@ -use support::{project, execs, main_file, basic_bin_manifest}; +extern crate cargotest; +extern crate hamcrest; + +use cargotest::support::{project, execs, main_file, basic_bin_manifest}; use hamcrest::{assert_that}; fn remove_all_whitespace(s: &str) -> String { diff --git a/tests/test_cargo_registry.rs b/tests/registry.rs similarity index 97% rename from tests/test_cargo_registry.rs rename to tests/registry.rs index 2e2efad35d5..cb517c91c1b 100644 --- a/tests/test_cargo_registry.rs +++ b/tests/registry.rs @@ -1,11 +1,15 @@ +#[macro_use] +extern crate cargotest; +extern crate hamcrest; + use std::fs::{self, File}; use std::io::prelude::*; -use support::{project, execs}; -use support::paths::{self, CargoPathExt}; -use support::registry::{self, Package}; -use support::git; - +use cargotest::cargo_process; +use cargotest::support::git; +use cargotest::support::paths::{self, CargoPathExt}; +use cargotest::support::registry::{self, Package}; +use cargotest::support::{project, execs}; use hamcrest::assert_that; #[test] @@ -282,7 +286,7 @@ fn lockfile_locks() { ", dir = p.url()))); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); Package::new("bar", "0.0.2").publish(); assert_that(p.cargo("build"), @@ -318,7 +322,7 @@ fn lockfile_locks_transitively() { ", dir = p.url()))); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); Package::new("baz", "0.0.2").publish(); Package::new("bar", "0.0.2").dep("baz", "*").publish(); @@ -439,9 +443,9 @@ fn update_with_lockfile_if_packages_missing() { Package::new("bar", "0.0.1").publish(); assert_that(p.cargo("build"), execs().with_status(0)); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); - paths::home().join(".cargo/registry").rm_rf().unwrap(); + paths::home().join(".cargo/registry").rm_rf(); assert_that(p.cargo("build"), execs().with_status(0).with_stderr("\ [UPDATING] registry `[..]` @@ -471,7 +475,7 @@ fn update_lockfile() { Package::new("bar", "0.0.2").publish(); Package::new("bar", "0.0.3").publish(); - paths::home().join(".cargo/registry").rm_rf().unwrap(); + paths::home().join(".cargo/registry").rm_rf(); println!("0.0.2 update"); assert_that(p.cargo("update") .arg("-p").arg("bar").arg("--precise").arg("0.0.2"), @@ -560,7 +564,7 @@ fn dev_dependency_not_used() { 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"), + assert_that(cargo_process().arg("login").arg("foo").arg("-v"), execs().with_status(0)); } @@ -623,7 +627,7 @@ fn updating_a_dep() { ", dir = p.url()))); - File::create(&p.root().join("a/Cargo.toml")).unwrap().write_all(br#" + t!(File::create(&p.root().join("a/Cargo.toml"))).write_all(br#" [project] name = "a" version = "0.0.1" @@ -678,7 +682,7 @@ fn git_and_registry_dep() { Package::new("a", "0.0.1").publish(); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); assert_that(p.cargo("build"), execs().with_status(0).with_stderr(&format!("\ [UPDATING] [..] @@ -689,7 +693,7 @@ fn git_and_registry_dep() { [COMPILING] foo v0.0.1 ({dir}) ", dir = p.url()))); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); println!("second"); assert_that(p.cargo("build"), diff --git a/tests/test_cargo_run.rs b/tests/run.rs similarity index 99% rename from tests/test_cargo_run.rs rename to tests/run.rs index 151ee8b09b5..53ab2b0cbf9 100644 --- a/tests/test_cargo_run.rs +++ b/tests/run.rs @@ -1,6 +1,9 @@ +extern crate cargotest; +extern crate hamcrest; + use std::path::MAIN_SEPARATOR as SEP; -use support::{project, execs, path2url}; +use cargotest::support::{project, execs, path2url}; use hamcrest::{assert_that, existing_file}; #[test] diff --git a/tests/test_cargo_rustc.rs b/tests/rustc.rs similarity index 99% rename from tests/test_cargo_rustc.rs rename to tests/rustc.rs index afc132e7f72..e65d713d41f 100644 --- a/tests/test_cargo_rustc.rs +++ b/tests/rustc.rs @@ -1,7 +1,9 @@ -use std::path::MAIN_SEPARATOR as SEP; +extern crate cargotest; +extern crate hamcrest; -use support::{execs, project}; +use std::path::MAIN_SEPARATOR as SEP; +use cargotest::support::{execs, project}; use hamcrest::assert_that; const CARGO_RUSTC_ERROR: &'static str = diff --git a/tests/test_cargo_rustdoc.rs b/tests/rustdoc.rs similarity index 98% rename from tests/test_cargo_rustdoc.rs rename to tests/rustdoc.rs index ed9e6fc9b6b..535c0d151dd 100644 --- a/tests/test_cargo_rustdoc.rs +++ b/tests/rustdoc.rs @@ -1,5 +1,9 @@ +extern crate cargotest; +extern crate hamcrest; + use std::path::MAIN_SEPARATOR as SEP; -use support::{execs, project}; + +use cargotest::support::{execs, project}; use hamcrest::{assert_that}; #[test] diff --git a/tests/test_cargo_compile_rustflags.rs b/tests/rustflags.rs similarity index 98% rename from tests/test_cargo_compile_rustflags.rs rename to tests/rustflags.rs index 8984b527a99..264c47219ef 100644 --- a/tests/test_cargo_compile_rustflags.rs +++ b/tests/rustflags.rs @@ -1,6 +1,11 @@ +extern crate cargotest; +extern crate hamcrest; + use std::io::Write; use std::fs::{self, File}; -use support::{project, execs, paths}; + +use cargotest::rustc_host; +use cargotest::support::{project, execs, paths}; use hamcrest::assert_that; #[test] @@ -184,7 +189,7 @@ fn env_rustflags_normal_source_with_target() { #[bench] fn run1(_ben: &mut test::Bencher) { }"#); p.build(); - let ref host = ::rustc_host(); + let ref host = rustc_host(); // Use RUSTFLAGS to pass an argument that will generate an error assert_that(p.cargo("build").env("RUSTFLAGS", "-Z bogus") @@ -224,7 +229,7 @@ fn env_rustflags_build_script_with_target() { "#); p.build(); - let host = ::rustc_host(); + let host = rustc_host(); assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo") .arg("--target").arg(host), execs().with_status(0)); @@ -263,7 +268,7 @@ fn env_rustflags_build_script_dep_with_target() { foo.build(); bar.build(); - let host = ::rustc_host(); + let host = rustc_host(); assert_that(foo.cargo("build").env("RUSTFLAGS", "--cfg foo") .arg("--target").arg(host), execs().with_status(0)); @@ -291,7 +296,7 @@ fn env_rustflags_plugin_with_target() { "#); p.build(); - let host = ::rustc_host(); + let host = rustc_host(); assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo") .arg("--target").arg(host), execs().with_status(0)); @@ -335,7 +340,7 @@ fn env_rustflags_plugin_dep_with_target() { foo.build(); bar.build(); - let host = ::rustc_host(); + let host = rustc_host(); assert_that(foo.cargo("build").env("RUSTFLAGS", "--cfg foo") .arg("--target").arg(host), execs().with_status(0)); @@ -598,7 +603,7 @@ fn build_rustflags_normal_source_with_target() { "#); p.build(); - let ref host = ::rustc_host(); + let ref host = rustc_host(); // Use RUSTFLAGS to pass an argument that will generate an error assert_that(p.cargo("build") @@ -642,7 +647,7 @@ fn build_rustflags_build_script_with_target() { "#); p.build(); - let host = ::rustc_host(); + let host = rustc_host(); assert_that(p.cargo("build") .arg("--target").arg(host), execs().with_status(0)); @@ -685,7 +690,7 @@ fn build_rustflags_build_script_dep_with_target() { foo.build(); bar.build(); - let host = ::rustc_host(); + let host = rustc_host(); assert_that(foo.cargo("build") .arg("--target").arg(host), execs().with_status(0)); @@ -717,7 +722,7 @@ fn build_rustflags_plugin_with_target() { "#); p.build(); - let host = ::rustc_host(); + let host = rustc_host(); assert_that(p.cargo("build") .arg("--target").arg(host), execs().with_status(0)); @@ -765,7 +770,7 @@ fn build_rustflags_plugin_dep_with_target() { foo.build(); bar.build(); - let host = ::rustc_host(); + let host = rustc_host(); assert_that(foo.cargo("build") .arg("--target").arg(host), execs().with_status(0)); diff --git a/tests/test_cargo_search.rs b/tests/search.rs similarity index 95% rename from tests/test_cargo_search.rs rename to tests/search.rs index 181088e0e71..19f04a33bdf 100644 --- a/tests/test_cargo_search.rs +++ b/tests/search.rs @@ -1,15 +1,18 @@ +extern crate cargo; +extern crate cargotest; +extern crate hamcrest; +extern crate url; + use std::fs::{self, File}; use std::io::prelude::*; use std::path::PathBuf; -use url::Url; - use cargo::util::ProcessBuilder; -use support::execs; -use support::paths; -use support::git::repo; - +use cargotest::support::execs; +use cargotest::support::git::repo; +use cargotest::support::paths; use hamcrest::assert_that; +use url::Url; fn registry_path() -> PathBuf { paths::root().join("registry") } fn registry() -> Url { Url::from_file_path(&*registry_path()).ok().unwrap() } @@ -34,7 +37,7 @@ fn setup() { } fn cargo_process(s: &str) -> ProcessBuilder { - let mut b = ::cargo_process(); + let mut b = cargotest::cargo_process(); b.arg(s); return b } diff --git a/tests/test_shell.rs b/tests/shell.rs similarity index 93% rename from tests/test_shell.rs rename to tests/shell.rs index 039b5c5e1aa..40471f0bf15 100644 --- a/tests/test_shell.rs +++ b/tests/shell.rs @@ -1,14 +1,18 @@ +extern crate cargo; +extern crate cargotest; +extern crate hamcrest; +extern crate term; + use std::io::prelude::*; use std::io; use std::sync::{Arc, Mutex}; -use term::{Terminal, TerminfoTerminal, color}; -use hamcrest::{assert_that}; -use cargo::core::shell::{Shell, ShellConfig}; use cargo::core::shell::ColorConfig::{Auto,Always, Never}; +use cargo::core::shell::{Shell, ShellConfig}; use cargo::util::CargoResult; - -use support::{Tap, execs, shell_writes}; +use cargotest::support::{Tap, execs, shell_writes}; +use hamcrest::{assert_that}; +use term::{Terminal, TerminfoTerminal, color}; struct Sink(Arc>>); @@ -83,7 +87,7 @@ fn color_explicitly_enabled() { #[test] fn no_term() { // Verify that shell creation is successful when $TERM does not exist. - assert_that(::cargo_process().env_remove("TERM"), + assert_that(cargotest::cargo_process().env_remove("TERM"), execs().with_stderr("")); } diff --git a/tests/support/paths.rs b/tests/support/paths.rs deleted file mode 100644 index 837cface05f..00000000000 --- a/tests/support/paths.rs +++ /dev/null @@ -1,166 +0,0 @@ -use std::env; -use std::cell::Cell; -use std::fs; -use std::io::{self, ErrorKind}; -use std::path::{Path, PathBuf}; -use std::sync::{Once, ONCE_INIT}; -use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; - -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)); - -fn init() { - static GLOBAL_INIT: Once = ONCE_INIT; - thread_local!(static LOCAL_INIT: Cell = 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' - - // If `cargo test` is run manually then our path looks like - // `target/debug/foo`, in which case our `path` is already pointing at - // `target`. If, however, `cargo test --target $target` is used then the - // output is `target/$target/debug/foo`, so our path is pointing at - // `target/$target`. Here we conditionally pop the `$target` name. - if path.file_name().and_then(|s| s.to_str()) != Some("target") { - path.pop(); - } - - path.join(CARGO_INTEGRATION_TEST_DIR) -} - -pub fn root() -> PathBuf { - init(); - global_root().join(&TASK_ID.with(|my_id| format!("t{}", my_id))) -} - -pub fn home() -> PathBuf { - root().join("home") -} - -pub trait CargoPathExt { - fn rm_rf(&self) -> io::Result<()>; - fn mkdir_p(&self) -> io::Result<()>; - fn move_into_the_past(&self) -> io::Result<()>; - - // cargo versions of the standard PathExt trait - fn c_exists(&self) -> bool; - fn c_is_file(&self) -> bool; - fn c_is_dir(&self) -> bool; - fn c_metadata(&self) -> io::Result; -} - -impl CargoPathExt for Path { - /* Technically there is a potential race condition, but we don't - * care all that much for our tests - */ - fn rm_rf(&self) -> io::Result<()> { - if self.c_exists() { - for file in fs::read_dir(self).unwrap() { - let file = try!(file).path(); - - if file.c_is_dir() { - try!(file.rm_rf()); - } else { - // On windows we can't remove a readonly file, and git will - // often clone files as readonly. As a result, we have some - // special logic to remove readonly files on windows. - match fs::remove_file(&file) { - Ok(()) => {} - Err(ref e) if cfg!(windows) && - e.kind() == ErrorKind::PermissionDenied => { - let mut p = file.c_metadata().unwrap().permissions(); - p.set_readonly(false); - fs::set_permissions(&file, p).unwrap(); - try!(fs::remove_file(&file)); - } - Err(e) => return Err(e) - } - } - } - fs::remove_dir(self) - } else { - Ok(()) - } - } - - fn mkdir_p(&self) -> io::Result<()> { - fs::create_dir_all(self) - } - - fn move_into_the_past(&self) -> io::Result<()> { - if self.c_is_file() { - try!(time_travel(self)); - } else { - try!(recurse(self, &self.join("target"))); - } - return Ok(()); - - fn recurse(p: &Path, bad: &Path) -> io::Result<()> { - if p.c_is_file() { - time_travel(p) - } else if p.starts_with(bad) { - Ok(()) - } else { - for f in try!(fs::read_dir(p)) { - let f = try!(f).path(); - try!(recurse(&f, bad)); - } - Ok(()) - } - } - - fn time_travel(path: &Path) -> io::Result<()> { - let stat = try!(path.c_metadata()); - - let mtime = FileTime::from_last_modification_time(&stat); - let newtime = mtime.seconds_relative_to_1970() - 3600; - let nanos = mtime.nanoseconds(); - let newtime = FileTime::from_seconds_since_1970(newtime, nanos); - - // Sadly change_file_times has a failure mode where a readonly file - // cannot have its times changed on windows. - match filetime::set_file_times(path, newtime, newtime) { - Err(ref e) if e.kind() == io::ErrorKind::PermissionDenied => {} - e => return e, - } - let mut perms = stat.permissions(); - perms.set_readonly(false); - try!(fs::set_permissions(path, perms)); - filetime::set_file_times(path, newtime, newtime) - } - } - - fn c_exists(&self) -> bool { - fs::metadata(self).is_ok() - } - - fn c_is_file(&self) -> bool { - fs::metadata(self).map(|m| m.is_file()).unwrap_or(false) - } - - fn c_is_dir(&self) -> bool { - fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false) - } - - fn c_metadata(&self) -> io::Result { - fs::metadata(self) - } -} diff --git a/tests/test_cargo_test.rs b/tests/test.rs similarity index 99% rename from tests/test_cargo_test.rs rename to tests/test.rs index 953449db1d0..96149890084 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test.rs @@ -1,9 +1,14 @@ +extern crate cargo; +extern crate cargotest; +extern crate hamcrest; + use std::fs::File; use std::io::prelude::*; use std::str; -use support::{project, execs, basic_bin_manifest, basic_lib_manifest}; -use support::paths::CargoPathExt; +use cargotest::{sleep_ms, is_nightly}; +use cargotest::support::{project, execs, basic_bin_manifest, basic_lib_manifest}; +use cargotest::support::paths::CargoPathExt; use hamcrest::{assert_that, existing_file, is_not}; use cargo::util::process; @@ -968,7 +973,7 @@ test foo ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured ")); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); assert_that(p.cargo("test"), execs().with_status(0) .with_stderr("\ @@ -1359,7 +1364,7 @@ fn build_then_selective_test() { .file("b/src/lib.rs", ""); assert_that(p.cargo_process("build"), execs().with_status(0)); - p.root().move_into_the_past().unwrap(); + p.root().move_into_the_past(); assert_that(p.cargo("test").arg("-p").arg("b"), execs().with_status(0)); } @@ -2010,7 +2015,7 @@ fn bin_does_not_rebuild_tests() { assert_that(p.cargo("test").arg("-v"), execs().with_status(0)); - ::sleep_ms(1000); + sleep_ms(1000); File::create(&p.root().join("src/main.rs")).unwrap() .write_all(b"fn main() { 3; }").unwrap(); @@ -2124,7 +2129,7 @@ test result: ok.[..] #[test] fn test_panic_abort_with_dep() { - if !::is_nightly() { + if !is_nightly() { return } let p = project("foo") diff --git a/tests/tests.rs b/tests/tests.rs deleted file mode 100644 index bad620d9658..00000000000 --- a/tests/tests.rs +++ /dev/null @@ -1,105 +0,0 @@ -#![deny(warnings)] - -extern crate bufstream; -extern crate cargo; -extern crate filetime; -extern crate flate2; -extern crate git2; -extern crate hamcrest; -extern crate libc; -extern crate rustc_serialize; -extern crate tar; -extern crate tempdir; -extern crate term; -extern crate url; -#[cfg(windows)] extern crate kernel32; -#[cfg(windows)] extern crate winapi; - -#[macro_use] -extern crate log; - -use cargo::util::Rustc; -use std::ffi::OsStr; -use std::time::Duration; - -mod support; - -mod test_bad_config; -mod test_bad_manifest_path; -mod test_cargo; -mod test_cargo_bench; -mod test_cargo_build_auth; -mod test_cargo_build_lib; -mod test_cargo_clean; -mod test_cargo_compile; -mod test_cargo_compile_custom_build; -mod test_cargo_compile_git_deps; -mod test_cargo_compile_path_deps; -mod test_cargo_compile_plugins; -mod test_cargo_compile_rustflags; -mod test_cargo_cross_compile; -mod test_cargo_doc; -mod test_cargo_features; -mod test_cargo_fetch; -mod test_cargo_freshness; -mod test_cargo_generate_lockfile; -mod test_cargo_init; -mod test_cargo_install; -mod test_cargo_metadata; -mod test_cargo_new; -mod test_cargo_package; -mod test_cargo_profiles; -mod test_cargo_overrides; -mod test_cargo_publish; -mod test_cargo_read_manifest; -mod test_cargo_registry; -mod test_cargo_run; -mod test_cargo_concurrent; -mod test_cargo_rustc; -mod test_cargo_rustdoc; -mod test_cargo_search; -mod test_cargo_test; -mod test_cargo_tool_paths; -mod test_cargo_config; -mod test_cargo_verify_project; -mod test_cargo_version; -mod test_shell; -mod test_cargo_death; -mod test_cargo_cfg; -mod test_cargo_net_config; - -thread_local!(static RUSTC: Rustc = Rustc::new("rustc").unwrap()); - -fn rustc_host() -> String { - RUSTC.with(|r| r.host.clone()) -} - -fn is_nightly() -> bool { - RUSTC.with(|r| { - r.verbose_version.contains("-nightly") || - r.verbose_version.contains("-dev") - }) -} - -fn process>(t: T) -> cargo::util::ProcessBuilder { - let mut p = cargo::util::process(t.as_ref()); - p.cwd(&support::paths::root()) - .env_remove("CARGO_HOME") - .env("HOME", support::paths::home()) - .env("CARGO_HOME", support::paths::home().join(".cargo")) - .env_remove("RUSTC") - .env_remove("RUSTFLAGS") - .env_remove("XDG_CONFIG_HOME") // see #2345 - .env("GIT_CONFIG_NOSYSTEM", "1") // keep trying to sandbox ourselves - .env_remove("CARGO_TARGET_DIR") // we assume 'target' - .env_remove("MSYSTEM"); // assume cmd.exe everywhere on windows - return p -} - -fn cargo_process() -> cargo::util::ProcessBuilder { - process(&support::cargo_dir().join("cargo")) -} - -fn sleep_ms(ms: u64) { - std::thread::sleep(Duration::from_millis(ms)); -} diff --git a/tests/test_cargo_tool_paths.rs b/tests/tool-paths.rs similarity index 94% rename from tests/test_cargo_tool_paths.rs rename to tests/tool-paths.rs index db76b45c216..2f61f503dfe 100644 --- a/tests/test_cargo_tool_paths.rs +++ b/tests/tool-paths.rs @@ -1,9 +1,13 @@ -use support::{path2url, project, execs}; +extern crate cargotest; +extern crate hamcrest; + +use cargotest::rustc_host; +use cargotest::support::{path2url, project, execs}; use hamcrest::assert_that; #[test] fn pathless_tools() { - let target = ::rustc_host(); + let target = rustc_host(); let foo = project("foo") .file("Cargo.toml", r#" @@ -31,7 +35,7 @@ fn pathless_tools() { #[test] fn absolute_tools() { - let target = ::rustc_host(); + let target = rustc_host(); // Escaped as they appear within a TOML config file let config = if cfg!(windows) { @@ -72,7 +76,7 @@ fn absolute_tools() { #[test] fn relative_tools() { - let target = ::rustc_host(); + let target = rustc_host(); // Escaped as they appear within a TOML config file let config = if cfg!(windows) { diff --git a/tests/test_cargo_verify_project.rs b/tests/verify-project.rs similarity index 92% rename from tests/test_cargo_verify_project.rs rename to tests/verify-project.rs index 64afb1d352d..7e76ae04d59 100644 --- a/tests/test_cargo_verify_project.rs +++ b/tests/verify-project.rs @@ -1,4 +1,7 @@ -use support::{project, execs, main_file, basic_bin_manifest}; +extern crate cargotest; +extern crate hamcrest; + +use cargotest::support::{project, execs, main_file, basic_bin_manifest}; use hamcrest::{assert_that}; fn verify_project_success_output() -> String { diff --git a/tests/test_cargo_version.rs b/tests/version.rs similarity index 90% rename from tests/test_cargo_version.rs rename to tests/version.rs index af54662c71d..e8b38262a47 100644 --- a/tests/test_cargo_version.rs +++ b/tests/version.rs @@ -1,6 +1,10 @@ -use support::{project, execs}; +extern crate cargo; +extern crate cargotest; +extern crate hamcrest; +extern crate rustc_serialize; + +use cargotest::support::{project, execs}; use hamcrest::assert_that; -use cargo; #[test] fn simple() {