From 43b42d6f4c7cb5008297546a945d9b89011becd4 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sat, 21 Jul 2018 22:17:44 +0100 Subject: [PATCH] Reorganise the testsuite crate module hierarchy * Collapse the nested cargotest::support module into the cargotest module (merge the mod.rs's) * Rename the cargotest module to support * Nest the top-level hamcrest module into support --- tests/testsuite/alt_registry.rs | 8 +- tests/testsuite/bad_config.rs | 6 +- tests/testsuite/bad_manifest_path.rs | 4 +- tests/testsuite/bench.rs | 8 +- tests/testsuite/build.rs | 14 +- tests/testsuite/build_auth.rs | 6 +- tests/testsuite/build_lib.rs | 4 +- tests/testsuite/build_plan.rs | 6 +- tests/testsuite/build_script.rs | 10 +- tests/testsuite/build_script_env.rs | 6 +- tests/testsuite/cargo_alias_config.rs | 4 +- tests/testsuite/cargo_command.rs | 10 +- tests/testsuite/cargo_features.rs | 6 +- tests/testsuite/cargotest/mod.rs | 179 ----------------- tests/testsuite/cfg.rs | 8 +- tests/testsuite/check.rs | 12 +- tests/testsuite/clean.rs | 6 +- tests/testsuite/concurrent.rs | 16 +- tests/testsuite/config.rs | 4 +- tests/testsuite/corrupt_git.rs | 6 +- tests/testsuite/cross_compile.rs | 6 +- tests/testsuite/cross_publish.rs | 4 +- tests/testsuite/custom_target.rs | 6 +- tests/testsuite/death.rs | 2 +- tests/testsuite/dep_info.rs | 4 +- tests/testsuite/directory.rs | 12 +- tests/testsuite/doc.rs | 16 +- tests/testsuite/features.rs | 10 +- tests/testsuite/fetch.rs | 8 +- tests/testsuite/fix.rs | 8 +- tests/testsuite/freshness.rs | 10 +- tests/testsuite/generate_lockfile.rs | 8 +- tests/testsuite/git.rs | 10 +- tests/testsuite/init.rs | 8 +- tests/testsuite/install.rs | 24 +-- tests/testsuite/jobserver.rs | 4 +- tests/testsuite/local_registry.rs | 8 +- tests/testsuite/lockfile_compat.rs | 8 +- tests/testsuite/login.rs | 10 +- tests/testsuite/main.rs | 3 +- tests/testsuite/metadata.rs | 6 +- tests/testsuite/net_config.rs | 4 +- tests/testsuite/new.rs | 10 +- tests/testsuite/out_dir.rs | 6 +- tests/testsuite/overrides.rs | 10 +- tests/testsuite/package.rs | 8 +- tests/testsuite/patch.rs | 10 +- tests/testsuite/path.rs | 10 +- tests/testsuite/plugins.rs | 6 +- tests/testsuite/proc_macro.rs | 6 +- tests/testsuite/profile_config.rs | 6 +- tests/testsuite/profile_overrides.rs | 6 +- tests/testsuite/profile_targets.rs | 6 +- tests/testsuite/profiles.rs | 6 +- tests/testsuite/publish.rs | 10 +- tests/testsuite/read_manifest.rs | 4 +- tests/testsuite/registry.rs | 14 +- tests/testsuite/rename_deps.rs | 12 +- tests/testsuite/required_features.rs | 8 +- tests/testsuite/resolve.rs | 8 +- tests/testsuite/run.rs | 14 +- tests/testsuite/rustc.rs | 4 +- tests/testsuite/rustc_info_cache.rs | 6 +- tests/testsuite/rustdoc.rs | 4 +- tests/testsuite/rustdocflags.rs | 4 +- tests/testsuite/rustflags.rs | 6 +- tests/testsuite/search.rs | 12 +- tests/testsuite/shell_quoting.rs | 4 +- tests/testsuite/small_fd_limits.rs | 10 +- .../{cargotest => }/support/cross_compile.rs | 2 +- .../testsuite/{cargotest => }/support/git.rs | 2 +- tests/testsuite/{ => support}/hamcrest.rs | 0 .../{cargotest => support}/install.rs | 4 +- .../testsuite/{cargotest => }/support/mod.rs | 189 +++++++++++++++++- .../{cargotest => }/support/paths.rs | 0 .../{cargotest => }/support/publish.rs | 4 +- .../{cargotest => }/support/registry.rs | 4 +- tests/testsuite/test.rs | 10 +- tests/testsuite/tool_paths.rs | 6 +- tests/testsuite/update.rs | 6 +- tests/testsuite/verify_project.rs | 4 +- tests/testsuite/version.rs | 4 +- tests/testsuite/warn_on_failure.rs | 6 +- tests/testsuite/workspaces.rs | 8 +- 84 files changed, 476 insertions(+), 485 deletions(-) delete mode 100644 tests/testsuite/cargotest/mod.rs rename tests/testsuite/{cargotest => }/support/cross_compile.rs (98%) rename tests/testsuite/{cargotest => }/support/git.rs (98%) rename tests/testsuite/{ => support}/hamcrest.rs (100%) rename tests/testsuite/{cargotest => support}/install.rs (91%) rename tests/testsuite/{cargotest => }/support/mod.rs (86%) rename tests/testsuite/{cargotest => }/support/paths.rs (100%) rename tests/testsuite/{cargotest => }/support/publish.rs (94%) rename tests/testsuite/{cargotest => }/support/registry.rs (99%) diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index e14a09b99..964c98082 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -1,7 +1,7 @@ -use cargotest::ChannelChanger; -use cargotest::support::registry::{self, alt_api_path, Package}; -use cargotest::support::{execs, paths, project}; -use hamcrest::assert_that; +use support::ChannelChanger; +use support::registry::{self, alt_api_path, Package}; +use support::{execs, paths, project}; +use support::hamcrest::assert_that; use std::fs::File; use std::io::Write; diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index 3a9cbcf12..a323e6971 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -1,6 +1,6 @@ -use cargotest::support::{execs, project}; -use cargotest::support::registry::Package; -use hamcrest::assert_that; +use support::{execs, project}; +use support::registry::Package; +use support::hamcrest::assert_that; #[test] fn bad1() { diff --git a/tests/testsuite/bad_manifest_path.rs b/tests/testsuite/bad_manifest_path.rs index 8ba9f5b0f..170534c8f 100644 --- a/tests/testsuite/bad_manifest_path.rs +++ b/tests/testsuite/bad_manifest_path.rs @@ -1,5 +1,5 @@ -use cargotest::support::{basic_bin_manifest, execs, main_file, project}; -use hamcrest::assert_that; +use support::{basic_bin_manifest, execs, main_file, project}; +use support::hamcrest::assert_that; fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) { let p = project() diff --git a/tests/testsuite/bench.rs b/tests/testsuite/bench.rs index 7d31b3e74..d28ebe4c8 100644 --- a/tests/testsuite/bench.rs +++ b/tests/testsuite/bench.rs @@ -1,10 +1,10 @@ use std::str; use cargo::util::process; -use cargotest::{is_nightly, ChannelChanger}; -use cargotest::support::paths::CargoPathExt; -use cargotest::support::{basic_bin_manifest, basic_lib_manifest, execs, project}; -use hamcrest::{assert_that, existing_file}; +use support::{is_nightly, ChannelChanger}; +use support::paths::CargoPathExt; +use support::{basic_bin_manifest, basic_lib_manifest, execs, project}; +use support::hamcrest::{assert_that, existing_file}; #[test] fn cargo_bench_simple() { diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 54d86894c..8bc8a71b9 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -4,13 +4,13 @@ use std::io::prelude::*; use cargo::util::paths::dylib_path_envvar; use cargo::util::{process, ProcessBuilder}; -use cargotest::{is_nightly, rustc_host, sleep_ms}; -use cargotest::support::paths::{root, CargoPathExt}; -use cargotest::support::ProjectBuilder; -use cargotest::support::{basic_bin_manifest, execs, main_file, project}; -use cargotest::support::registry::Package; -use cargotest::ChannelChanger; -use hamcrest::{assert_that, existing_dir, existing_file, is_not}; +use support::{is_nightly, rustc_host, sleep_ms}; +use support::paths::{root, CargoPathExt}; +use support::ProjectBuilder; +use support::{basic_bin_manifest, execs, main_file, project}; +use support::registry::Package; +use support::ChannelChanger; +use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; use tempfile; #[test] diff --git a/tests/testsuite/build_auth.rs b/tests/testsuite/build_auth.rs index 44659da5a..3c3450f19 100644 --- a/tests/testsuite/build_auth.rs +++ b/tests/testsuite/build_auth.rs @@ -6,9 +6,9 @@ use std::thread; use git2; use bufstream::BufStream; -use cargotest::support::paths; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::paths; +use support::{execs, project}; +use support::hamcrest::assert_that; // Test that HTTP auth is offered from `credential.helper` #[test] diff --git a/tests/testsuite/build_lib.rs b/tests/testsuite/build_lib.rs index 7b53630d8..949c4371d 100644 --- a/tests/testsuite/build_lib.rs +++ b/tests/testsuite/build_lib.rs @@ -1,5 +1,5 @@ -use cargotest::support::{basic_bin_manifest, execs, project, Project}; -use hamcrest::assert_that; +use support::{basic_bin_manifest, execs, project, Project}; +use support::hamcrest::assert_that; fn verbose_output_for_lib(p: &Project) -> String { format!( diff --git a/tests/testsuite/build_plan.rs b/tests/testsuite/build_plan.rs index 7b7a007c9..8e275c76e 100644 --- a/tests/testsuite/build_plan.rs +++ b/tests/testsuite/build_plan.rs @@ -1,6 +1,6 @@ -use cargotest::ChannelChanger; -use cargotest::support::{basic_bin_manifest, execs, main_file, project}; -use hamcrest::{assert_that, existing_file, is_not}; +use support::ChannelChanger; +use support::{basic_bin_manifest, execs, main_file, project}; +use support::hamcrest::{assert_that, existing_file, is_not}; #[test] fn cargo_build_plan_simple() { diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index ccbd293df..c27a1cfdf 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -7,11 +7,11 @@ use std::thread; use std::time::Duration; use cargo::util::paths::remove_dir_all; -use cargotest::{rustc_host, sleep_ms}; -use cargotest::support::{cross_compile, execs, project}; -use cargotest::support::paths::CargoPathExt; -use cargotest::support::registry::Package; -use hamcrest::{assert_that, existing_dir, existing_file}; +use support::{rustc_host, sleep_ms}; +use support::{cross_compile, execs, project}; +use support::paths::CargoPathExt; +use support::registry::Package; +use support::hamcrest::{assert_that, existing_dir, existing_file}; #[test] fn custom_build_script_failed() { diff --git a/tests/testsuite/build_script_env.rs b/tests/testsuite/build_script_env.rs index 9ab2da611..d9edb281f 100644 --- a/tests/testsuite/build_script_env.rs +++ b/tests/testsuite/build_script_env.rs @@ -1,8 +1,8 @@ use std::fs::File; -use cargotest::sleep_ms; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::sleep_ms; +use support::{execs, project}; +use support::hamcrest::assert_that; #[test] fn rerun_if_env_changes() { diff --git a/tests/testsuite/cargo_alias_config.rs b/tests/testsuite/cargo_alias_config.rs index 1d5d5f89c..6f5447a15 100644 --- a/tests/testsuite/cargo_alias_config.rs +++ b/tests/testsuite/cargo_alias_config.rs @@ -1,5 +1,5 @@ -use cargotest::support::{basic_bin_manifest, execs, project}; -use hamcrest::assert_that; +use support::{basic_bin_manifest, execs, project}; +use support::hamcrest::assert_that; #[test] fn alias_incorrect_config_type() { diff --git a/tests/testsuite/cargo_command.rs b/tests/testsuite/cargo_command.rs index 946a8e7b7..ac306e16c 100644 --- a/tests/testsuite/cargo_command.rs +++ b/tests/testsuite/cargo_command.rs @@ -5,11 +5,11 @@ use std::path::{Path, PathBuf}; use std::str; use cargo; -use cargotest::cargo_process; -use cargotest::support::paths::{self, CargoPathExt}; -use cargotest::support::registry::Package; -use cargotest::support::{basic_bin_manifest, cargo_exe, execs, project, Project}; -use hamcrest::{assert_that, existing_file}; +use support::cargo_process; +use support::paths::{self, CargoPathExt}; +use support::registry::Package; +use support::{basic_bin_manifest, cargo_exe, execs, project, Project}; +use support::hamcrest::{assert_that, existing_file}; #[cfg_attr(windows, allow(dead_code))] enum FakeKind<'a> { diff --git a/tests/testsuite/cargo_features.rs b/tests/testsuite/cargo_features.rs index b5df5c984..f79354eb6 100644 --- a/tests/testsuite/cargo_features.rs +++ b/tests/testsuite/cargo_features.rs @@ -1,6 +1,6 @@ -use cargotest::ChannelChanger; -use cargotest::support::{execs, project, publish}; -use hamcrest::assert_that; +use support::ChannelChanger; +use support::{execs, project, publish}; +use support::hamcrest::assert_that; #[test] fn feature_required() { diff --git a/tests/testsuite/cargotest/mod.rs b/tests/testsuite/cargotest/mod.rs deleted file mode 100644 index 171ac377f..000000000 --- a/tests/testsuite/cargotest/mod.rs +++ /dev/null @@ -1,179 +0,0 @@ -/* -# Introduction To `cargotest` - -Cargo has a wide variety of integration tests that execute the `cargo` binary -and verify its behavior. The `cargotest` module contains many helpers to make -this process easy. - -The general form of a test involves creating a "project", running cargo, and -checking the result. Projects are created with the `ProjectBuilder` where you -specify some files to create. The general form looks like this: - -``` -let p = project() - .file("Cargo.toml", &basic_bin_manifest("foo")) - .file("src/main.rs", r#"fn main() { println!("hi!"); }"#) - .build(); -``` - -To run cargo, call the `cargo` method and use the `hamcrest` matchers to check -the output. - -``` -assert_that( - p.cargo("run --bin foo"), - execs() - .with_status(0) - .with_stderr( - "\ -[COMPILING] foo [..] -[FINISHED] [..] -[RUNNING] `target[/]debug[/]foo` -", - ) - .with_stdout("hi!"), -); -``` - -The project creates a mini sandbox under the "cargo integration test" -directory with each test getting a separate directory such as -`/path/to/cargo/target/cit/t123/`. Each project appears as a separate -directory. There is also an empty `home` directory created that will be used -as a home directory instead of your normal home directory. - -See `cargotest::support::lines_match` for an explanation of the string pattern -matching. - -See the `hamcrest` module for other matchers like -`is_not(existing_file(path))`. This is not the actual hamcrest library, but -instead a lightweight subset of matchers that are used in cargo tests. - -Browse the `pub` functions in the `cargotest` module for a variety of other -helpful utilities. - -## Testing Nightly Features - -If you are testing a Cargo feature that only works on "nightly" cargo, then -you need to call `masquerade_as_nightly_cargo` on the process builder like -this: - -``` -p.cargo("build").masquerade_as_nightly_cargo() -``` - -If you are testing a feature that only works on *nightly rustc* (such as -benchmarks), then you should exit the test if it is not running with nightly -rust, like this: - -``` -if !is_nightly() { - return; -} -``` - -## Platform-specific Notes - -When checking output, be sure to use `[/]` when checking paths to -automatically support backslashes on Windows. - -Be careful when executing binaries on Windows. You should not rename, delete, -or overwrite a binary immediately after running it. Under some conditions -Windows will fail with errors like "directory not empty" or "failed to remove" -or "access is denied". - -*/ - -use std::ffi::OsStr; -use std::time::Duration; - -use cargo::util::Rustc; -use cargo; -use std::path::{Path, PathBuf}; - -#[macro_use] -pub mod support; - -pub mod install; - -thread_local!( -pub static RUSTC: Rustc = Rustc::new( - PathBuf::from("rustc"), - None, - Path::new("should be path to rustup rustc, but we don't care in tests"), - None, -).unwrap() -); - -/// The rustc host such as `x86_64-unknown-linux-gnu`. -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 { - _process(t.as_ref()) -} - -fn _process(t: &OsStr) -> cargo::util::ProcessBuilder { - let mut p = cargo::util::process(t); - p.cwd(&support::paths::root()) - .env_remove("CARGO_HOME") - .env("HOME", support::paths::home()) - .env("CARGO_HOME", support::paths::home().join(".cargo")) - .env("__CARGO_TEST_ROOT", support::paths::root()) - - // Force cargo to think it's on the stable channel for all tests, this - // should hopefully not surprise us as we add cargo features over time and - // cargo rides the trains. - .env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "stable") - - // For now disable incremental by default as support hasn't ridden to the - // stable channel yet. Once incremental support hits the stable compiler we - // can switch this to one and then fix the tests. - .env("CARGO_INCREMENTAL", "0") - - // This env var can switch the git backend from libgit2 to git2-curl, which - // can tweak error messages and cause some tests to fail, so let's forcibly - // remove it. - .env_remove("CARGO_HTTP_CHECK_REVOKE") - - .env_remove("__CARGO_DEFAULT_LIB_METADATA") - .env_remove("RUSTC") - .env_remove("RUSTDOC") - .env_remove("RUSTC_WRAPPER") - .env_remove("RUSTFLAGS") - .env_remove("XDG_CONFIG_HOME") // see #2345 - .env("GIT_CONFIG_NOSYSTEM", "1") // keep trying to sandbox ourselves - .env_remove("EMAIL") - .env_remove("MFLAGS") - .env_remove("MAKEFLAGS") - .env_remove("CARGO_MAKEFLAGS") - .env_remove("GIT_AUTHOR_NAME") - .env_remove("GIT_AUTHOR_EMAIL") - .env_remove("GIT_COMMITTER_NAME") - .env_remove("GIT_COMMITTER_EMAIL") - .env_remove("CARGO_TARGET_DIR") // we assume 'target' - .env_remove("MSYSTEM"); // assume cmd.exe everywhere on windows - return p; -} - -pub trait ChannelChanger: Sized { - fn masquerade_as_nightly_cargo(&mut self) -> &mut Self; -} - -impl ChannelChanger for cargo::util::ProcessBuilder { - fn masquerade_as_nightly_cargo(&mut self) -> &mut Self { - self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly") - } -} - -pub fn cargo_process() -> cargo::util::ProcessBuilder { - process(&support::cargo_exe()) -} - -pub fn sleep_ms(ms: u64) { - ::std::thread::sleep(Duration::from_millis(ms)); -} diff --git a/tests/testsuite/cfg.rs b/tests/testsuite/cfg.rs index 4a93df514..ef1c321b7 100644 --- a/tests/testsuite/cfg.rs +++ b/tests/testsuite/cfg.rs @@ -2,10 +2,10 @@ use std::str::FromStr; use std::fmt; use cargo::util::{Cfg, CfgExpr}; -use cargotest::rustc_host; -use cargotest::support::registry::Package; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::rustc_host; +use support::registry::Package; +use support::{execs, project}; +use support::hamcrest::assert_that; macro_rules! c { ($a:ident) => ( diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index f984ac640..81f8fa715 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -1,10 +1,10 @@ -use cargotest::install::exe; -use cargotest::is_nightly; -use cargotest::support::paths::CargoPathExt; -use cargotest::support::registry::Package; -use cargotest::support::{execs, project}; +use support::install::exe; +use support::is_nightly; +use support::paths::CargoPathExt; +use support::registry::Package; +use support::{execs, project}; use glob::glob; -use hamcrest::{assert_that, existing_file, is_not}; +use support::hamcrest::{assert_that, existing_file, is_not}; const SIMPLE_MANIFEST: &str = r#" [package] diff --git a/tests/testsuite/clean.rs b/tests/testsuite/clean.rs index a761a8f05..8ca4d6738 100644 --- a/tests/testsuite/clean.rs +++ b/tests/testsuite/clean.rs @@ -1,8 +1,8 @@ use std::env; -use cargotest::support::{basic_bin_manifest, execs, git, main_file, project}; -use cargotest::support::registry::Package; -use hamcrest::{assert_that, existing_dir, existing_file, is_not}; +use support::{basic_bin_manifest, execs, git, main_file, project}; +use support::registry::Package; +use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; #[test] fn cargo_clean_simple() { diff --git a/tests/testsuite/concurrent.rs b/tests/testsuite/concurrent.rs index b01630efb..dbc3249a9 100644 --- a/tests/testsuite/concurrent.rs +++ b/tests/testsuite/concurrent.rs @@ -8,12 +8,12 @@ use std::sync::mpsc::channel; use std::time::Duration; use git2; -use cargotest; -use cargotest::install::{cargo_home, has_installed_exe}; -use cargotest::support::git; -use cargotest::support::registry::Package; -use cargotest::support::{execs, project}; -use hamcrest::{assert_that, existing_file}; +use support; +use support::install::{cargo_home, has_installed_exe}; +use support::git; +use support::registry::Package; +use support::{execs, project}; +use support::hamcrest::{assert_that, existing_file}; fn pkg(name: &str, vers: &str) { Package::new(name, vers) @@ -72,11 +72,11 @@ fn concurrent_installs() { pkg("foo", "0.0.1"); pkg("bar", "0.0.1"); - let mut a = cargotest::cargo_process() + let mut a = support::cargo_process() .arg("install") .arg("foo") .build_command(); - let mut b = cargotest::cargo_process() + let mut b = support::cargo_process() .arg("install") .arg("bar") .build_command(); diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index 1ca4f139d..d1b42e153 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -2,8 +2,8 @@ use cargo::core::{Shell, enable_nightly_features}; use cargo::util::config::{self, Config}; use cargo::util::toml::{self, VecStringOrBool as VSOB}; use cargo::CargoError; -use cargotest::support::{execs, lines_match, paths, project}; -use hamcrest::assert_that; +use support::{execs, lines_match, paths, project}; +use support::hamcrest::assert_that; use std::collections; use std::fs; diff --git a/tests/testsuite/corrupt_git.rs b/tests/testsuite/corrupt_git.rs index 1786e0966..465165e71 100644 --- a/tests/testsuite/corrupt_git.rs +++ b/tests/testsuite/corrupt_git.rs @@ -2,9 +2,9 @@ use std::fs; use std::path::{Path, PathBuf}; use cargo::util::paths as cargopaths; -use cargotest::support::paths; -use cargotest::support::{execs, git, project}; -use hamcrest::assert_that; +use support::paths; +use support::{execs, git, project}; +use support::hamcrest::assert_that; #[test] fn deleting_database_files() { diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index 5f4d61571..e60e45c40 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -1,7 +1,7 @@ use cargo::util::process; -use cargotest::{is_nightly, rustc_host}; -use cargotest::support::{basic_bin_manifest, cross_compile, execs, project}; -use hamcrest::{assert_that, existing_file}; +use support::{is_nightly, rustc_host}; +use support::{basic_bin_manifest, cross_compile, execs, project}; +use support::hamcrest::{assert_that, existing_file}; #[test] fn simple_cross() { diff --git a/tests/testsuite/cross_publish.rs b/tests/testsuite/cross_publish.rs index f3eeb8251..54b7bda6d 100644 --- a/tests/testsuite/cross_publish.rs +++ b/tests/testsuite/cross_publish.rs @@ -2,8 +2,8 @@ use std::fs::File; use std::path::PathBuf; use std::io::prelude::*; -use cargotest::support::{cross_compile, execs, project, publish}; -use hamcrest::{assert_that, contains}; +use support::{cross_compile, execs, project, publish}; +use support::hamcrest::{assert_that, contains}; use flate2::read::GzDecoder; use tar::Archive; diff --git a/tests/testsuite/custom_target.rs b/tests/testsuite/custom_target.rs index b65b34be3..b67bcbe24 100644 --- a/tests/testsuite/custom_target.rs +++ b/tests/testsuite/custom_target.rs @@ -1,6 +1,6 @@ -use cargotest::is_nightly; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::is_nightly; +use support::{execs, project}; +use support::hamcrest::assert_that; #[test] fn custom_target_minimal() { diff --git a/tests/testsuite/death.rs b/tests/testsuite/death.rs index 4b833860c..b8eb13a9e 100644 --- a/tests/testsuite/death.rs +++ b/tests/testsuite/death.rs @@ -5,7 +5,7 @@ use std::process::{Child, Stdio}; use std::thread; use std::time::Duration; -use cargotest::support::project; +use support::project; #[cfg(unix)] fn enabled() -> bool { diff --git a/tests/testsuite/dep_info.rs b/tests/testsuite/dep_info.rs index d06fe493b..2cecbc66b 100644 --- a/tests/testsuite/dep_info.rs +++ b/tests/testsuite/dep_info.rs @@ -1,6 +1,6 @@ -use cargotest::support::{basic_bin_manifest, execs, main_file, project}; +use support::{basic_bin_manifest, execs, main_file, project}; use filetime::FileTime; -use hamcrest::{assert_that, existing_file}; +use support::hamcrest::{assert_that, existing_file}; #[test] fn build_dep_info() { diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs index c6c147aee..5ca5a0c62 100644 --- a/tests/testsuite/directory.rs +++ b/tests/testsuite/directory.rs @@ -4,12 +4,12 @@ use std::fs::{self, File}; use std::io::prelude::*; use std::str; -use cargotest::cargo_process; -use cargotest::support::git; -use cargotest::support::paths; -use cargotest::support::registry::{cksum, Package}; -use cargotest::support::{execs, project, ProjectBuilder}; -use hamcrest::assert_that; +use support::cargo_process; +use support::git; +use support::paths; +use support::registry::{cksum, Package}; +use support::{execs, project, ProjectBuilder}; +use support::hamcrest::assert_that; fn setup() { let root = paths::root(); diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index df700a57b..cc68f5ff3 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -1,13 +1,13 @@ -use cargotest; +use support; use std::str; use std::fs::{self, File}; use std::io::Read; -use cargotest::{is_nightly, rustc_host, ChannelChanger}; -use cargotest::support::{basic_lib_manifest, execs, git, project, path2url}; -use cargotest::support::paths::CargoPathExt; -use cargotest::support::registry::Package; -use hamcrest::{assert_that, existing_dir, existing_file, is_not}; +use support::{is_nightly, rustc_host, ChannelChanger}; +use support::{basic_lib_manifest, execs, git, project, path2url}; +use support::paths::CargoPathExt; +use support::registry::Package; +use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; use cargo::util::ProcessError; use glob::glob; @@ -1216,7 +1216,7 @@ fn document_only_lib() { #[test] fn plugins_no_use_target() { - if !cargotest::is_nightly() { + if !support::is_nightly() { return; } let p = project() @@ -1591,7 +1591,7 @@ fn doc_workspace_open_binary_and_library() { #[test] fn doc_edition() { - if !cargotest::is_nightly() { + if !support::is_nightly() { // Stable rustdoc won't have the edition option. Remove this once it // is stabilized. return; diff --git a/tests/testsuite/features.rs b/tests/testsuite/features.rs index e170b1e1a..317717b9a 100644 --- a/tests/testsuite/features.rs +++ b/tests/testsuite/features.rs @@ -1,11 +1,11 @@ use std::fs::File; use std::io::prelude::*; -use cargotest::support::paths::CargoPathExt; -use cargotest::support::{execs, project}; -use cargotest::ChannelChanger; -use hamcrest::assert_that; -use cargotest::support::registry::Package; +use support::paths::CargoPathExt; +use support::{execs, project}; +use support::ChannelChanger; +use support::hamcrest::assert_that; +use support::registry::Package; #[test] fn invalid1() { diff --git a/tests/testsuite/fetch.rs b/tests/testsuite/fetch.rs index 4dc23f383..b1d392c62 100644 --- a/tests/testsuite/fetch.rs +++ b/tests/testsuite/fetch.rs @@ -1,7 +1,7 @@ -use cargotest::rustc_host; -use cargotest::support::registry::Package; -use cargotest::support::{cross_compile, execs, project}; -use hamcrest::assert_that; +use support::rustc_host; +use support::registry::Package; +use support::{cross_compile, execs, project}; +use support::hamcrest::assert_that; #[test] fn no_deps() { diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index 9739a403f..88c865868 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -1,8 +1,8 @@ -use cargotest::support::git; -use cargotest::support::{execs, project}; -use cargotest::{is_nightly, ChannelChanger}; +use support::git; +use support::{execs, project}; +use support::{is_nightly, ChannelChanger}; use git2; -use hamcrest::assert_that; +use support::hamcrest::assert_that; #[test] fn do_not_fix_broken_builds() { diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index e4da1c6ac..02946b086 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -1,11 +1,11 @@ use std::fs::{self, File}; use std::io::prelude::*; -use cargotest::sleep_ms; -use cargotest::support::paths::CargoPathExt; -use cargotest::support::registry::Package; -use cargotest::support::{execs, path2url, project}; -use hamcrest::{assert_that, existing_file}; +use support::sleep_ms; +use support::paths::CargoPathExt; +use support::registry::Package; +use support::{execs, path2url, project}; +use support::hamcrest::{assert_that, existing_file}; #[test] fn modifying_and_moving() { diff --git a/tests/testsuite/generate_lockfile.rs b/tests/testsuite/generate_lockfile.rs index 16d81c990..4c540a8b4 100644 --- a/tests/testsuite/generate_lockfile.rs +++ b/tests/testsuite/generate_lockfile.rs @@ -1,10 +1,10 @@ use std::fs::{self, File}; use std::io::prelude::*; -use cargotest::support::registry::Package; -use cargotest::support::{execs, paths, project, ProjectBuilder}; -use cargotest::ChannelChanger; -use hamcrest::{assert_that, existing_file, is_not}; +use support::registry::Package; +use support::{execs, paths, project, ProjectBuilder}; +use support::ChannelChanger; +use support::hamcrest::{assert_that, existing_file, is_not}; #[test] fn adding_and_removing_packages() { diff --git a/tests/testsuite/git.rs b/tests/testsuite/git.rs index 9efb92c4b..baf19ef63 100644 --- a/tests/testsuite/git.rs +++ b/tests/testsuite/git.rs @@ -8,11 +8,11 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::thread; use cargo::util::process; -use cargotest::sleep_ms; -use cargotest::support::paths::{self, CargoPathExt}; -use cargotest::support::{execs, git, main_file, project, path2url}; -use cargotest::ChannelChanger; -use hamcrest::{assert_that, existing_file}; +use support::sleep_ms; +use support::paths::{self, CargoPathExt}; +use support::{execs, git, main_file, project, path2url}; +use support::ChannelChanger; +use support::hamcrest::{assert_that, existing_file}; #[test] fn cargo_compile_simple_git_dep() { diff --git a/tests/testsuite/init.rs b/tests/testsuite/init.rs index 48d1f65c8..cc4101000 100644 --- a/tests/testsuite/init.rs +++ b/tests/testsuite/init.rs @@ -1,15 +1,15 @@ -use cargotest; +use support; use std::fs::{self, File}; use std::io::prelude::*; use std::env; use cargo::util::ProcessBuilder; -use cargotest::support::{cargo_exe, execs, paths}; -use hamcrest::{assert_that, existing_dir, existing_file, is_not}; +use support::{cargo_exe, execs, paths}; +use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; use tempfile; fn cargo_process(s: &str) -> ProcessBuilder { - let mut p = cargotest::process(&cargo_exe()); + let mut p = support::process(&cargo_exe()); p.arg(s).cwd(&paths::root()).env("HOME", &paths::home()); p } diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 304da160f..c11154cb2 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -1,20 +1,20 @@ -use cargotest; +use support; use std::fs::{self, File, OpenOptions}; use std::io::prelude::*; use cargo::util::ProcessBuilder; -use cargotest::install::{cargo_home, has_installed_exe}; -use cargotest::support::cross_compile; -use cargotest::support::git; -use cargotest::support::paths; -use cargotest::support::registry::Package; -use cargotest::support::{execs, project}; -use cargotest::ChannelChanger; +use support::install::{cargo_home, has_installed_exe}; +use support::cross_compile; +use support::git; +use support::paths; +use support::registry::Package; +use support::{execs, project}; +use support::ChannelChanger; use git2; -use hamcrest::{assert_that, existing_dir, is_not}; +use support::hamcrest::{assert_that, existing_dir, is_not}; fn cargo_process(s: &str) -> ProcessBuilder { - let mut p = cargotest::cargo_process(); + let mut p = support::cargo_process(); p.arg(s); p } @@ -1050,7 +1050,7 @@ warning: To build the current package use `cargo build`, to install the current #[test] fn installs_from_cwd_with_2018_warnings() { - if !cargotest::is_nightly() { + if !support::is_nightly() { // Stable rust won't have the edition option. Remove this once it // is stabilized. return; @@ -1343,7 +1343,7 @@ fn install_target_native() { cargo_process("install") .arg("foo") .arg("--target") - .arg(cargotest::rustc_host()), + .arg(support::rustc_host()), execs() .with_status(0), ); diff --git a/tests/testsuite/jobserver.rs b/tests/testsuite/jobserver.rs index 618a7b970..d2ffaebd1 100644 --- a/tests/testsuite/jobserver.rs +++ b/tests/testsuite/jobserver.rs @@ -2,8 +2,8 @@ use std::net::TcpListener; use std::thread; use std::process::Command; -use cargotest::support::{cargo_exe, execs, project}; -use hamcrest::assert_that; +use support::{cargo_exe, execs, project}; +use support::hamcrest::assert_that; #[test] fn jobserver_exists() { diff --git a/tests/testsuite/local_registry.rs b/tests/testsuite/local_registry.rs index a90f3d9aa..66f6ca18f 100644 --- a/tests/testsuite/local_registry.rs +++ b/tests/testsuite/local_registry.rs @@ -1,10 +1,10 @@ use std::fs::{self, File}; use std::io::prelude::*; -use cargotest::support::paths::{self, CargoPathExt}; -use cargotest::support::registry::Package; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::paths::{self, CargoPathExt}; +use support::registry::Package; +use support::{execs, project}; +use support::hamcrest::assert_that; fn setup() { let root = paths::root(); diff --git a/tests/testsuite/lockfile_compat.rs b/tests/testsuite/lockfile_compat.rs index f931ee277..c31117540 100644 --- a/tests/testsuite/lockfile_compat.rs +++ b/tests/testsuite/lockfile_compat.rs @@ -1,7 +1,7 @@ -use cargotest::support::git; -use cargotest::support::registry::Package; -use cargotest::support::{execs, lines_match, project}; -use hamcrest::assert_that; +use support::git; +use support::registry::Package; +use support::{execs, lines_match, project}; +use support::hamcrest::assert_that; #[test] fn oldest_lockfile_still_works() { diff --git a/tests/testsuite/login.rs b/tests/testsuite/login.rs index 7ae9f9705..4e728d393 100644 --- a/tests/testsuite/login.rs +++ b/tests/testsuite/login.rs @@ -2,13 +2,13 @@ use std::io::prelude::*; use std::fs::{self, File}; use toml; -use cargotest::{cargo_process, ChannelChanger}; -use cargotest::support::execs; -use cargotest::support::registry::registry; -use cargotest::install::cargo_home; +use support::{cargo_process, ChannelChanger}; +use support::execs; +use support::registry::registry; +use support::install::cargo_home; use cargo::util::config::Config; use cargo::core::Shell; -use hamcrest::{assert_that, existing_file, is_not}; +use support::hamcrest::{assert_that, existing_file, is_not}; const TOKEN: &str = "test-token"; const ORIGINAL_TOKEN: &str = "api-token"; diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 22747b65d..e88119b29 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -20,8 +20,7 @@ extern crate url; extern crate winapi; #[macro_use] -mod cargotest; -mod hamcrest; +mod support; mod alt_registry; mod bad_config; diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 0fb272ba2..8836d35a7 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -1,6 +1,6 @@ -use cargotest::support::registry::Package; -use cargotest::support::{basic_bin_manifest, basic_lib_manifest, execs, main_file, project}; -use hamcrest::assert_that; +use support::registry::Package; +use support::{basic_bin_manifest, basic_lib_manifest, execs, main_file, project}; +use support::hamcrest::assert_that; #[test] fn cargo_metadata_simple() { diff --git a/tests/testsuite/net_config.rs b/tests/testsuite/net_config.rs index 534ee386b..78ec624da 100644 --- a/tests/testsuite/net_config.rs +++ b/tests/testsuite/net_config.rs @@ -1,5 +1,5 @@ -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::{execs, project}; +use support::hamcrest::assert_that; #[test] fn net_retry_loads_from_config() { diff --git a/tests/testsuite/new.rs b/tests/testsuite/new.rs index 1fab114bb..847dde9f3 100644 --- a/tests/testsuite/new.rs +++ b/tests/testsuite/new.rs @@ -2,15 +2,15 @@ use std::fs::{self, File}; use std::io::prelude::*; use std::env; -use cargotest; +use support; use cargo::util::ProcessBuilder; -use cargotest::process; -use cargotest::support::{execs, paths}; -use hamcrest::{assert_that, existing_dir, existing_file, is_not}; +use support::process; +use support::{execs, paths}; +use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; use tempfile; fn cargo_process(s: &str) -> ProcessBuilder { - let mut p = cargotest::cargo_process(); + let mut p = support::cargo_process(); p.arg(s); p } diff --git a/tests/testsuite/out_dir.rs b/tests/testsuite/out_dir.rs index 5184dee02..6f8e42c64 100644 --- a/tests/testsuite/out_dir.rs +++ b/tests/testsuite/out_dir.rs @@ -2,10 +2,10 @@ use std::path::Path; use std::fs::{self, File}; use std::env; -use hamcrest::assert_that; +use support::hamcrest::assert_that; -use cargotest::{process, sleep_ms, ChannelChanger}; -use cargotest::support::{execs, project}; +use support::{process, sleep_ms, ChannelChanger}; +use support::{execs, project}; #[test] fn binary_with_debug() { diff --git a/tests/testsuite/overrides.rs b/tests/testsuite/overrides.rs index 48665b43b..00df0b62d 100644 --- a/tests/testsuite/overrides.rs +++ b/tests/testsuite/overrides.rs @@ -1,8 +1,8 @@ -use cargotest::support::git; -use cargotest::support::paths; -use cargotest::support::registry::Package; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::git; +use support::paths; +use support::registry::Package; +use support::{execs, project}; +use support::hamcrest::assert_that; #[test] fn override_simple() { diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 1efd917a9..6eb1e0f15 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -4,11 +4,11 @@ use std::io::prelude::*; use std::path::{Path, PathBuf}; use git2; -use cargotest::{cargo_process, process, sleep_ms, ChannelChanger}; -use cargotest::support::{cargo_exe, execs, git, paths, project, registry, path2url}; -use cargotest::support::registry::Package; +use support::{cargo_process, process, sleep_ms, ChannelChanger}; +use support::{cargo_exe, execs, git, paths, project, registry, path2url}; +use support::registry::Package; use flate2::read::GzDecoder; -use hamcrest::{assert_that, contains, existing_file}; +use support::hamcrest::{assert_that, contains, existing_file}; use tar::Archive; #[test] diff --git a/tests/testsuite/patch.rs b/tests/testsuite/patch.rs index 337613ed7..3d2afff45 100644 --- a/tests/testsuite/patch.rs +++ b/tests/testsuite/patch.rs @@ -2,11 +2,11 @@ use std::fs::{self, File}; use std::io::{Read, Write}; use toml; -use cargotest::support::git; -use cargotest::support::paths; -use cargotest::support::registry::Package; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::git; +use support::paths; +use support::registry::Package; +use support::{execs, project}; +use support::hamcrest::assert_that; #[test] fn replace() { diff --git a/tests/testsuite/path.rs b/tests/testsuite/path.rs index 7e45a8050..590947208 100644 --- a/tests/testsuite/path.rs +++ b/tests/testsuite/path.rs @@ -2,11 +2,11 @@ use std::fs::{self, File}; use std::io::prelude::*; use cargo::util::process; -use cargotest::sleep_ms; -use cargotest::support::paths::{self, CargoPathExt}; -use cargotest::support::registry::Package; -use cargotest::support::{execs, main_file, project}; -use hamcrest::{assert_that, existing_file, is_not}; +use support::sleep_ms; +use support::paths::{self, CargoPathExt}; +use support::registry::Package; +use support::{execs, main_file, project}; +use support::hamcrest::{assert_that, existing_file, is_not}; #[test] #[cfg(not(windows))] // I have no idea why this is failing spuriously on diff --git a/tests/testsuite/plugins.rs b/tests/testsuite/plugins.rs index 4daab6136..6f903054e 100644 --- a/tests/testsuite/plugins.rs +++ b/tests/testsuite/plugins.rs @@ -1,9 +1,9 @@ use std::fs; use std::env; -use cargotest::{is_nightly, rustc_host}; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::{is_nightly, rustc_host}; +use support::{execs, project}; +use support::hamcrest::assert_that; #[test] fn plugin_to_the_max() { diff --git a/tests/testsuite/proc_macro.rs b/tests/testsuite/proc_macro.rs index 771665897..650f0f42c 100644 --- a/tests/testsuite/proc_macro.rs +++ b/tests/testsuite/proc_macro.rs @@ -1,6 +1,6 @@ -use cargotest::is_nightly; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::is_nightly; +use support::{execs, project}; +use support::hamcrest::assert_that; #[test] fn probe_cfg_before_crate_type_discovery() { diff --git a/tests/testsuite/profile_config.rs b/tests/testsuite/profile_config.rs index 3a7052510..343dafd79 100644 --- a/tests/testsuite/profile_config.rs +++ b/tests/testsuite/profile_config.rs @@ -1,6 +1,6 @@ -use cargotest::support::{basic_lib_manifest, execs, paths, project}; -use cargotest::ChannelChanger; -use hamcrest::assert_that; +use support::{basic_lib_manifest, execs, paths, project}; +use support::ChannelChanger; +use support::hamcrest::assert_that; #[test] fn profile_config_gated() { diff --git a/tests/testsuite/profile_overrides.rs b/tests/testsuite/profile_overrides.rs index ebd7c295c..bde033da9 100644 --- a/tests/testsuite/profile_overrides.rs +++ b/tests/testsuite/profile_overrides.rs @@ -1,6 +1,6 @@ -use cargotest::support::{basic_lib_manifest, execs, project}; -use cargotest::ChannelChanger; -use hamcrest::assert_that; +use support::{basic_lib_manifest, execs, project}; +use support::ChannelChanger; +use support::hamcrest::assert_that; #[test] fn profile_override_gated() { diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index 971aa29b8..5c954cba7 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -1,6 +1,6 @@ -use cargotest::is_nightly; -use cargotest::support::{execs, project, Project}; -use hamcrest::assert_that; +use support::is_nightly; +use support::{execs, project, Project}; +use support::hamcrest::assert_that; // These tests try to exercise exactly which profiles are selected for every // target. diff --git a/tests/testsuite/profiles.rs b/tests/testsuite/profiles.rs index 2207f0461..bbfe4101d 100644 --- a/tests/testsuite/profiles.rs +++ b/tests/testsuite/profiles.rs @@ -1,8 +1,8 @@ use std::env; -use cargotest::is_nightly; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::is_nightly; +use support::{execs, project}; +use support::hamcrest::assert_that; #[test] fn profile_overrides() { diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index 0d4b9bee9..a55b84cbc 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -2,12 +2,12 @@ use std::io::prelude::*; use std::fs::{self, File}; use std::io::SeekFrom; -use cargotest::ChannelChanger; -use cargotest::support::git::repo; -use cargotest::support::paths; -use cargotest::support::{execs, project, publish}; +use support::ChannelChanger; +use support::git::repo; +use support::paths; +use support::{execs, project, publish}; use flate2::read::GzDecoder; -use hamcrest::assert_that; +use support::hamcrest::assert_that; use tar::Archive; #[test] diff --git a/tests/testsuite/read_manifest.rs b/tests/testsuite/read_manifest.rs index 95add862a..e8ef37000 100644 --- a/tests/testsuite/read_manifest.rs +++ b/tests/testsuite/read_manifest.rs @@ -1,5 +1,5 @@ -use cargotest::support::{basic_bin_manifest, execs, main_file, project}; -use hamcrest::assert_that; +use support::{basic_bin_manifest, execs, main_file, project}; +use support::hamcrest::assert_that; static MANIFEST_OUTPUT: &'static str = r#" { diff --git a/tests/testsuite/registry.rs b/tests/testsuite/registry.rs index 8c1c81438..d9f88107c 100644 --- a/tests/testsuite/registry.rs +++ b/tests/testsuite/registry.rs @@ -3,12 +3,12 @@ use std::io::prelude::*; use std::path::PathBuf; use cargo::util::paths::remove_dir_all; -use cargotest::cargo_process; -use cargotest::support::git; -use cargotest::support::paths::{self, CargoPathExt}; -use cargotest::support::registry::{self, Package}; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::cargo_process; +use support::git; +use support::paths::{self, CargoPathExt}; +use support::registry::{self, Package}; +use support::{execs, project}; +use support::hamcrest::assert_that; use url::Url; fn registry_path() -> PathBuf { @@ -762,7 +762,7 @@ fn update_lockfile() { #[test] fn update_offline() { - use cargotest::ChannelChanger; + use support::ChannelChanger; let p = project() .file( "Cargo.toml", diff --git a/tests/testsuite/rename_deps.rs b/tests/testsuite/rename_deps.rs index d495522f5..84567faaf 100644 --- a/tests/testsuite/rename_deps.rs +++ b/tests/testsuite/rename_deps.rs @@ -1,9 +1,9 @@ -use cargotest::ChannelChanger; -use cargotest::support::git; -use cargotest::support::paths; -use cargotest::support::registry::Package; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::ChannelChanger; +use support::git; +use support::paths; +use support::registry::Package; +use support::{execs, project}; +use support::hamcrest::assert_that; #[test] fn gated() { diff --git a/tests/testsuite/required_features.rs b/tests/testsuite/required_features.rs index 46c036c41..25b4cd331 100644 --- a/tests/testsuite/required_features.rs +++ b/tests/testsuite/required_features.rs @@ -1,7 +1,7 @@ -use cargotest::is_nightly; -use cargotest::install::{cargo_home, has_installed_exe}; -use cargotest::support::{execs, project}; -use hamcrest::{assert_that, existing_file, is_not}; +use support::is_nightly; +use support::install::{cargo_home, has_installed_exe}; +use support::{execs, project}; +use support::hamcrest::{assert_that, existing_file, is_not}; #[test] fn build_bin_default_features() { diff --git a/tests/testsuite/resolve.rs b/tests/testsuite/resolve.rs index ecf6349cf..a658edfa1 100644 --- a/tests/testsuite/resolve.rs +++ b/tests/testsuite/resolve.rs @@ -1,6 +1,6 @@ use std::collections::{BTreeMap, HashSet}; -use hamcrest::{assert_that, contains, is_not}; +use support::hamcrest::{assert_that, contains, is_not}; use cargo::core::source::{GitReference, SourceId}; use cargo::core::dependency::Kind::{self, Development}; @@ -8,9 +8,9 @@ use cargo::core::{Dependency, PackageId, Registry, Summary, enable_nightly_featu use cargo::util::{CargoResult, Config, ToUrl}; use cargo::core::resolver::{self, Method}; -use cargotest::ChannelChanger; -use cargotest::support::{execs, project}; -use cargotest::support::registry::Package; +use support::ChannelChanger; +use support::{execs, project}; +use support::registry::Package; fn resolve( pkg: &PackageId, diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index bd99175f9..51519e589 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -1,7 +1,7 @@ use cargo::util::paths::dylib_path_envvar; -use cargotest::{self, ChannelChanger}; -use cargotest::support::{execs, project, Project, path2url}; -use hamcrest::{assert_that, existing_file}; +use support::{self, ChannelChanger}; +use support::{execs, project, Project, path2url}; +use support::hamcrest::{assert_that, existing_file}; #[test] fn simple() { @@ -596,7 +596,7 @@ fn autodiscover_examples_project(rust_edition: &str, autoexamples: Option) #[test] fn run_example_autodiscover_2015() { - if !cargotest::is_nightly() { + if !support::is_nightly() { return; } @@ -631,7 +631,7 @@ error: no example target named `a` #[test] fn run_example_autodiscover_2015_with_autoexamples_enabled() { - if !cargotest::is_nightly() { + if !support::is_nightly() { return; } @@ -656,7 +656,7 @@ fn run_example_autodiscover_2015_with_autoexamples_enabled() { #[test] fn run_example_autodiscover_2015_with_autoexamples_disabled() { - if !cargotest::is_nightly() { + if !support::is_nightly() { return; } @@ -674,7 +674,7 @@ fn run_example_autodiscover_2015_with_autoexamples_disabled() { #[test] fn run_example_autodiscover_2018() { - if !cargotest::is_nightly() { + if !support::is_nightly() { return; } diff --git a/tests/testsuite/rustc.rs b/tests/testsuite/rustc.rs index 5c4658f2d..09ea5519a 100644 --- a/tests/testsuite/rustc.rs +++ b/tests/testsuite/rustc.rs @@ -1,5 +1,5 @@ -use cargotest::support::{basic_bin_manifest, basic_lib_manifest, execs, project}; -use hamcrest::assert_that; +use support::{basic_bin_manifest, basic_lib_manifest, execs, project}; +use support::hamcrest::assert_that; const CARGO_RUSTC_ERROR: &'static str = "[ERROR] extra arguments to `rustc` can only be passed to one target, consider filtering diff --git a/tests/testsuite/rustc_info_cache.rs b/tests/testsuite/rustc_info_cache.rs index b68947a11..ba04370e5 100644 --- a/tests/testsuite/rustc_info_cache.rs +++ b/tests/testsuite/rustc_info_cache.rs @@ -1,6 +1,6 @@ -use cargotest::support::{execs, project}; -use cargotest::support::paths::CargoPathExt; -use hamcrest::assert_that; +use support::{execs, project}; +use support::paths::CargoPathExt; +use support::hamcrest::assert_that; use std::env; #[test] diff --git a/tests/testsuite/rustdoc.rs b/tests/testsuite/rustdoc.rs index 8dc595797..e84d849a8 100644 --- a/tests/testsuite/rustdoc.rs +++ b/tests/testsuite/rustdoc.rs @@ -1,5 +1,5 @@ -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::{execs, project}; +use support::hamcrest::assert_that; #[test] fn rustdoc_simple() { diff --git a/tests/testsuite/rustdocflags.rs b/tests/testsuite/rustdocflags.rs index e0d2a34ed..77abdaf1a 100644 --- a/tests/testsuite/rustdocflags.rs +++ b/tests/testsuite/rustdocflags.rs @@ -1,5 +1,5 @@ -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::{execs, project}; +use support::hamcrest::assert_that; #[test] fn parses_env() { diff --git a/tests/testsuite/rustflags.rs b/tests/testsuite/rustflags.rs index ae9e1d7ff..26231fa7d 100644 --- a/tests/testsuite/rustflags.rs +++ b/tests/testsuite/rustflags.rs @@ -1,9 +1,9 @@ use std::io::Write; use std::fs::{self, File}; -use cargotest::rustc_host; -use cargotest::support::{execs, paths, project, project_in_home}; -use hamcrest::assert_that; +use support::rustc_host; +use support::{execs, paths, project, project_in_home}; +use support::hamcrest::assert_that; #[test] fn env_rustflags_normal_source() { diff --git a/tests/testsuite/search.rs b/tests/testsuite/search.rs index a0904da28..0889f7e71 100644 --- a/tests/testsuite/search.rs +++ b/tests/testsuite/search.rs @@ -3,11 +3,11 @@ use std::io::prelude::*; use std::path::PathBuf; use cargo::util::ProcessBuilder; -use cargotest; -use cargotest::support::execs; -use cargotest::support::git::repo; -use cargotest::support::paths; -use hamcrest::assert_that; +use support; +use support::execs; +use support::git::repo; +use support::paths; +use support::hamcrest::assert_that; use url::Url; fn registry_path() -> PathBuf { @@ -43,7 +43,7 @@ fn setup() { } fn cargo_process(s: &str) -> ProcessBuilder { - let mut b = cargotest::cargo_process(); + let mut b = support::cargo_process(); b.arg(s); b } diff --git a/tests/testsuite/shell_quoting.rs b/tests/testsuite/shell_quoting.rs index 771a8ea37..ae6013c8f 100644 --- a/tests/testsuite/shell_quoting.rs +++ b/tests/testsuite/shell_quoting.rs @@ -2,11 +2,11 @@ //! in the output, their arguments are quoted properly //! so that the command can be run in a terminal -use cargotest::support::{ +use support::{ execs, project, }; -use hamcrest::assert_that; +use support::hamcrest::assert_that; #[test] fn features_are_quoted() { diff --git a/tests/testsuite/small_fd_limits.rs b/tests/testsuite/small_fd_limits.rs index 82c924b6f..759c245a7 100644 --- a/tests/testsuite/small_fd_limits.rs +++ b/tests/testsuite/small_fd_limits.rs @@ -4,11 +4,11 @@ use std::path::PathBuf; use std::process::Command; use git2; -use cargotest::support::{execs, project}; -use cargotest::support::registry::Package; -use cargotest::support::paths; -use cargotest::support::git; -use hamcrest::assert_that; +use support::{execs, project}; +use support::registry::Package; +use support::paths; +use support::git; +use support::hamcrest::assert_that; use url::Url; diff --git a/tests/testsuite/cargotest/support/cross_compile.rs b/tests/testsuite/support/cross_compile.rs similarity index 98% rename from tests/testsuite/cargotest/support/cross_compile.rs rename to tests/testsuite/support/cross_compile.rs index fffc18db0..94c8ff7c3 100644 --- a/tests/testsuite/cargotest/support/cross_compile.rs +++ b/tests/testsuite/support/cross_compile.rs @@ -3,7 +3,7 @@ use std::process::Command; use std::sync::{Once, ONCE_INIT}; use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT}; -use cargotest::support::{basic_bin_manifest, main_file, project}; +use support::{basic_bin_manifest, main_file, project}; pub fn disabled() -> bool { // First, disable if ./configure requested so diff --git a/tests/testsuite/cargotest/support/git.rs b/tests/testsuite/support/git.rs similarity index 98% rename from tests/testsuite/cargotest/support/git.rs rename to tests/testsuite/support/git.rs index 7e0d89968..3edbc10b6 100644 --- a/tests/testsuite/cargotest/support/git.rs +++ b/tests/testsuite/support/git.rs @@ -6,7 +6,7 @@ use cargo::util::ProcessError; use git2; use url::Url; -use cargotest::support::{project, Project, ProjectBuilder, path2url}; +use support::{project, Project, ProjectBuilder, path2url}; #[must_use] pub struct RepoBuilder { diff --git a/tests/testsuite/hamcrest.rs b/tests/testsuite/support/hamcrest.rs similarity index 100% rename from tests/testsuite/hamcrest.rs rename to tests/testsuite/support/hamcrest.rs diff --git a/tests/testsuite/cargotest/install.rs b/tests/testsuite/support/install.rs similarity index 91% rename from tests/testsuite/cargotest/install.rs rename to tests/testsuite/support/install.rs index f6b8c83d0..d768db47d 100644 --- a/tests/testsuite/cargotest/install.rs +++ b/tests/testsuite/support/install.rs @@ -1,9 +1,9 @@ use std::fmt; use std::path::{Path, PathBuf}; -use hamcrest::{existing_file, MatchResult, Matcher}; +use support::hamcrest::{existing_file, MatchResult, Matcher}; -use cargotest::support::paths; +use support::paths; pub use self::InstalledExe as has_installed_exe; diff --git a/tests/testsuite/cargotest/support/mod.rs b/tests/testsuite/support/mod.rs similarity index 86% rename from tests/testsuite/cargotest/support/mod.rs rename to tests/testsuite/support/mod.rs index 7c7c5e517..a4090478a 100644 --- a/tests/testsuite/cargotest/support/mod.rs +++ b/tests/testsuite/support/mod.rs @@ -1,3 +1,87 @@ +/* +# Introduction To `support` + +Cargo has a wide variety of integration tests that execute the `cargo` binary +and verify its behavior. The `support` module contains many helpers to make +this process easy. + +The general form of a test involves creating a "project", running cargo, and +checking the result. Projects are created with the `ProjectBuilder` where you +specify some files to create. The general form looks like this: + +``` +let p = project() + .file("Cargo.toml", &basic_bin_manifest("foo")) + .file("src/main.rs", r#"fn main() { println!("hi!"); }"#) + .build(); +``` + +To run cargo, call the `cargo` method and use the `hamcrest` matchers to check +the output. + +``` +assert_that( + p.cargo("run --bin foo"), + execs() + .with_status(0) + .with_stderr( + "\ +[COMPILING] foo [..] +[FINISHED] [..] +[RUNNING] `target[/]debug[/]foo` +", + ) + .with_stdout("hi!"), +); +``` + +The project creates a mini sandbox under the "cargo integration test" +directory with each test getting a separate directory such as +`/path/to/cargo/target/cit/t123/`. Each project appears as a separate +directory. There is also an empty `home` directory created that will be used +as a home directory instead of your normal home directory. + +See `support::lines_match` for an explanation of the string pattern matching. + +See the `hamcrest` module for other matchers like +`is_not(existing_file(path))`. This is not the actual hamcrest library, but +instead a lightweight subset of matchers that are used in cargo tests. + +Browse the `pub` functions in the `support` module for a variety of other +helpful utilities. + +## Testing Nightly Features + +If you are testing a Cargo feature that only works on "nightly" cargo, then +you need to call `masquerade_as_nightly_cargo` on the process builder like +this: + +``` +p.cargo("build").masquerade_as_nightly_cargo() +``` + +If you are testing a feature that only works on *nightly rustc* (such as +benchmarks), then you should exit the test if it is not running with nightly +rust, like this: + +``` +if !is_nightly() { + return; +} +``` + +## Platform-specific Notes + +When checking output, be sure to use `[/]` when checking paths to +automatically support backslashes on Windows. + +Be careful when executing binaries on Windows. You should not rename, delete, +or overwrite a binary immediately after running it. Under some conditions +Windows will fail with errors like "directory not empty" or "failed to remove" +or "access is denied". + +*/ + use std::env; use std::ffi::OsStr; use std::fmt; @@ -7,16 +91,17 @@ use std::os; use std::path::{Path, PathBuf}; use std::process::Output; use std::str; +use std::time::Duration; use std::usize; -use cargo::util::ProcessBuilder; -use cargo::util::ProcessError; -use hamcrest as ham; +use cargo::util::{ProcessBuilder, ProcessError, Rustc}; +use cargo; use serde_json::{self, Value}; -use url::Url; use tempfile::TempDir; +use url::Url; -use cargotest::support::paths::CargoPathExt; +use self::hamcrest as ham; +use self::paths::CargoPathExt; macro_rules! t { ($e:expr) => { @@ -29,6 +114,7 @@ macro_rules! t { pub mod cross_compile; pub mod git; +pub mod hamcrest; pub mod paths; pub mod publish; pub mod registry; @@ -263,7 +349,7 @@ impl Project { /// execs().with_status(0).with_stdout("bar\n"), /// ); pub fn process>(&self, program: T) -> ProcessBuilder { - let mut p = ::cargotest::process(program); + let mut p = ::support::process(program); p.cwd(self.root()); return p; } @@ -1078,9 +1164,9 @@ impl<'a> ham::Matcher<&'a mut ProcessBuilder> for Execs { output: Some(ref out), .. }) = err - { - return self.match_output(out); - } + { + return self.match_output(out); + } let mut s = format!("could not exec process {}: {}", process, e); for cause in e.causes() { s.push_str(&format!("\ncaused by: {}", cause)); @@ -1199,3 +1285,88 @@ fn substitute_macros(input: &str) -> String { } return result; } + +pub mod install; + +thread_local!( +pub static RUSTC: Rustc = Rustc::new( + PathBuf::from("rustc"), + None, + Path::new("should be path to rustup rustc, but we don't care in tests"), + None, +).unwrap() +); + +/// The rustc host such as `x86_64-unknown-linux-gnu`. +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 { + _process(t.as_ref()) +} + +fn _process(t: &OsStr) -> cargo::util::ProcessBuilder { + let mut p = cargo::util::process(t); + p.cwd(&paths::root()) + .env_remove("CARGO_HOME") + .env("HOME", paths::home()) + .env("CARGO_HOME", paths::home().join(".cargo")) + .env("__CARGO_TEST_ROOT", paths::root()) + + // Force cargo to think it's on the stable channel for all tests, this + // should hopefully not surprise us as we add cargo features over time and + // cargo rides the trains. + .env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "stable") + + // For now disable incremental by default as support hasn't ridden to the + // stable channel yet. Once incremental support hits the stable compiler we + // can switch this to one and then fix the tests. + .env("CARGO_INCREMENTAL", "0") + + // This env var can switch the git backend from libgit2 to git2-curl, which + // can tweak error messages and cause some tests to fail, so let's forcibly + // remove it. + .env_remove("CARGO_HTTP_CHECK_REVOKE") + + .env_remove("__CARGO_DEFAULT_LIB_METADATA") + .env_remove("RUSTC") + .env_remove("RUSTDOC") + .env_remove("RUSTC_WRAPPER") + .env_remove("RUSTFLAGS") + .env_remove("XDG_CONFIG_HOME") // see #2345 + .env("GIT_CONFIG_NOSYSTEM", "1") // keep trying to sandbox ourselves + .env_remove("EMAIL") + .env_remove("MFLAGS") + .env_remove("MAKEFLAGS") + .env_remove("CARGO_MAKEFLAGS") + .env_remove("GIT_AUTHOR_NAME") + .env_remove("GIT_AUTHOR_EMAIL") + .env_remove("GIT_COMMITTER_NAME") + .env_remove("GIT_COMMITTER_EMAIL") + .env_remove("CARGO_TARGET_DIR") // we assume 'target' + .env_remove("MSYSTEM"); // assume cmd.exe everywhere on windows + return p; +} + +pub trait ChannelChanger: Sized { + fn masquerade_as_nightly_cargo(&mut self) -> &mut Self; +} + +impl ChannelChanger for cargo::util::ProcessBuilder { + fn masquerade_as_nightly_cargo(&mut self) -> &mut Self { + self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly") + } +} + +pub fn cargo_process() -> cargo::util::ProcessBuilder { + process(&cargo_exe()) +} + +pub fn sleep_ms(ms: u64) { + ::std::thread::sleep(Duration::from_millis(ms)); +} diff --git a/tests/testsuite/cargotest/support/paths.rs b/tests/testsuite/support/paths.rs similarity index 100% rename from tests/testsuite/cargotest/support/paths.rs rename to tests/testsuite/support/paths.rs diff --git a/tests/testsuite/cargotest/support/publish.rs b/tests/testsuite/support/publish.rs similarity index 94% rename from tests/testsuite/cargotest/support/publish.rs rename to tests/testsuite/support/publish.rs index 88c7bcbab..cc30b46f6 100644 --- a/tests/testsuite/cargotest/support/publish.rs +++ b/tests/testsuite/support/publish.rs @@ -2,8 +2,8 @@ use std::path::PathBuf; use std::io::prelude::*; use std::fs::{self, File}; -use cargotest::support::paths; -use cargotest::support::git::{repo, Repository}; +use support::paths; +use support::git::{repo, Repository}; use url::Url; diff --git a/tests/testsuite/cargotest/support/registry.rs b/tests/testsuite/support/registry.rs similarity index 99% rename from tests/testsuite/cargotest/support/registry.rs rename to tests/testsuite/support/registry.rs index 2842fad2f..d0a4d0bbf 100644 --- a/tests/testsuite/cargotest/support/registry.rs +++ b/tests/testsuite/support/registry.rs @@ -11,8 +11,8 @@ use hex; use tar::{Builder, Header}; use url::Url; -use cargotest::support::paths; -use cargotest::support::git::repo; +use support::paths; +use support::git::repo; pub fn registry_path() -> PathBuf { paths::root().join("registry") diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index 20ceecd84..d1669aa03 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -4,11 +4,11 @@ use std::str; use cargo; use cargo::util::process; -use cargotest::support::paths::CargoPathExt; -use cargotest::support::registry::Package; -use cargotest::support::{basic_bin_manifest, basic_lib_manifest, cargo_exe, execs, project}; -use cargotest::{is_nightly, rustc_host, sleep_ms}; -use hamcrest::{assert_that, existing_file, is_not}; +use support::paths::CargoPathExt; +use support::registry::Package; +use support::{basic_bin_manifest, basic_lib_manifest, cargo_exe, execs, project}; +use support::{is_nightly, rustc_host, sleep_ms}; +use support::hamcrest::{assert_that, existing_file, is_not}; #[test] fn cargo_test_simple() { diff --git a/tests/testsuite/tool_paths.rs b/tests/testsuite/tool_paths.rs index a4751f0ab..b859af6aa 100644 --- a/tests/testsuite/tool_paths.rs +++ b/tests/testsuite/tool_paths.rs @@ -1,6 +1,6 @@ -use cargotest::rustc_host; -use cargotest::support::{execs, project, path2url}; -use hamcrest::assert_that; +use support::rustc_host; +use support::{execs, project, path2url}; +use support::hamcrest::assert_that; #[test] fn pathless_tools() { diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index f092a86ac..03918e359 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -1,9 +1,9 @@ use std::fs::File; use std::io::prelude::*; -use cargotest::support::{execs, project}; -use cargotest::support::registry::Package; -use hamcrest::assert_that; +use support::{execs, project}; +use support::registry::Package; +use support::hamcrest::assert_that; #[test] fn minor_update_two_places() { diff --git a/tests/testsuite/verify_project.rs b/tests/testsuite/verify_project.rs index fb08db66c..90c2d97dc 100644 --- a/tests/testsuite/verify_project.rs +++ b/tests/testsuite/verify_project.rs @@ -1,5 +1,5 @@ -use cargotest::support::{basic_bin_manifest, execs, main_file, project}; -use hamcrest::assert_that; +use support::{basic_bin_manifest, execs, main_file, project}; +use support::hamcrest::assert_that; fn verify_project_success_output() -> String { r#"{"success":"true"}"#.into() diff --git a/tests/testsuite/version.rs b/tests/testsuite/version.rs index 63dbc38fc..221491f19 100644 --- a/tests/testsuite/version.rs +++ b/tests/testsuite/version.rs @@ -1,6 +1,6 @@ use cargo; -use cargotest::support::{execs, project}; -use hamcrest::assert_that; +use support::{execs, project}; +use support::hamcrest::assert_that; #[test] fn simple() { diff --git a/tests/testsuite/warn_on_failure.rs b/tests/testsuite/warn_on_failure.rs index 8316af6cb..c36499f8b 100644 --- a/tests/testsuite/warn_on_failure.rs +++ b/tests/testsuite/warn_on_failure.rs @@ -1,6 +1,6 @@ -use cargotest::support::{execs, project, Project}; -use cargotest::support::registry::Package; -use hamcrest::assert_that; +use support::{execs, project, Project}; +use support::registry::Package; +use support::hamcrest::assert_that; static WARNING1: &'static str = "Hello! I'm a warning. :)"; static WARNING2: &'static str = "And one more!"; diff --git a/tests/testsuite/workspaces.rs b/tests/testsuite/workspaces.rs index e3b34f739..32358f831 100644 --- a/tests/testsuite/workspaces.rs +++ b/tests/testsuite/workspaces.rs @@ -2,10 +2,10 @@ use std::env; use std::fs::{self, File}; use std::io::{Read, Write}; -use cargotest::sleep_ms; -use cargotest::support::{basic_lib_manifest, execs, git, project}; -use cargotest::support::registry::Package; -use hamcrest::{assert_that, existing_dir, existing_file, is_not}; +use support::sleep_ms; +use support::{basic_lib_manifest, execs, git, project}; +use support::registry::Package; +use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; #[test] fn simple_explicit() {