Skip to content

Commit 9115b2c

Browse files
committed
Extract support directory to its own crate
Extract out all our test support code to its own standalone crate so it can be shared between multiple test suites if necessary.
1 parent 4cbfd02 commit 9115b2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+268
-263
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ features = [
103103

104104
[dev-dependencies]
105105
cargo-test-macro = { path = "crates/cargo-test-macro", version = "0.1.0" }
106+
cargo-test-support = { path = "crates/cargo-test-support", version = "0.1.0" }
106107

107108
[[bin]]
108109
name = "cargo"

azure-pipelines.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ jobs:
5454
displayName: "Check rustfmt (cargo)"
5555
- bash: cd crates/cargo-test-macro && cargo fmt --all -- --check
5656
displayName: "Check rustfmt (cargo-test-macro)"
57+
- bash: cd crates/cargo-test-support && cargo fmt --all -- --check
58+
displayName: "Check rustfmt (cargo-test-support)"
5759
- bash: cd crates/crates-io && cargo fmt --all -- --check
5860
displayName: "Check rustfmt (crates-io)"
5961
- bash: cd crates/resolver-tests && cargo fmt --all -- --check

ci/azure-test-all.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ steps:
3131
# fix the link errors.
3232
- bash: cargo test --features 'deny-warnings curl/force-system-lib-on-osx'
3333
displayName: "cargo test"
34+
35+
- bash: cargo test -p cargo-test-support
36+
displayName: "cargo test -p cargo-test-support"

crates/cargo-test-macro/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ pub fn cargo_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
3333
TokenTree::from(Ident::new("let", span)),
3434
TokenTree::from(Ident::new("_test_guard", span)),
3535
TokenTree::from(Punct::new('=', Spacing::Alone)),
36-
TokenTree::from(Ident::new("crate", span)),
37-
TokenTree::from(Punct::new(':', Spacing::Joint)),
38-
TokenTree::from(Punct::new(':', Spacing::Alone)),
39-
TokenTree::from(Ident::new("support", span)),
36+
TokenTree::from(Ident::new("cargo_test_support", span)),
4037
TokenTree::from(Punct::new(':', Spacing::Joint)),
4138
TokenTree::from(Punct::new(':', Spacing::Alone)),
4239
TokenTree::from(Ident::new("paths", span)),

crates/cargo-test-support/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "cargo-test-support"
3+
version = "0.1.0"
4+
authors = ["Alex Crichton <alex@alexcrichton.com>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
cargo = { path = "../.." }
9+
filetime = "0.2"
10+
flate2 = "1.0"
11+
git2 = "0.10"
12+
glob = "0.3"
13+
lazy_static = "1.0"
14+
remove_dir_all = "0.5"
15+
serde_json = "1.0"
16+
tar = "0.4"
17+
url = "2.0"

tests/testsuite/support/cross_compile.rs renamed to crates/cargo-test-support/src/cross_compile.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
use crate::{basic_bin_manifest, main_file, project};
12
use std::env;
23
use std::process::Command;
34
use std::sync::atomic::{AtomicBool, Ordering};
45
use std::sync::Once;
56

6-
use crate::support::{basic_bin_manifest, main_file, project};
7-
87
pub fn disabled() -> bool {
98
// First, disable if `./configure` requested so.
109
match env::var("CFG_DISABLE_CROSS_TESTS") {

tests/testsuite/support/git.rs renamed to crates/cargo-test-support/src/git.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ use some of the helper functions in this file to interact with the repository.
3838
3939
*/
4040

41+
use crate::{path2url, project, Project, ProjectBuilder};
42+
use git2;
4143
use std::fs::{self, File};
4244
use std::io::prelude::*;
4345
use std::path::{Path, PathBuf};
44-
45-
use git2;
4646
use url::Url;
4747

48-
use crate::support::{path2url, project, Project, ProjectBuilder};
49-
5048
#[must_use]
5149
pub struct RepoBuilder {
5250
repo: git2::Repository,

tests/testsuite/support/install.rs renamed to crates/cargo-test-support/src/install.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
use crate::paths;
12
use std::env::consts::EXE_SUFFIX;
23
use std::path::{Path, PathBuf};
34

4-
use crate::support::paths;
5-
65
/// Used by `cargo install` tests to assert an executable binary
76
/// has been installed. Example usage:
87
///

tests/testsuite/support/mod.rs renamed to crates/cargo-test-support/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ use url::Url;
125125

126126
use self::paths::CargoPathExt;
127127

128+
#[macro_export]
128129
macro_rules! t {
129130
($e:expr) => {
130131
match $e {
@@ -409,7 +410,7 @@ impl Project {
409410
/// .with_stdout("bar\n")
410411
/// .run();
411412
pub fn process<T: AsRef<OsStr>>(&self, program: T) -> Execs {
412-
let mut p = crate::support::process(program);
413+
let mut p = process(program);
413414
p.cwd(self.root());
414415
execs().with_process_builder(p)
415416
}
@@ -1425,7 +1426,7 @@ pub fn lines_match(expected: &str, mut actual: &str) -> bool {
14251426
actual.is_empty() || expected.ends_with("[..]")
14261427
}
14271428

1428-
#[cargo_test]
1429+
#[test]
14291430
fn lines_match_works() {
14301431
assert!(lines_match("a b", "a b"));
14311432
assert!(lines_match("a[..]b", "a b"));

tests/testsuite/support/paths.rs renamed to crates/cargo-test-support/src/paths.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use filetime::{self, FileTime};
2+
use lazy_static::lazy_static;
13
use std::cell::RefCell;
24
use std::collections::HashMap;
35
use std::env;
@@ -7,9 +9,6 @@ use std::path::{Path, PathBuf};
79
use std::sync::atomic::{AtomicUsize, Ordering};
810
use std::sync::Mutex;
911

10-
use filetime::{self, FileTime};
11-
use lazy_static::lazy_static;
12-
1312
static CARGO_INTEGRATION_TEST_DIR: &str = "cit";
1413

1514
lazy_static! {

0 commit comments

Comments
 (0)