Skip to content

Commit b31577d

Browse files
committed
Auto merge of #14243 - epage:prelude, r=weihanglo
feat(test): Add cargo_test to test-support prelude ### What does this PR try to resolve? With where we are at with #14039, I was revisiting our test writing documentation. I was wanting to put more emphasis on rustdoc and found it would be helpful to talk about the concepts if a prelude was used instead of `extern crate`. ### How should we test and review this PR? Yes, this included some `use` clean ups in tangentially-related commit but its already painful enough walking through every test file, I didn't want to do it twice. ### Additional information
2 parents 916c5a4 + e2e2f31 commit b31577d

File tree

166 files changed

+298
-112
lines changed

Some content is hidden

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

166 files changed

+298
-112
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ features = [
237237

238238
[dev-dependencies]
239239
annotate-snippets = { workspace = true, features = ["testing-colors"] }
240-
cargo-test-macro.workspace = true
241240
cargo-test-support.workspace = true
242241
gix = { workspace = true, features = ["revision"] }
243242
same-file.workspace = true

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub mod registry;
7373
pub mod tools;
7474

7575
pub mod prelude {
76+
pub use crate::cargo_test;
7677
pub use crate::ArgLine;
7778
pub use crate::CargoCommand;
7879
pub use crate::ChannelChanger;

src/doc/contrib/src/tests/writing.md

Lines changed: 2 additions & 0 deletions

tests/build-std/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#![allow(clippy::disallowed_methods)]
2222

2323
use cargo_test_support::prelude::*;
24-
use cargo_test_support::*;
24+
use cargo_test_support::{basic_manifest, paths, project, rustc_host, str, Execs};
2525
use std::env;
2626
use std::path::Path;
2727

tests/testsuite/advanced_env.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! -Zadvanced-env tests
22
3+
use cargo_test_support::prelude::*;
34
use cargo_test_support::{paths, project, registry::Package};
45

56
#[cargo_test]

tests/testsuite/alt_registry.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//! Tests for alternative registries.
22
3+
use std::fs;
4+
35
use cargo_test_support::compare::assert_e2e;
46
use cargo_test_support::prelude::*;
57
use cargo_test_support::publish::validate_alt_upload;
68
use cargo_test_support::registry::{self, Package, RegistryBuilder};
79
use cargo_test_support::str;
810
use cargo_test_support::{basic_manifest, paths, project};
9-
use std::fs;
1011

1112
#[cargo_test]
1213
fn depend_on_alt_registry() {

tests/testsuite/artifact_dir.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//! Tests for --artifact-dir flag.
22
3+
use std::env;
4+
use std::fs;
5+
use std::path::Path;
6+
37
use cargo_test_support::prelude::*;
48
use cargo_test_support::sleep_ms;
59
use cargo_test_support::str;
610
use cargo_test_support::{basic_manifest, project};
7-
use std::env;
8-
use std::fs;
9-
use std::path::Path;
1011

1112
#[cargo_test]
1213
fn binary_with_debug() {

tests/testsuite/build.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
//! Tests for the `cargo build` command.
22
3+
use std::env;
4+
use std::fs;
5+
use std::io::Read;
6+
use std::process::Stdio;
7+
38
use cargo::{
49
core::compiler::CompileMode,
510
core::{Shell, Workspace},
@@ -17,10 +22,6 @@ use cargo_test_support::{
1722
tools, Execs, ProjectBuilder,
1823
};
1924
use cargo_util::paths::dylib_path_envvar;
20-
use std::env;
21-
use std::fs;
22-
use std::io::Read;
23-
use std::process::Stdio;
2425

2526
#[cargo_test]
2627
fn cargo_compile_simple() {

tests/testsuite/build_script.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
//! Tests for build.rs scripts.
22
3+
use std::env;
4+
use std::fs;
5+
use std::io;
6+
use std::thread;
7+
38
use cargo_test_support::compare::assert_e2e;
49
use cargo_test_support::install::cargo_home;
510
use cargo_test_support::paths::CargoPathExt;
@@ -12,10 +17,6 @@ use cargo_test_support::{
1217
};
1318
use cargo_test_support::{rustc_host, sleep_ms, slow_cpu_multiplier, symlink_supported};
1419
use cargo_util::paths::{self, remove_dir_all};
15-
use std::env;
16-
use std::fs;
17-
use std::io;
18-
use std::thread;
1920

2021
#[cargo_test]
2122
fn custom_build_script_failed() {

tests/testsuite/build_script_env.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Tests for build.rs rerun-if-env-changed and rustc-env
22
33
use cargo_test_support::basic_manifest;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::project;
56
use cargo_test_support::sleep_ms;
67
use cargo_test_support::str;

tests/testsuite/build_script_extra_link_arg.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// because MSVC link.exe just gives a warning on unknown flags (how helpful!),
55
// and other linkers will return an error.
66

7+
use cargo_test_support::prelude::*;
78
use cargo_test_support::registry::Package;
89
use cargo_test_support::str;
910
use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, project};

tests/testsuite/cache_lock.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
//! Tests for `CacheLock`.
22
3-
use crate::config::GlobalContextBuilder;
3+
use std::thread::JoinHandle;
4+
45
use cargo::util::cache_lock::{CacheLockMode, CacheLocker};
56
use cargo_test_support::paths::{self, CargoPathExt};
7+
use cargo_test_support::prelude::*;
68
use cargo_test_support::{retry, thread_wait_timeout, threaded_timeout};
7-
use std::thread::JoinHandle;
9+
10+
use crate::config::GlobalContextBuilder;
811

912
/// Helper to verify that it is OK to acquire the given lock (it shouldn't block).
1013
fn verify_lock_is_ok(mode: CacheLockMode) {

tests/testsuite/cache_messages.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//! Tests for caching compiler diagnostics.
22
3-
use super::messages::raw_rustc_output;
3+
use cargo_test_support::prelude::*;
44
use cargo_test_support::str;
55
use cargo_test_support::tools;
66
use cargo_test_support::{basic_manifest, is_coarse_mtime, project, registry::Package, sleep_ms};
77

8+
use super::messages::raw_rustc_output;
9+
810
fn as_str(bytes: &[u8]) -> &str {
911
std::str::from_utf8(bytes).expect("valid utf-8")
1012
}

tests/testsuite/cargo_alias_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::env;
44

5+
use cargo_test_support::prelude::*;
56
use cargo_test_support::str;
67
use cargo_test_support::tools::echo_subcommand;
78
use cargo_test_support::{basic_bin_manifest, project};

tests/testsuite/cargo_bench/no_keep_going/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use cargo_test_support::current_dir;
22
use cargo_test_support::file;
3+
use cargo_test_support::prelude::*;
34
use cargo_test_support::str;
45
use cargo_test_support::CargoCommand;
56
use cargo_test_support::Project;

tests/testsuite/cargo_command.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::str;
99

1010
use cargo_test_support::basic_manifest;
1111
use cargo_test_support::paths::CargoPathExt;
12+
use cargo_test_support::prelude::*;
1213
use cargo_test_support::registry::Package;
1314
use cargo_test_support::str;
1415
use cargo_test_support::tools::echo_subcommand;

tests/testsuite/cargo_env_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Tests for `[env]` config.
22
33
use cargo_test_support::basic_manifest;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::{basic_bin_manifest, project};
67

tests/testsuite/cargo_features.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Tests for `cargo-features` definitions.
22
3+
use cargo_test_support::prelude::*;
34
use cargo_test_support::registry::Package;
45
use cargo_test_support::str;
56
use cargo_test_support::{project, registry};

tests/testsuite/cargo_init/inherit_workspace_package_table/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_init/reserved_name/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use std::fs;
2+
13
use cargo_test_support::file;
24
use cargo_test_support::paths;
35
use cargo_test_support::prelude::*;
46
use cargo_test_support::str;
5-
use std::fs;
67

78
#[cargo_test]
89
fn case() {

tests/testsuite/cargo_new/add_members_to_non_workspace/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/add_members_to_workspace_format_previous_items/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/add_members_to_workspace_format_sorted/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/add_members_to_workspace_with_absolute_package_path/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/add_members_to_workspace_with_empty_members/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/add_members_to_workspace_with_exclude_list/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/add_members_to_workspace_with_members_glob/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/add_members_to_workspace_without_members/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/empty_name/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/inherit_workspace_lints/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/inherit_workspace_package_table/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_members/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_remove/avoid_empty_tables/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_remove/build/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_remove/dev/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_remove/dry_run/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_remove/gc_keep_used_patch/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::current_dir;
33
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
45
use cargo_test_support::str;
56
use cargo_test_support::CargoCommand;
67
use cargo_test_support::Project;

tests/testsuite/cargo_remove/gc_patch/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use cargo_test_support::compare::assert_ui;
33
use cargo_test_support::current_dir;
44
use cargo_test_support::file;
55
use cargo_test_support::git;
6+
use cargo_test_support::prelude::*;
67
use cargo_test_support::project;
78
use cargo_test_support::str;
89
use cargo_test_support::CargoCommand;

0 commit comments

Comments
 (0)