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() {

0 commit comments

Comments
 (0)