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
This commit is contained in:
Dale Wijnand 2018-07-21 22:17:44 +01:00
parent ffcf739578
commit 43b42d6f4c
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
84 changed files with 476 additions and 485 deletions

View File

@ -1,7 +1,7 @@
use cargotest::ChannelChanger; use support::ChannelChanger;
use cargotest::support::registry::{self, alt_api_path, Package}; use support::registry::{self, alt_api_path, Package};
use cargotest::support::{execs, paths, project}; use support::{execs, paths, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
use std::fs::File; use std::fs::File;
use std::io::Write; use std::io::Write;

View File

@ -1,6 +1,6 @@
use cargotest::support::{execs, project}; use support::{execs, project};
use cargotest::support::registry::Package; use support::registry::Package;
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn bad1() { fn bad1() {

View File

@ -1,5 +1,5 @@
use cargotest::support::{basic_bin_manifest, execs, main_file, project}; use support::{basic_bin_manifest, execs, main_file, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) { fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) {
let p = project() let p = project()

View File

@ -1,10 +1,10 @@
use std::str; use std::str;
use cargo::util::process; use cargo::util::process;
use cargotest::{is_nightly, ChannelChanger}; use support::{is_nightly, ChannelChanger};
use cargotest::support::paths::CargoPathExt; use support::paths::CargoPathExt;
use cargotest::support::{basic_bin_manifest, basic_lib_manifest, execs, project}; use support::{basic_bin_manifest, basic_lib_manifest, execs, project};
use hamcrest::{assert_that, existing_file}; use support::hamcrest::{assert_that, existing_file};
#[test] #[test]
fn cargo_bench_simple() { fn cargo_bench_simple() {

View File

@ -4,13 +4,13 @@ use std::io::prelude::*;
use cargo::util::paths::dylib_path_envvar; use cargo::util::paths::dylib_path_envvar;
use cargo::util::{process, ProcessBuilder}; use cargo::util::{process, ProcessBuilder};
use cargotest::{is_nightly, rustc_host, sleep_ms}; use support::{is_nightly, rustc_host, sleep_ms};
use cargotest::support::paths::{root, CargoPathExt}; use support::paths::{root, CargoPathExt};
use cargotest::support::ProjectBuilder; use support::ProjectBuilder;
use cargotest::support::{basic_bin_manifest, execs, main_file, project}; use support::{basic_bin_manifest, execs, main_file, project};
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::ChannelChanger; use support::ChannelChanger;
use hamcrest::{assert_that, existing_dir, existing_file, is_not}; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not};
use tempfile; use tempfile;
#[test] #[test]

View File

@ -6,9 +6,9 @@ use std::thread;
use git2; use git2;
use bufstream::BufStream; use bufstream::BufStream;
use cargotest::support::paths; use support::paths;
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
// Test that HTTP auth is offered from `credential.helper` // Test that HTTP auth is offered from `credential.helper`
#[test] #[test]

View File

@ -1,5 +1,5 @@
use cargotest::support::{basic_bin_manifest, execs, project, Project}; use support::{basic_bin_manifest, execs, project, Project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
fn verbose_output_for_lib(p: &Project) -> String { fn verbose_output_for_lib(p: &Project) -> String {
format!( format!(

View File

@ -1,6 +1,6 @@
use cargotest::ChannelChanger; use support::ChannelChanger;
use cargotest::support::{basic_bin_manifest, execs, main_file, project}; use support::{basic_bin_manifest, execs, main_file, project};
use hamcrest::{assert_that, existing_file, is_not}; use support::hamcrest::{assert_that, existing_file, is_not};
#[test] #[test]
fn cargo_build_plan_simple() { fn cargo_build_plan_simple() {

View File

@ -7,11 +7,11 @@ use std::thread;
use std::time::Duration; use std::time::Duration;
use cargo::util::paths::remove_dir_all; use cargo::util::paths::remove_dir_all;
use cargotest::{rustc_host, sleep_ms}; use support::{rustc_host, sleep_ms};
use cargotest::support::{cross_compile, execs, project}; use support::{cross_compile, execs, project};
use cargotest::support::paths::CargoPathExt; use support::paths::CargoPathExt;
use cargotest::support::registry::Package; use support::registry::Package;
use hamcrest::{assert_that, existing_dir, existing_file}; use support::hamcrest::{assert_that, existing_dir, existing_file};
#[test] #[test]
fn custom_build_script_failed() { fn custom_build_script_failed() {

View File

@ -1,8 +1,8 @@
use std::fs::File; use std::fs::File;
use cargotest::sleep_ms; use support::sleep_ms;
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn rerun_if_env_changes() { fn rerun_if_env_changes() {

View File

@ -1,5 +1,5 @@
use cargotest::support::{basic_bin_manifest, execs, project}; use support::{basic_bin_manifest, execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn alias_incorrect_config_type() { fn alias_incorrect_config_type() {

View File

@ -5,11 +5,11 @@ use std::path::{Path, PathBuf};
use std::str; use std::str;
use cargo; use cargo;
use cargotest::cargo_process; use support::cargo_process;
use cargotest::support::paths::{self, CargoPathExt}; use support::paths::{self, CargoPathExt};
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{basic_bin_manifest, cargo_exe, execs, project, Project}; use support::{basic_bin_manifest, cargo_exe, execs, project, Project};
use hamcrest::{assert_that, existing_file}; use support::hamcrest::{assert_that, existing_file};
#[cfg_attr(windows, allow(dead_code))] #[cfg_attr(windows, allow(dead_code))]
enum FakeKind<'a> { enum FakeKind<'a> {

View File

@ -1,6 +1,6 @@
use cargotest::ChannelChanger; use support::ChannelChanger;
use cargotest::support::{execs, project, publish}; use support::{execs, project, publish};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn feature_required() { fn feature_required() {

View File

@ -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: AsRef<OsStr>>(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));
}

View File

@ -2,10 +2,10 @@ use std::str::FromStr;
use std::fmt; use std::fmt;
use cargo::util::{Cfg, CfgExpr}; use cargo::util::{Cfg, CfgExpr};
use cargotest::rustc_host; use support::rustc_host;
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
macro_rules! c { macro_rules! c {
($a:ident) => ( ($a:ident) => (

View File

@ -1,10 +1,10 @@
use cargotest::install::exe; use support::install::exe;
use cargotest::is_nightly; use support::is_nightly;
use cargotest::support::paths::CargoPathExt; use support::paths::CargoPathExt;
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{execs, project}; use support::{execs, project};
use glob::glob; 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#" const SIMPLE_MANIFEST: &str = r#"
[package] [package]

View File

@ -1,8 +1,8 @@
use std::env; use std::env;
use cargotest::support::{basic_bin_manifest, execs, git, main_file, project}; use support::{basic_bin_manifest, execs, git, main_file, project};
use cargotest::support::registry::Package; use support::registry::Package;
use hamcrest::{assert_that, existing_dir, existing_file, is_not}; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not};
#[test] #[test]
fn cargo_clean_simple() { fn cargo_clean_simple() {

View File

@ -8,12 +8,12 @@ use std::sync::mpsc::channel;
use std::time::Duration; use std::time::Duration;
use git2; use git2;
use cargotest; use support;
use cargotest::install::{cargo_home, has_installed_exe}; use support::install::{cargo_home, has_installed_exe};
use cargotest::support::git; use support::git;
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::{assert_that, existing_file}; use support::hamcrest::{assert_that, existing_file};
fn pkg(name: &str, vers: &str) { fn pkg(name: &str, vers: &str) {
Package::new(name, vers) Package::new(name, vers)
@ -72,11 +72,11 @@ fn concurrent_installs() {
pkg("foo", "0.0.1"); pkg("foo", "0.0.1");
pkg("bar", "0.0.1"); pkg("bar", "0.0.1");
let mut a = cargotest::cargo_process() let mut a = support::cargo_process()
.arg("install") .arg("install")
.arg("foo") .arg("foo")
.build_command(); .build_command();
let mut b = cargotest::cargo_process() let mut b = support::cargo_process()
.arg("install") .arg("install")
.arg("bar") .arg("bar")
.build_command(); .build_command();

View File

@ -2,8 +2,8 @@ use cargo::core::{Shell, enable_nightly_features};
use cargo::util::config::{self, Config}; use cargo::util::config::{self, Config};
use cargo::util::toml::{self, VecStringOrBool as VSOB}; use cargo::util::toml::{self, VecStringOrBool as VSOB};
use cargo::CargoError; use cargo::CargoError;
use cargotest::support::{execs, lines_match, paths, project}; use support::{execs, lines_match, paths, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
use std::collections; use std::collections;
use std::fs; use std::fs;

View File

@ -2,9 +2,9 @@ use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use cargo::util::paths as cargopaths; use cargo::util::paths as cargopaths;
use cargotest::support::paths; use support::paths;
use cargotest::support::{execs, git, project}; use support::{execs, git, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn deleting_database_files() { fn deleting_database_files() {

View File

@ -1,7 +1,7 @@
use cargo::util::process; use cargo::util::process;
use cargotest::{is_nightly, rustc_host}; use support::{is_nightly, rustc_host};
use cargotest::support::{basic_bin_manifest, cross_compile, execs, project}; use support::{basic_bin_manifest, cross_compile, execs, project};
use hamcrest::{assert_that, existing_file}; use support::hamcrest::{assert_that, existing_file};
#[test] #[test]
fn simple_cross() { fn simple_cross() {

View File

@ -2,8 +2,8 @@ use std::fs::File;
use std::path::PathBuf; use std::path::PathBuf;
use std::io::prelude::*; use std::io::prelude::*;
use cargotest::support::{cross_compile, execs, project, publish}; use support::{cross_compile, execs, project, publish};
use hamcrest::{assert_that, contains}; use support::hamcrest::{assert_that, contains};
use flate2::read::GzDecoder; use flate2::read::GzDecoder;
use tar::Archive; use tar::Archive;

View File

@ -1,6 +1,6 @@
use cargotest::is_nightly; use support::is_nightly;
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn custom_target_minimal() { fn custom_target_minimal() {

View File

@ -5,7 +5,7 @@ use std::process::{Child, Stdio};
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use cargotest::support::project; use support::project;
#[cfg(unix)] #[cfg(unix)]
fn enabled() -> bool { fn enabled() -> bool {

View File

@ -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 filetime::FileTime;
use hamcrest::{assert_that, existing_file}; use support::hamcrest::{assert_that, existing_file};
#[test] #[test]
fn build_dep_info() { fn build_dep_info() {

View File

@ -4,12 +4,12 @@ use std::fs::{self, File};
use std::io::prelude::*; use std::io::prelude::*;
use std::str; use std::str;
use cargotest::cargo_process; use support::cargo_process;
use cargotest::support::git; use support::git;
use cargotest::support::paths; use support::paths;
use cargotest::support::registry::{cksum, Package}; use support::registry::{cksum, Package};
use cargotest::support::{execs, project, ProjectBuilder}; use support::{execs, project, ProjectBuilder};
use hamcrest::assert_that; use support::hamcrest::assert_that;
fn setup() { fn setup() {
let root = paths::root(); let root = paths::root();

View File

@ -1,13 +1,13 @@
use cargotest; use support;
use std::str; use std::str;
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::Read; use std::io::Read;
use cargotest::{is_nightly, rustc_host, ChannelChanger}; use support::{is_nightly, rustc_host, ChannelChanger};
use cargotest::support::{basic_lib_manifest, execs, git, project, path2url}; use support::{basic_lib_manifest, execs, git, project, path2url};
use cargotest::support::paths::CargoPathExt; use support::paths::CargoPathExt;
use cargotest::support::registry::Package; use support::registry::Package;
use hamcrest::{assert_that, existing_dir, existing_file, is_not}; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not};
use cargo::util::ProcessError; use cargo::util::ProcessError;
use glob::glob; use glob::glob;
@ -1216,7 +1216,7 @@ fn document_only_lib() {
#[test] #[test]
fn plugins_no_use_target() { fn plugins_no_use_target() {
if !cargotest::is_nightly() { if !support::is_nightly() {
return; return;
} }
let p = project() let p = project()
@ -1591,7 +1591,7 @@ fn doc_workspace_open_binary_and_library() {
#[test] #[test]
fn doc_edition() { fn doc_edition() {
if !cargotest::is_nightly() { if !support::is_nightly() {
// Stable rustdoc won't have the edition option. Remove this once it // Stable rustdoc won't have the edition option. Remove this once it
// is stabilized. // is stabilized.
return; return;

View File

@ -1,11 +1,11 @@
use std::fs::File; use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;
use cargotest::support::paths::CargoPathExt; use support::paths::CargoPathExt;
use cargotest::support::{execs, project}; use support::{execs, project};
use cargotest::ChannelChanger; use support::ChannelChanger;
use hamcrest::assert_that; use support::hamcrest::assert_that;
use cargotest::support::registry::Package; use support::registry::Package;
#[test] #[test]
fn invalid1() { fn invalid1() {

View File

@ -1,7 +1,7 @@
use cargotest::rustc_host; use support::rustc_host;
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{cross_compile, execs, project}; use support::{cross_compile, execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn no_deps() { fn no_deps() {

View File

@ -1,8 +1,8 @@
use cargotest::support::git; use support::git;
use cargotest::support::{execs, project}; use support::{execs, project};
use cargotest::{is_nightly, ChannelChanger}; use support::{is_nightly, ChannelChanger};
use git2; use git2;
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn do_not_fix_broken_builds() { fn do_not_fix_broken_builds() {

View File

@ -1,11 +1,11 @@
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::prelude::*; use std::io::prelude::*;
use cargotest::sleep_ms; use support::sleep_ms;
use cargotest::support::paths::CargoPathExt; use support::paths::CargoPathExt;
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{execs, path2url, project}; use support::{execs, path2url, project};
use hamcrest::{assert_that, existing_file}; use support::hamcrest::{assert_that, existing_file};
#[test] #[test]
fn modifying_and_moving() { fn modifying_and_moving() {

View File

@ -1,10 +1,10 @@
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::prelude::*; use std::io::prelude::*;
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{execs, paths, project, ProjectBuilder}; use support::{execs, paths, project, ProjectBuilder};
use cargotest::ChannelChanger; use support::ChannelChanger;
use hamcrest::{assert_that, existing_file, is_not}; use support::hamcrest::{assert_that, existing_file, is_not};
#[test] #[test]
fn adding_and_removing_packages() { fn adding_and_removing_packages() {

View File

@ -8,11 +8,11 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::thread; use std::thread;
use cargo::util::process; use cargo::util::process;
use cargotest::sleep_ms; use support::sleep_ms;
use cargotest::support::paths::{self, CargoPathExt}; use support::paths::{self, CargoPathExt};
use cargotest::support::{execs, git, main_file, project, path2url}; use support::{execs, git, main_file, project, path2url};
use cargotest::ChannelChanger; use support::ChannelChanger;
use hamcrest::{assert_that, existing_file}; use support::hamcrest::{assert_that, existing_file};
#[test] #[test]
fn cargo_compile_simple_git_dep() { fn cargo_compile_simple_git_dep() {

View File

@ -1,15 +1,15 @@
use cargotest; use support;
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::prelude::*; use std::io::prelude::*;
use std::env; use std::env;
use cargo::util::ProcessBuilder; use cargo::util::ProcessBuilder;
use cargotest::support::{cargo_exe, execs, paths}; use support::{cargo_exe, execs, paths};
use hamcrest::{assert_that, existing_dir, existing_file, is_not}; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not};
use tempfile; use tempfile;
fn cargo_process(s: &str) -> ProcessBuilder { 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.arg(s).cwd(&paths::root()).env("HOME", &paths::home());
p p
} }

View File

@ -1,20 +1,20 @@
use cargotest; use support;
use std::fs::{self, File, OpenOptions}; use std::fs::{self, File, OpenOptions};
use std::io::prelude::*; use std::io::prelude::*;
use cargo::util::ProcessBuilder; use cargo::util::ProcessBuilder;
use cargotest::install::{cargo_home, has_installed_exe}; use support::install::{cargo_home, has_installed_exe};
use cargotest::support::cross_compile; use support::cross_compile;
use cargotest::support::git; use support::git;
use cargotest::support::paths; use support::paths;
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{execs, project}; use support::{execs, project};
use cargotest::ChannelChanger; use support::ChannelChanger;
use git2; 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 { fn cargo_process(s: &str) -> ProcessBuilder {
let mut p = cargotest::cargo_process(); let mut p = support::cargo_process();
p.arg(s); p.arg(s);
p p
} }
@ -1050,7 +1050,7 @@ warning: To build the current package use `cargo build`, to install the current
#[test] #[test]
fn installs_from_cwd_with_2018_warnings() { 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 // Stable rust won't have the edition option. Remove this once it
// is stabilized. // is stabilized.
return; return;
@ -1343,7 +1343,7 @@ fn install_target_native() {
cargo_process("install") cargo_process("install")
.arg("foo") .arg("foo")
.arg("--target") .arg("--target")
.arg(cargotest::rustc_host()), .arg(support::rustc_host()),
execs() execs()
.with_status(0), .with_status(0),
); );

View File

@ -2,8 +2,8 @@ use std::net::TcpListener;
use std::thread; use std::thread;
use std::process::Command; use std::process::Command;
use cargotest::support::{cargo_exe, execs, project}; use support::{cargo_exe, execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn jobserver_exists() { fn jobserver_exists() {

View File

@ -1,10 +1,10 @@
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::prelude::*; use std::io::prelude::*;
use cargotest::support::paths::{self, CargoPathExt}; use support::paths::{self, CargoPathExt};
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
fn setup() { fn setup() {
let root = paths::root(); let root = paths::root();

View File

@ -1,7 +1,7 @@
use cargotest::support::git; use support::git;
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{execs, lines_match, project}; use support::{execs, lines_match, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn oldest_lockfile_still_works() { fn oldest_lockfile_still_works() {

View File

@ -2,13 +2,13 @@ use std::io::prelude::*;
use std::fs::{self, File}; use std::fs::{self, File};
use toml; use toml;
use cargotest::{cargo_process, ChannelChanger}; use support::{cargo_process, ChannelChanger};
use cargotest::support::execs; use support::execs;
use cargotest::support::registry::registry; use support::registry::registry;
use cargotest::install::cargo_home; use support::install::cargo_home;
use cargo::util::config::Config; use cargo::util::config::Config;
use cargo::core::Shell; 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 TOKEN: &str = "test-token";
const ORIGINAL_TOKEN: &str = "api-token"; const ORIGINAL_TOKEN: &str = "api-token";

View File

@ -20,8 +20,7 @@ extern crate url;
extern crate winapi; extern crate winapi;
#[macro_use] #[macro_use]
mod cargotest; mod support;
mod hamcrest;
mod alt_registry; mod alt_registry;
mod bad_config; mod bad_config;

View File

@ -1,6 +1,6 @@
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{basic_bin_manifest, basic_lib_manifest, execs, main_file, project}; use support::{basic_bin_manifest, basic_lib_manifest, execs, main_file, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn cargo_metadata_simple() { fn cargo_metadata_simple() {

View File

@ -1,5 +1,5 @@
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn net_retry_loads_from_config() { fn net_retry_loads_from_config() {

View File

@ -2,15 +2,15 @@ use std::fs::{self, File};
use std::io::prelude::*; use std::io::prelude::*;
use std::env; use std::env;
use cargotest; use support;
use cargo::util::ProcessBuilder; use cargo::util::ProcessBuilder;
use cargotest::process; use support::process;
use cargotest::support::{execs, paths}; use support::{execs, paths};
use hamcrest::{assert_that, existing_dir, existing_file, is_not}; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not};
use tempfile; use tempfile;
fn cargo_process(s: &str) -> ProcessBuilder { fn cargo_process(s: &str) -> ProcessBuilder {
let mut p = cargotest::cargo_process(); let mut p = support::cargo_process();
p.arg(s); p.arg(s);
p p
} }

View File

@ -2,10 +2,10 @@ use std::path::Path;
use std::fs::{self, File}; use std::fs::{self, File};
use std::env; use std::env;
use hamcrest::assert_that; use support::hamcrest::assert_that;
use cargotest::{process, sleep_ms, ChannelChanger}; use support::{process, sleep_ms, ChannelChanger};
use cargotest::support::{execs, project}; use support::{execs, project};
#[test] #[test]
fn binary_with_debug() { fn binary_with_debug() {

View File

@ -1,8 +1,8 @@
use cargotest::support::git; use support::git;
use cargotest::support::paths; use support::paths;
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn override_simple() { fn override_simple() {

View File

@ -4,11 +4,11 @@ use std::io::prelude::*;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use git2; use git2;
use cargotest::{cargo_process, process, sleep_ms, ChannelChanger}; use support::{cargo_process, process, sleep_ms, ChannelChanger};
use cargotest::support::{cargo_exe, execs, git, paths, project, registry, path2url}; use support::{cargo_exe, execs, git, paths, project, registry, path2url};
use cargotest::support::registry::Package; use support::registry::Package;
use flate2::read::GzDecoder; use flate2::read::GzDecoder;
use hamcrest::{assert_that, contains, existing_file}; use support::hamcrest::{assert_that, contains, existing_file};
use tar::Archive; use tar::Archive;
#[test] #[test]

View File

@ -2,11 +2,11 @@ use std::fs::{self, File};
use std::io::{Read, Write}; use std::io::{Read, Write};
use toml; use toml;
use cargotest::support::git; use support::git;
use cargotest::support::paths; use support::paths;
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn replace() { fn replace() {

View File

@ -2,11 +2,11 @@ use std::fs::{self, File};
use std::io::prelude::*; use std::io::prelude::*;
use cargo::util::process; use cargo::util::process;
use cargotest::sleep_ms; use support::sleep_ms;
use cargotest::support::paths::{self, CargoPathExt}; use support::paths::{self, CargoPathExt};
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{execs, main_file, project}; use support::{execs, main_file, project};
use hamcrest::{assert_that, existing_file, is_not}; use support::hamcrest::{assert_that, existing_file, is_not};
#[test] #[test]
#[cfg(not(windows))] // I have no idea why this is failing spuriously on #[cfg(not(windows))] // I have no idea why this is failing spuriously on

View File

@ -1,9 +1,9 @@
use std::fs; use std::fs;
use std::env; use std::env;
use cargotest::{is_nightly, rustc_host}; use support::{is_nightly, rustc_host};
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn plugin_to_the_max() { fn plugin_to_the_max() {

View File

@ -1,6 +1,6 @@
use cargotest::is_nightly; use support::is_nightly;
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn probe_cfg_before_crate_type_discovery() { fn probe_cfg_before_crate_type_discovery() {

View File

@ -1,6 +1,6 @@
use cargotest::support::{basic_lib_manifest, execs, paths, project}; use support::{basic_lib_manifest, execs, paths, project};
use cargotest::ChannelChanger; use support::ChannelChanger;
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn profile_config_gated() { fn profile_config_gated() {

View File

@ -1,6 +1,6 @@
use cargotest::support::{basic_lib_manifest, execs, project}; use support::{basic_lib_manifest, execs, project};
use cargotest::ChannelChanger; use support::ChannelChanger;
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn profile_override_gated() { fn profile_override_gated() {

View File

@ -1,6 +1,6 @@
use cargotest::is_nightly; use support::is_nightly;
use cargotest::support::{execs, project, Project}; use support::{execs, project, Project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
// These tests try to exercise exactly which profiles are selected for every // These tests try to exercise exactly which profiles are selected for every
// target. // target.

View File

@ -1,8 +1,8 @@
use std::env; use std::env;
use cargotest::is_nightly; use support::is_nightly;
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn profile_overrides() { fn profile_overrides() {

View File

@ -2,12 +2,12 @@ use std::io::prelude::*;
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::SeekFrom; use std::io::SeekFrom;
use cargotest::ChannelChanger; use support::ChannelChanger;
use cargotest::support::git::repo; use support::git::repo;
use cargotest::support::paths; use support::paths;
use cargotest::support::{execs, project, publish}; use support::{execs, project, publish};
use flate2::read::GzDecoder; use flate2::read::GzDecoder;
use hamcrest::assert_that; use support::hamcrest::assert_that;
use tar::Archive; use tar::Archive;
#[test] #[test]

View File

@ -1,5 +1,5 @@
use cargotest::support::{basic_bin_manifest, execs, main_file, project}; use support::{basic_bin_manifest, execs, main_file, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
static MANIFEST_OUTPUT: &'static str = r#" static MANIFEST_OUTPUT: &'static str = r#"
{ {

View File

@ -3,12 +3,12 @@ use std::io::prelude::*;
use std::path::PathBuf; use std::path::PathBuf;
use cargo::util::paths::remove_dir_all; use cargo::util::paths::remove_dir_all;
use cargotest::cargo_process; use support::cargo_process;
use cargotest::support::git; use support::git;
use cargotest::support::paths::{self, CargoPathExt}; use support::paths::{self, CargoPathExt};
use cargotest::support::registry::{self, Package}; use support::registry::{self, Package};
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
use url::Url; use url::Url;
fn registry_path() -> PathBuf { fn registry_path() -> PathBuf {
@ -762,7 +762,7 @@ fn update_lockfile() {
#[test] #[test]
fn update_offline() { fn update_offline() {
use cargotest::ChannelChanger; use support::ChannelChanger;
let p = project() let p = project()
.file( .file(
"Cargo.toml", "Cargo.toml",

View File

@ -1,9 +1,9 @@
use cargotest::ChannelChanger; use support::ChannelChanger;
use cargotest::support::git; use support::git;
use cargotest::support::paths; use support::paths;
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn gated() { fn gated() {

View File

@ -1,7 +1,7 @@
use cargotest::is_nightly; use support::is_nightly;
use cargotest::install::{cargo_home, has_installed_exe}; use support::install::{cargo_home, has_installed_exe};
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::{assert_that, existing_file, is_not}; use support::hamcrest::{assert_that, existing_file, is_not};
#[test] #[test]
fn build_bin_default_features() { fn build_bin_default_features() {

View File

@ -1,6 +1,6 @@
use std::collections::{BTreeMap, HashSet}; 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::source::{GitReference, SourceId};
use cargo::core::dependency::Kind::{self, Development}; 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::util::{CargoResult, Config, ToUrl};
use cargo::core::resolver::{self, Method}; use cargo::core::resolver::{self, Method};
use cargotest::ChannelChanger; use support::ChannelChanger;
use cargotest::support::{execs, project}; use support::{execs, project};
use cargotest::support::registry::Package; use support::registry::Package;
fn resolve( fn resolve(
pkg: &PackageId, pkg: &PackageId,

View File

@ -1,7 +1,7 @@
use cargo::util::paths::dylib_path_envvar; use cargo::util::paths::dylib_path_envvar;
use cargotest::{self, ChannelChanger}; use support::{self, ChannelChanger};
use cargotest::support::{execs, project, Project, path2url}; use support::{execs, project, Project, path2url};
use hamcrest::{assert_that, existing_file}; use support::hamcrest::{assert_that, existing_file};
#[test] #[test]
fn simple() { fn simple() {
@ -596,7 +596,7 @@ fn autodiscover_examples_project(rust_edition: &str, autoexamples: Option<bool>)
#[test] #[test]
fn run_example_autodiscover_2015() { fn run_example_autodiscover_2015() {
if !cargotest::is_nightly() { if !support::is_nightly() {
return; return;
} }
@ -631,7 +631,7 @@ error: no example target named `a`
#[test] #[test]
fn run_example_autodiscover_2015_with_autoexamples_enabled() { fn run_example_autodiscover_2015_with_autoexamples_enabled() {
if !cargotest::is_nightly() { if !support::is_nightly() {
return; return;
} }
@ -656,7 +656,7 @@ fn run_example_autodiscover_2015_with_autoexamples_enabled() {
#[test] #[test]
fn run_example_autodiscover_2015_with_autoexamples_disabled() { fn run_example_autodiscover_2015_with_autoexamples_disabled() {
if !cargotest::is_nightly() { if !support::is_nightly() {
return; return;
} }
@ -674,7 +674,7 @@ fn run_example_autodiscover_2015_with_autoexamples_disabled() {
#[test] #[test]
fn run_example_autodiscover_2018() { fn run_example_autodiscover_2018() {
if !cargotest::is_nightly() { if !support::is_nightly() {
return; return;
} }

View File

@ -1,5 +1,5 @@
use cargotest::support::{basic_bin_manifest, basic_lib_manifest, execs, project}; use support::{basic_bin_manifest, basic_lib_manifest, execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
const CARGO_RUSTC_ERROR: &'static str = const CARGO_RUSTC_ERROR: &'static str =
"[ERROR] extra arguments to `rustc` can only be passed to one target, consider filtering "[ERROR] extra arguments to `rustc` can only be passed to one target, consider filtering

View File

@ -1,6 +1,6 @@
use cargotest::support::{execs, project}; use support::{execs, project};
use cargotest::support::paths::CargoPathExt; use support::paths::CargoPathExt;
use hamcrest::assert_that; use support::hamcrest::assert_that;
use std::env; use std::env;
#[test] #[test]

View File

@ -1,5 +1,5 @@
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn rustdoc_simple() { fn rustdoc_simple() {

View File

@ -1,5 +1,5 @@
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn parses_env() { fn parses_env() {

View File

@ -1,9 +1,9 @@
use std::io::Write; use std::io::Write;
use std::fs::{self, File}; use std::fs::{self, File};
use cargotest::rustc_host; use support::rustc_host;
use cargotest::support::{execs, paths, project, project_in_home}; use support::{execs, paths, project, project_in_home};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn env_rustflags_normal_source() { fn env_rustflags_normal_source() {

View File

@ -3,11 +3,11 @@ use std::io::prelude::*;
use std::path::PathBuf; use std::path::PathBuf;
use cargo::util::ProcessBuilder; use cargo::util::ProcessBuilder;
use cargotest; use support;
use cargotest::support::execs; use support::execs;
use cargotest::support::git::repo; use support::git::repo;
use cargotest::support::paths; use support::paths;
use hamcrest::assert_that; use support::hamcrest::assert_that;
use url::Url; use url::Url;
fn registry_path() -> PathBuf { fn registry_path() -> PathBuf {
@ -43,7 +43,7 @@ fn setup() {
} }
fn cargo_process(s: &str) -> ProcessBuilder { fn cargo_process(s: &str) -> ProcessBuilder {
let mut b = cargotest::cargo_process(); let mut b = support::cargo_process();
b.arg(s); b.arg(s);
b b
} }

View File

@ -2,11 +2,11 @@
//! in the output, their arguments are quoted properly //! in the output, their arguments are quoted properly
//! so that the command can be run in a terminal //! so that the command can be run in a terminal
use cargotest::support::{ use support::{
execs, execs,
project, project,
}; };
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn features_are_quoted() { fn features_are_quoted() {

View File

@ -4,11 +4,11 @@ use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use git2; use git2;
use cargotest::support::{execs, project}; use support::{execs, project};
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::paths; use support::paths;
use cargotest::support::git; use support::git;
use hamcrest::assert_that; use support::hamcrest::assert_that;
use url::Url; use url::Url;

View File

@ -3,7 +3,7 @@ use std::process::Command;
use std::sync::{Once, ONCE_INIT}; use std::sync::{Once, ONCE_INIT};
use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_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 { pub fn disabled() -> bool {
// First, disable if ./configure requested so // First, disable if ./configure requested so

View File

@ -6,7 +6,7 @@ use cargo::util::ProcessError;
use git2; use git2;
use url::Url; use url::Url;
use cargotest::support::{project, Project, ProjectBuilder, path2url}; use support::{project, Project, ProjectBuilder, path2url};
#[must_use] #[must_use]
pub struct RepoBuilder { pub struct RepoBuilder {

View File

@ -1,9 +1,9 @@
use std::fmt; use std::fmt;
use std::path::{Path, PathBuf}; 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; pub use self::InstalledExe as has_installed_exe;

View File

@ -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::env;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::fmt; use std::fmt;
@ -7,16 +91,17 @@ use std::os;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Output; use std::process::Output;
use std::str; use std::str;
use std::time::Duration;
use std::usize; use std::usize;
use cargo::util::ProcessBuilder; use cargo::util::{ProcessBuilder, ProcessError, Rustc};
use cargo::util::ProcessError; use cargo;
use hamcrest as ham;
use serde_json::{self, Value}; use serde_json::{self, Value};
use url::Url;
use tempfile::TempDir; use tempfile::TempDir;
use url::Url;
use cargotest::support::paths::CargoPathExt; use self::hamcrest as ham;
use self::paths::CargoPathExt;
macro_rules! t { macro_rules! t {
($e:expr) => { ($e:expr) => {
@ -29,6 +114,7 @@ macro_rules! t {
pub mod cross_compile; pub mod cross_compile;
pub mod git; pub mod git;
pub mod hamcrest;
pub mod paths; pub mod paths;
pub mod publish; pub mod publish;
pub mod registry; pub mod registry;
@ -263,7 +349,7 @@ impl Project {
/// execs().with_status(0).with_stdout("bar\n"), /// execs().with_status(0).with_stdout("bar\n"),
/// ); /// );
pub fn process<T: AsRef<OsStr>>(&self, program: T) -> ProcessBuilder { pub fn process<T: AsRef<OsStr>>(&self, program: T) -> ProcessBuilder {
let mut p = ::cargotest::process(program); let mut p = ::support::process(program);
p.cwd(self.root()); p.cwd(self.root());
return p; return p;
} }
@ -1078,9 +1164,9 @@ impl<'a> ham::Matcher<&'a mut ProcessBuilder> for Execs {
output: Some(ref out), output: Some(ref out),
.. ..
}) = err }) = err
{ {
return self.match_output(out); return self.match_output(out);
} }
let mut s = format!("could not exec process {}: {}", process, e); let mut s = format!("could not exec process {}: {}", process, e);
for cause in e.causes() { for cause in e.causes() {
s.push_str(&format!("\ncaused by: {}", cause)); s.push_str(&format!("\ncaused by: {}", cause));
@ -1199,3 +1285,88 @@ fn substitute_macros(input: &str) -> String {
} }
return result; 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: AsRef<OsStr>>(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));
}

View File

@ -2,8 +2,8 @@ use std::path::PathBuf;
use std::io::prelude::*; use std::io::prelude::*;
use std::fs::{self, File}; use std::fs::{self, File};
use cargotest::support::paths; use support::paths;
use cargotest::support::git::{repo, Repository}; use support::git::{repo, Repository};
use url::Url; use url::Url;

View File

@ -11,8 +11,8 @@ use hex;
use tar::{Builder, Header}; use tar::{Builder, Header};
use url::Url; use url::Url;
use cargotest::support::paths; use support::paths;
use cargotest::support::git::repo; use support::git::repo;
pub fn registry_path() -> PathBuf { pub fn registry_path() -> PathBuf {
paths::root().join("registry") paths::root().join("registry")

View File

@ -4,11 +4,11 @@ use std::str;
use cargo; use cargo;
use cargo::util::process; use cargo::util::process;
use cargotest::support::paths::CargoPathExt; use support::paths::CargoPathExt;
use cargotest::support::registry::Package; use support::registry::Package;
use cargotest::support::{basic_bin_manifest, basic_lib_manifest, cargo_exe, execs, project}; use support::{basic_bin_manifest, basic_lib_manifest, cargo_exe, execs, project};
use cargotest::{is_nightly, rustc_host, sleep_ms}; use support::{is_nightly, rustc_host, sleep_ms};
use hamcrest::{assert_that, existing_file, is_not}; use support::hamcrest::{assert_that, existing_file, is_not};
#[test] #[test]
fn cargo_test_simple() { fn cargo_test_simple() {

View File

@ -1,6 +1,6 @@
use cargotest::rustc_host; use support::rustc_host;
use cargotest::support::{execs, project, path2url}; use support::{execs, project, path2url};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn pathless_tools() { fn pathless_tools() {

View File

@ -1,9 +1,9 @@
use std::fs::File; use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;
use cargotest::support::{execs, project}; use support::{execs, project};
use cargotest::support::registry::Package; use support::registry::Package;
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn minor_update_two_places() { fn minor_update_two_places() {

View File

@ -1,5 +1,5 @@
use cargotest::support::{basic_bin_manifest, execs, main_file, project}; use support::{basic_bin_manifest, execs, main_file, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
fn verify_project_success_output() -> String { fn verify_project_success_output() -> String {
r#"{"success":"true"}"#.into() r#"{"success":"true"}"#.into()

View File

@ -1,6 +1,6 @@
use cargo; use cargo;
use cargotest::support::{execs, project}; use support::{execs, project};
use hamcrest::assert_that; use support::hamcrest::assert_that;
#[test] #[test]
fn simple() { fn simple() {

View File

@ -1,6 +1,6 @@
use cargotest::support::{execs, project, Project}; use support::{execs, project, Project};
use cargotest::support::registry::Package; use support::registry::Package;
use hamcrest::assert_that; use support::hamcrest::assert_that;
static WARNING1: &'static str = "Hello! I'm a warning. :)"; static WARNING1: &'static str = "Hello! I'm a warning. :)";
static WARNING2: &'static str = "And one more!"; static WARNING2: &'static str = "And one more!";

View File

@ -2,10 +2,10 @@ use std::env;
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::{Read, Write}; use std::io::{Read, Write};
use cargotest::sleep_ms; use support::sleep_ms;
use cargotest::support::{basic_lib_manifest, execs, git, project}; use support::{basic_lib_manifest, execs, git, project};
use cargotest::support::registry::Package; use support::registry::Package;
use hamcrest::{assert_that, existing_dir, existing_file, is_not}; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not};
#[test] #[test]
fn simple_explicit() { fn simple_explicit() {