Skip to content

Commit

Permalink
Extract support directory to its own crate
Browse files Browse the repository at this point in the history
Extract out all our test support code to its own standalone crate so it
can be shared between multiple test suites if necessary.
  • Loading branch information
alexcrichton committed Sep 16, 2019
1 parent 4cbfd02 commit 9115b2c
Show file tree
Hide file tree
Showing 101 changed files with 268 additions and 263 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ features = [

[dev-dependencies]
cargo-test-macro = { path = "crates/cargo-test-macro", version = "0.1.0" }
cargo-test-support = { path = "crates/cargo-test-support", version = "0.1.0" }

[[bin]]
name = "cargo"
Expand Down
2 changes: 2 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ jobs:
displayName: "Check rustfmt (cargo)"
- bash: cd crates/cargo-test-macro && cargo fmt --all -- --check
displayName: "Check rustfmt (cargo-test-macro)"
- bash: cd crates/cargo-test-support && cargo fmt --all -- --check
displayName: "Check rustfmt (cargo-test-support)"
- bash: cd crates/crates-io && cargo fmt --all -- --check
displayName: "Check rustfmt (crates-io)"
- bash: cd crates/resolver-tests && cargo fmt --all -- --check
Expand Down
3 changes: 3 additions & 0 deletions ci/azure-test-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ steps:
# fix the link errors.
- bash: cargo test --features 'deny-warnings curl/force-system-lib-on-osx'
displayName: "cargo test"

- bash: cargo test -p cargo-test-support
displayName: "cargo test -p cargo-test-support"
5 changes: 1 addition & 4 deletions crates/cargo-test-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ pub fn cargo_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
TokenTree::from(Ident::new("let", span)),
TokenTree::from(Ident::new("_test_guard", span)),
TokenTree::from(Punct::new('=', Spacing::Alone)),
TokenTree::from(Ident::new("crate", span)),
TokenTree::from(Punct::new(':', Spacing::Joint)),
TokenTree::from(Punct::new(':', Spacing::Alone)),
TokenTree::from(Ident::new("support", span)),
TokenTree::from(Ident::new("cargo_test_support", span)),
TokenTree::from(Punct::new(':', Spacing::Joint)),
TokenTree::from(Punct::new(':', Spacing::Alone)),
TokenTree::from(Ident::new("paths", span)),
Expand Down
17 changes: 17 additions & 0 deletions crates/cargo-test-support/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "cargo-test-support"
version = "0.1.0"
authors = ["Alex Crichton <[email protected]>"]
edition = "2018"

[dependencies]
cargo = { path = "../.." }
filetime = "0.2"
flate2 = "1.0"
git2 = "0.10"
glob = "0.3"
lazy_static = "1.0"
remove_dir_all = "0.5"
serde_json = "1.0"
tar = "0.4"
url = "2.0"
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{basic_bin_manifest, main_file, project};
use std::env;
use std::process::Command;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Once;

use crate::support::{basic_bin_manifest, main_file, project};

pub fn disabled() -> bool {
// First, disable if `./configure` requested so.
match env::var("CFG_DISABLE_CROSS_TESTS") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ use some of the helper functions in this file to interact with the repository.
*/

use crate::{path2url, project, Project, ProjectBuilder};
use git2;
use std::fs::{self, File};
use std::io::prelude::*;
use std::path::{Path, PathBuf};

use git2;
use url::Url;

use crate::support::{path2url, project, Project, ProjectBuilder};

#[must_use]
pub struct RepoBuilder {
repo: git2::Repository,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::paths;
use std::env::consts::EXE_SUFFIX;
use std::path::{Path, PathBuf};

use crate::support::paths;

/// Used by `cargo install` tests to assert an executable binary
/// has been installed. Example usage:
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ use url::Url;

use self::paths::CargoPathExt;

#[macro_export]
macro_rules! t {
($e:expr) => {
match $e {
Expand Down Expand Up @@ -409,7 +410,7 @@ impl Project {
/// .with_stdout("bar\n")
/// .run();
pub fn process<T: AsRef<OsStr>>(&self, program: T) -> Execs {
let mut p = crate::support::process(program);
let mut p = process(program);
p.cwd(self.root());
execs().with_process_builder(p)
}
Expand Down Expand Up @@ -1425,7 +1426,7 @@ pub fn lines_match(expected: &str, mut actual: &str) -> bool {
actual.is_empty() || expected.ends_with("[..]")
}

#[cargo_test]
#[test]
fn lines_match_works() {
assert!(lines_match("a b", "a b"));
assert!(lines_match("a[..]b", "a b"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use filetime::{self, FileTime};
use lazy_static::lazy_static;
use std::cell::RefCell;
use std::collections::HashMap;
use std::env;
Expand All @@ -7,9 +9,6 @@ use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Mutex;

use filetime::{self, FileTime};
use lazy_static::lazy_static;

static CARGO_INTEGRATION_TEST_DIR: &str = "cit";

lazy_static! {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::registry::{self, alt_api_path};
use crate::{find_json_mismatch, lines_match};
use flate2::read::GzDecoder;
use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::io::{self, prelude::*, SeekFrom};
use std::path::{Path, PathBuf};

use crate::support::registry::{self, alt_api_path};
use crate::support::{find_json_mismatch, lines_match};

use flate2::read::GzDecoder;
use tar::Archive;

fn read_le_u32<R>(mut reader: R) -> io::Result<u32>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use std::collections::HashMap;
use std::fs::{self, File};
use std::io::prelude::*;
use std::path::{Path, PathBuf};

use crate::git::repo;
use crate::paths;
use cargo::sources::CRATES_IO_INDEX;
use cargo::util::Sha256;
use flate2::write::GzEncoder;
use flate2::Compression;
use std::collections::HashMap;
use std::fs::{self, File};
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use tar::{Builder, Header};
use url::Url;

use crate::support::git::repo;
use crate::support::paths;

/// Gets the path to the local index pretending to be crates.io. This is a Git repo
/// initialized with a `config.json` file pointing to `dl_path` for downloads
/// and `api_path` for uploads.
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::support::publish::validate_alt_upload;
use crate::support::registry::{self, Package};
use crate::support::{basic_manifest, git, paths, project};
use cargo_test_support::publish::validate_alt_upload;
use cargo_test_support::registry::{self, Package};
use cargo_test_support::{basic_manifest, git, paths, project};
use cargo::util::IntoUrl;
use std::fs::{self, File};
use std::io::Write;
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/bad_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::support::registry::Package;
use crate::support::{basic_manifest, project};
use cargo_test_support::registry::Package;
use cargo_test_support::{basic_manifest, project};

#[cargo_test]
fn bad1() {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/bad_manifest_path.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::support::{basic_bin_manifest, main_file, project};
use cargo_test_support::{basic_bin_manifest, main_file, project};

fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) {
let p = project()
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::support::is_nightly;
use crate::support::paths::CargoPathExt;
use crate::support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, project};
use cargo_test_support::is_nightly;
use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, project};

#[cargo_test]
fn cargo_bench_simple() {
Expand Down
15 changes: 7 additions & 8 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::env;
use std::fs::{self, File};
use std::io::prelude::*;

use crate::support::paths::{root, CargoPathExt};
use crate::support::registry::Package;
use crate::support::{
use cargo_test_support::paths::{root, CargoPathExt};
use cargo_test_support::registry::Package;
use cargo_test_support::{
basic_bin_manifest, basic_lib_manifest, basic_manifest, main_file, project, rustc_host,
sleep_ms, symlink_supported, Execs, ProjectBuilder,
sleep_ms, symlink_supported, Execs, ProjectBuilder, t,
};
use cargo::util::paths::dylib_path_envvar;

Expand Down Expand Up @@ -4541,7 +4540,7 @@ Caused by:

#[cargo_test]
fn tricky_pipelining() {
if !crate::support::is_nightly() {
if !cargo_test_support::is_nightly() {
return;
}

Expand Down Expand Up @@ -4571,7 +4570,7 @@ fn tricky_pipelining() {

#[cargo_test]
fn pipelining_works() {
if !crate::support::is_nightly() {
if !cargo_test_support::is_nightly() {
return;
}

Expand Down Expand Up @@ -4606,7 +4605,7 @@ fn pipelining_works() {

#[cargo_test]
fn pipelining_big_graph() {
if !crate::support::is_nightly() {
if !cargo_test_support::is_nightly() {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/build_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
use std::sync::Arc;
use std::thread;

use crate::support::paths;
use crate::support::{basic_manifest, project};
use cargo_test_support::paths;
use cargo_test_support::{basic_manifest, project};
use git2;

// Tests that HTTP auth is offered from `credential.helper`.
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/build_lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::support::{basic_bin_manifest, basic_manifest, project};
use cargo_test_support::{basic_bin_manifest, basic_manifest, project};

#[cargo_test]
fn build_lib_only() {
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/build_plan.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::support::registry::Package;
use crate::support::{basic_bin_manifest, basic_manifest, main_file, project};
use cargo_test_support::registry::Package;
use cargo_test_support::{basic_bin_manifest, basic_manifest, main_file, project};

#[cargo_test]
fn cargo_build_plan_simple() {
Expand Down
10 changes: 5 additions & 5 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use std::io;
use std::io::prelude::*;
use std::thread;

use crate::support::paths::CargoPathExt;
use crate::support::registry::Package;
use crate::support::{basic_manifest, cross_compile, project};
use crate::support::{rustc_host, sleep_ms, slow_cpu_multiplier};
use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::registry::Package;
use cargo_test_support::{basic_manifest, cross_compile, project};
use cargo_test_support::{rustc_host, sleep_ms, slow_cpu_multiplier};
use cargo::util::paths::remove_dir_all;

#[cargo_test]
Expand Down Expand Up @@ -2277,7 +2277,7 @@ fn flags_go_into_tests() {
#[cargo_test]
fn diamond_passes_args_only_once() {
// FIXME: when pipelining rides to stable, enable this test on all channels.
if !crate::support::is_nightly() {
if !cargo_test_support::is_nightly() {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/build_script_env.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::File;

use crate::support::project;
use crate::support::sleep_ms;
use cargo_test_support::project;
use cargo_test_support::sleep_ms;

#[cargo_test]
fn rerun_if_env_changes() {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/cache_messages.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::support::{clippy_is_available, is_nightly, process, project, registry::Package};
use cargo_test_support::{clippy_is_available, is_nightly, process, project, registry::Package};
use std::path::Path;

fn as_str(bytes: &[u8]) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_alias_config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::support::{basic_bin_manifest, project};
use cargo_test_support::{basic_bin_manifest, project};

#[cargo_test]
fn alias_incorrect_config_type() {
Expand Down
8 changes: 4 additions & 4 deletions tests/testsuite/cargo_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::str;

use crate::support::cargo_process;
use crate::support::paths::{self, CargoPathExt};
use crate::support::registry::Package;
use crate::support::{basic_bin_manifest, basic_manifest, cargo_exe, project, Project};
use cargo_test_support::cargo_process;
use cargo_test_support::paths::{self, CargoPathExt};
use cargo_test_support::registry::Package;
use cargo_test_support::{basic_bin_manifest, basic_manifest, cargo_exe, project, Project};
use cargo;

#[cfg_attr(windows, allow(dead_code))]
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_features.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::support::{project, registry};
use cargo_test_support::{project, registry};

#[cargo_test]
fn feature_required() {
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/cfg.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::fmt;
use std::str::FromStr;

use crate::support::registry::Package;
use crate::support::rustc_host;
use crate::support::{basic_manifest, project};
use cargo_test_support::registry::Package;
use cargo_test_support::rustc_host;
use cargo_test_support::{basic_manifest, project};
use cargo::util::{Cfg, CfgExpr};

macro_rules! c {
Expand Down
8 changes: 4 additions & 4 deletions tests/testsuite/check.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::fmt::{self, Write};

use crate::support::install::exe;
use crate::support::paths::CargoPathExt;
use crate::support::registry::Package;
use crate::support::{basic_manifest, project};
use cargo_test_support::install::exe;
use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::registry::Package;
use cargo_test_support::{basic_manifest, project};

#[cargo_test]
fn check_success() {
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/clean.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::env;

use crate::support::registry::Package;
use crate::support::{basic_bin_manifest, basic_manifest, git, main_file, project};
use cargo_test_support::registry::Package;
use cargo_test_support::{basic_bin_manifest, basic_manifest, git, main_file, project};

#[cargo_test]
fn cargo_clean_simple() {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/clippy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::support::{clippy_is_available, project, registry::Package};
use cargo_test_support::{clippy_is_available, project, registry::Package};

#[cargo_test]
// Clippy should never be considered fresh.
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/collisions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::support::{basic_manifest, project};
use cargo_test_support::{basic_manifest, project};
use std::env;

#[cargo_test]
Expand Down
Loading

0 comments on commit 9115b2c

Please sign in to comment.