diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index 40129e430..2c8c2c6fe 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -115,7 +115,6 @@ pub mod prelude { pub use crate::cargo_test; pub use crate::paths::CargoPathExt; pub use crate::ArgLineCommandExt; - pub use crate::CargoCommandExt; pub use crate::ChannelChangerCommandExt; pub use crate::TestEnvCommandExt; pub use snapbox::IntoData; @@ -598,11 +597,6 @@ pub fn main_file(println: &str, externed_deps: &[&str]) -> String { buf } -/// Path to the cargo binary -pub fn cargo_exe() -> PathBuf { - snapbox::cmd::cargo_bin("cargo") -} - /// This is the raw output from the process. /// /// This is similar to `std::process::Output`, however the `status` is @@ -1472,21 +1466,6 @@ impl TestEnvCommandExt for snapbox::cmd::Command { } } -/// Test the cargo command -pub trait CargoCommandExt { - fn cargo_ui() -> Self; -} - -impl CargoCommandExt for snapbox::cmd::Command { - fn cargo_ui() -> Self { - Self::new(cargo_exe()) - .with_assert(compare::assert_ui()) - .env("CARGO_TERM_COLOR", "always") - .env("CARGO_TERM_HYPERLINKS", "true") - .test_env() - } -} - /// Add a list of arguments as a line pub trait ArgLineCommandExt: Sized { fn arg_line(mut self, s: &str) -> Self { @@ -1524,15 +1503,6 @@ impl ArgLineCommandExt for snapbox::cmd::Command { } } -/// Run `cargo $arg_line`, see [`Execs`] -pub fn cargo_process(arg_line: &str) -> Execs { - let cargo = cargo_exe(); - let mut p = process(&cargo); - p.env("CARGO", cargo); - p.arg_line(arg_line); - execs().with_process_builder(p) -} - /// Run `git $arg_line`, see [`ProcessBuilder`] pub fn git_process(arg_line: &str) -> ProcessBuilder { let mut p = process("git"); diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 30d8f8765..39fad946d 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -6,6 +6,8 @@ use std::io::Read; use std::process::Stdio; use crate::prelude::*; +use crate::utils::cargo_exe; +use crate::utils::cargo_process; use crate::utils::tools; use cargo::core::compiler::UserIntent; use cargo::core::Shell; @@ -17,9 +19,8 @@ use cargo_test_support::paths::root; use cargo_test_support::registry::Package; use cargo_test_support::str; use cargo_test_support::{ - basic_bin_manifest, basic_lib_manifest, basic_manifest, cargo_exe, cargo_process, git, - is_nightly, main_file, paths, process, project, rustc_host, sleep_ms, symlink_supported, t, - Execs, ProjectBuilder, + basic_bin_manifest, basic_lib_manifest, basic_manifest, git, is_nightly, main_file, paths, + process, project, rustc_host, sleep_ms, symlink_supported, t, Execs, ProjectBuilder, }; use cargo_util::paths::dylib_path_envvar; diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 716c20019..c62170211 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -6,6 +6,7 @@ use std::io; use std::thread; use crate::prelude::*; +use crate::utils::cargo_exe; use crate::utils::cross_compile::{ can_run_on_host as cross_compile_can_run_on_host, disabled as cross_compile_disabled, }; @@ -14,9 +15,7 @@ use cargo_test_support::compare::assert_e2e; use cargo_test_support::paths::cargo_home; use cargo_test_support::registry::Package; use cargo_test_support::str; -use cargo_test_support::{ - basic_manifest, cargo_exe, cross_compile, is_coarse_mtime, project, project_in, -}; +use cargo_test_support::{basic_manifest, cross_compile, is_coarse_mtime, project, project_in}; use cargo_test_support::{git, rustc_host, sleep_ms, slow_cpu_multiplier, symlink_supported}; use cargo_util::paths::{self, remove_dir_all}; diff --git a/tests/testsuite/cargo_command.rs b/tests/testsuite/cargo_command.rs index a84e26f3a..e0fe47dd3 100644 --- a/tests/testsuite/cargo_command.rs +++ b/tests/testsuite/cargo_command.rs @@ -8,14 +8,14 @@ use std::process::Stdio; use std::str; use crate::prelude::*; +use crate::utils::cargo_exe; +use crate::utils::cargo_process; use crate::utils::tools::echo_subcommand; use cargo_test_support::basic_manifest; use cargo_test_support::registry::Package; use cargo_test_support::rustc_host; use cargo_test_support::str; -use cargo_test_support::{ - basic_bin_manifest, cargo_exe, cargo_process, paths, project, project_in_home, -}; +use cargo_test_support::{basic_bin_manifest, paths, project, project_in_home}; use cargo_util::paths::join_paths; fn path() -> Vec { @@ -601,7 +601,7 @@ fn overwrite_cargo_environment_variable() { // Create two other cargo binaries in the project root, one with the wrong // name and one with the right name. - let cargo_exe = cargo_test_support::cargo_exe(); + let cargo_exe = crate::utils::cargo_exe(); let wrong_name_path = p .root() .join(format!("wrong_name{}", env::consts::EXE_SUFFIX)); diff --git a/tests/testsuite/cargo_config/mod.rs b/tests/testsuite/cargo_config/mod.rs index 5346a7c02..be5cf7d35 100644 --- a/tests/testsuite/cargo_config/mod.rs +++ b/tests/testsuite/cargo_config/mod.rs @@ -10,7 +10,7 @@ use std::path::PathBuf; mod help; fn cargo_process(s: &str) -> cargo_test_support::Execs { - let mut p = cargo_test_support::cargo_process(s); + let mut p = crate::utils::cargo_process(s); // Clear out some of the environment added by the default cargo_process so // the tests don't need to deal with it. p.env_remove("CARGO_PROFILE_DEV_SPLIT_DEBUGINFO") diff --git a/tests/testsuite/concurrent.rs b/tests/testsuite/concurrent.rs index 5fb6dc157..1f8afa35c 100644 --- a/tests/testsuite/concurrent.rs +++ b/tests/testsuite/concurrent.rs @@ -8,7 +8,7 @@ use std::thread; use std::{env, str}; use crate::prelude::*; -use cargo_test_support::cargo_process; +use crate::utils::cargo_process; use cargo_test_support::git; use cargo_test_support::install::assert_has_installed_exe; use cargo_test_support::paths; diff --git a/tests/testsuite/credential_process.rs b/tests/testsuite/credential_process.rs index a373ea0a2..a775f829f 100644 --- a/tests/testsuite/credential_process.rs +++ b/tests/testsuite/credential_process.rs @@ -1,8 +1,9 @@ //! Tests for credential-process. use crate::prelude::*; +use crate::utils::cargo_process; use cargo_test_support::registry::{Package, TestRegistry}; -use cargo_test_support::{basic_manifest, cargo_process, paths, project, registry, str, Project}; +use cargo_test_support::{basic_manifest, paths, project, registry, str, Project}; fn toml_bin(proj: &Project, name: &str) -> String { proj.bin(name).display().to_string().replace('\\', "\\\\") diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs index 2406e7e98..4bd13860a 100644 --- a/tests/testsuite/directory.rs +++ b/tests/testsuite/directory.rs @@ -5,7 +5,7 @@ use std::fs; use std::str; use crate::prelude::*; -use cargo_test_support::cargo_process; +use crate::utils::cargo_process; use cargo_test_support::git; use cargo_test_support::paths; use cargo_test_support::registry::{cksum, Package}; diff --git a/tests/testsuite/error.rs b/tests/testsuite/error.rs index e948ba226..8898ff1ad 100644 --- a/tests/testsuite/error.rs +++ b/tests/testsuite/error.rs @@ -1,7 +1,7 @@ //! General error tests that don't belong anywhere else. use crate::prelude::*; -use cargo_test_support::cargo_process; +use crate::utils::cargo_process; #[cargo_test] fn internal_error() { diff --git a/tests/testsuite/feature_unification.rs b/tests/testsuite/feature_unification.rs index 278788a93..f5337336a 100644 --- a/tests/testsuite/feature_unification.rs +++ b/tests/testsuite/feature_unification.rs @@ -1,7 +1,8 @@ //! Tests for workspace feature unification. use crate::prelude::*; -use cargo_test_support::{basic_manifest, cargo_process, project, str}; +use crate::utils::cargo_process; +use cargo_test_support::{basic_manifest, project, str}; #[cargo_test] fn workspace_feature_unification() { diff --git a/tests/testsuite/features2.rs b/tests/testsuite/features2.rs index 8216f4055..ec121c78c 100644 --- a/tests/testsuite/features2.rs +++ b/tests/testsuite/features2.rs @@ -3,13 +3,14 @@ use std::fs::File; use crate::prelude::*; +use crate::utils::cargo_process; use crate::utils::cross_compile::disabled as cross_compile_disabled; use cargo_test_support::cross_compile::alternate; use cargo_test_support::paths; use cargo_test_support::publish::validate_crate_contents; use cargo_test_support::registry::{Dependency, Package}; use cargo_test_support::str; -use cargo_test_support::{basic_manifest, cargo_process, project, rustc_host, Project}; +use cargo_test_support::{basic_manifest, project, rustc_host, Project}; /// Switches Cargo.toml to use `resolver = "2"`. pub fn switch_to_resolver_2(p: &Project) { diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index 29b269938..837b03d42 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -2986,7 +2986,7 @@ fn cargo_env_changes() { ) .build(); - let cargo_exe = cargo_test_support::cargo_exe(); + let cargo_exe = crate::utils::cargo_exe(); let other_cargo_path = p.root().join(cargo_exe.file_name().unwrap()); std::fs::hard_link(&cargo_exe, &other_cargo_path).unwrap(); let other_cargo = || { diff --git a/tests/testsuite/global_cache_tracker.rs b/tests/testsuite/global_cache_tracker.rs index 1b7730d28..a42e054c8 100644 --- a/tests/testsuite/global_cache_tracker.rs +++ b/tests/testsuite/global_cache_tracker.rs @@ -15,6 +15,7 @@ use std::sync::OnceLock; use std::time::{Duration, SystemTime}; use crate::prelude::*; +use crate::utils::cargo_process; use cargo::core::global_cache_tracker::{self, DeferredGlobalLastUse, GlobalCacheTracker}; use cargo::util::cache_lock::CacheLockMode; use cargo::GlobalContext; @@ -22,8 +23,8 @@ use cargo_test_support::compare::assert_e2e; use cargo_test_support::paths; use cargo_test_support::registry::{Package, RegistryBuilder}; use cargo_test_support::{ - basic_manifest, cargo_process, execs, git, process, project, retry, sleep_ms, str, - thread_wait_timeout, Execs, Project, + basic_manifest, execs, git, process, project, retry, sleep_ms, str, thread_wait_timeout, Execs, + Project, }; use itertools::Itertools; diff --git a/tests/testsuite/help.rs b/tests/testsuite/help.rs index ae3a95a03..cec7d5513 100644 --- a/tests/testsuite/help.rs +++ b/tests/testsuite/help.rs @@ -5,9 +5,10 @@ use std::path::Path; use std::str::from_utf8; use crate::prelude::*; +use crate::utils::cargo_process; use cargo_test_support::registry::Package; use cargo_test_support::str; -use cargo_test_support::{basic_manifest, cargo_process, paths, project}; +use cargo_test_support::{basic_manifest, paths, project}; #[cargo_test] fn help() { diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index e0ce5294e..7197649b2 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -8,14 +8,13 @@ use std::path::PathBuf; use std::thread; use crate::prelude::*; +use crate::utils::cargo_process; use cargo_test_support::compare::assert_e2e; use cargo_test_support::cross_compile; use cargo_test_support::git; use cargo_test_support::registry::{self, Package}; use cargo_test_support::str; -use cargo_test_support::{ - basic_manifest, cargo_process, project, project_in, symlink_supported, t, -}; +use cargo_test_support::{basic_manifest, project, project_in, symlink_supported, t}; use cargo_util::{ProcessBuilder, ProcessError}; use crate::utils::cross_compile::disabled as cross_compile_disabled; diff --git a/tests/testsuite/install_upgrade.rs b/tests/testsuite/install_upgrade.rs index 037b4a4d8..4677309a4 100644 --- a/tests/testsuite/install_upgrade.rs +++ b/tests/testsuite/install_upgrade.rs @@ -7,14 +7,13 @@ use std::path::PathBuf; use std::sync::atomic::{AtomicUsize, Ordering}; use crate::prelude::*; +use crate::utils::cargo_process; use crate::utils::cross_compile::disabled as cross_compile_disabled; use cargo::core::PackageId; use cargo_test_support::install::exe; use cargo_test_support::paths; use cargo_test_support::registry::{self, Package}; -use cargo_test_support::{ - basic_manifest, cargo_process, cross_compile, execs, git, process, project, str, Execs, -}; +use cargo_test_support::{basic_manifest, cross_compile, execs, git, process, project, str, Execs}; fn pkg_maybe_yanked(name: &str, vers: &str, yanked: bool) { Package::new(name, vers) diff --git a/tests/testsuite/jobserver.rs b/tests/testsuite/jobserver.rs index 295040322..f66c01740 100644 --- a/tests/testsuite/jobserver.rs +++ b/tests/testsuite/jobserver.rs @@ -6,8 +6,8 @@ use std::process::Command; use std::thread; use crate::prelude::*; +use crate::utils::cargo_exe; use cargo_test_support::basic_bin_manifest; -use cargo_test_support::cargo_exe; use cargo_test_support::install::assert_has_installed_exe; use cargo_test_support::paths; use cargo_test_support::{project, rustc_host, str}; diff --git a/tests/testsuite/lockfile_path.rs b/tests/testsuite/lockfile_path.rs index 2718553e2..2c492e88b 100644 --- a/tests/testsuite/lockfile_path.rs +++ b/tests/testsuite/lockfile_path.rs @@ -5,12 +5,12 @@ use std::fs; use snapbox::str; use crate::prelude::*; +use crate::utils::cargo_process; use cargo_test_support::compare::assert_e2e; use cargo_test_support::install::assert_has_installed_exe; use cargo_test_support::registry::{Package, RegistryBuilder}; use cargo_test_support::{ - basic_bin_manifest, cargo_process, cargo_test, paths, project, symlink_supported, - ProjectBuilder, + basic_bin_manifest, cargo_test, paths, project, symlink_supported, ProjectBuilder, }; /////////////////////////////// //// Unstable feature tests start diff --git a/tests/testsuite/login.rs b/tests/testsuite/login.rs index 2cfcc8f86..f93618b37 100644 --- a/tests/testsuite/login.rs +++ b/tests/testsuite/login.rs @@ -4,7 +4,7 @@ use std::fs; use std::path::PathBuf; use crate::prelude::*; -use cargo_test_support::cargo_process; +use crate::utils::cargo_process; use cargo_test_support::paths; use cargo_test_support::registry::{self, RegistryBuilder}; use cargo_test_support::str; diff --git a/tests/testsuite/logout.rs b/tests/testsuite/logout.rs index 23cf1b9a7..283754b41 100644 --- a/tests/testsuite/logout.rs +++ b/tests/testsuite/logout.rs @@ -2,9 +2,10 @@ use super::login::check_token; use crate::prelude::*; +use crate::utils::cargo_process; use cargo_test_support::paths; use cargo_test_support::registry::TestRegistry; -use cargo_test_support::{cargo_process, registry, str}; +use cargo_test_support::{registry, str}; fn simple_logout_test(registry: &TestRegistry, reg: Option<&str>, flag: &str, note: &str) { let msg = reg.unwrap_or("crates-io"); diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 2eeb27827..bcff5664a 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -196,9 +196,9 @@ mod yank; use crate::prelude::*; pub mod prelude { + pub use crate::utils::ext::CargoCommandExt; pub use crate::utils::ext::CargoProjectExt; pub use cargo_test_support::prelude::*; - pub use cargo_test_support::CargoCommandExt; } #[cargo_test] diff --git a/tests/testsuite/new.rs b/tests/testsuite/new.rs index 43eccb062..b559b5887 100644 --- a/tests/testsuite/new.rs +++ b/tests/testsuite/new.rs @@ -4,7 +4,7 @@ use std::env; use std::fs::{self, File}; use crate::prelude::*; -use cargo_test_support::cargo_process; +use crate::utils::cargo_process; use cargo_test_support::paths; use cargo_test_support::str; diff --git a/tests/testsuite/old_cargos.rs b/tests/testsuite/old_cargos.rs index 64d4ba054..42d3e9c9c 100644 --- a/tests/testsuite/old_cargos.rs +++ b/tests/testsuite/old_cargos.rs @@ -13,9 +13,10 @@ use std::fs; use crate::prelude::*; +use crate::utils::cargo_exe; use cargo::CargoResult; use cargo_test_support::registry::{self, Dependency, Package}; -use cargo_test_support::{cargo_exe, execs, paths, process, project, rustc_host, str}; +use cargo_test_support::{execs, paths, process, project, rustc_host, str}; use cargo_util::{ProcessBuilder, ProcessError}; use semver::Version; diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 244477707..69ab788ea 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -4,11 +4,12 @@ use std::fs::{self, read_to_string, File}; use std::path::Path; use crate::prelude::*; +use crate::utils::cargo_process; use cargo_test_support::publish::validate_crate_contents; use cargo_test_support::registry::{self, Package}; use cargo_test_support::{ - basic_manifest, cargo_process, git, paths, project, rustc_host, str, symlink_supported, t, - Project, ProjectBuilder, + basic_manifest, git, paths, project, rustc_host, str, symlink_supported, t, Project, + ProjectBuilder, }; use flate2::read::GzDecoder; use tar::Archive; diff --git a/tests/testsuite/publish_lockfile.rs b/tests/testsuite/publish_lockfile.rs index 7d32bf038..1d3a095f4 100644 --- a/tests/testsuite/publish_lockfile.rs +++ b/tests/testsuite/publish_lockfile.rs @@ -3,9 +3,10 @@ use std::fs::File; use crate::prelude::*; +use crate::utils::cargo_process; use cargo_test_support::registry::Package; use cargo_test_support::{ - basic_manifest, cargo_process, git, paths, project, publish::validate_crate_contents, str, + basic_manifest, git, paths, project, publish::validate_crate_contents, str, }; fn pl_manifest(name: &str, version: &str, extra: &str) -> String { diff --git a/tests/testsuite/registry.rs b/tests/testsuite/registry.rs index 16e47e5f1..a2b2e9d85 100644 --- a/tests/testsuite/registry.rs +++ b/tests/testsuite/registry.rs @@ -7,8 +7,8 @@ use std::sync::Arc; use std::sync::Mutex; use crate::prelude::*; +use crate::utils::cargo_process; use cargo::core::SourceId; -use cargo_test_support::cargo_process; use cargo_test_support::paths; use cargo_test_support::registry::{ self, registry_path, Dependency, Package, RegistryBuilder, Response, TestRegistry, diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs index 0063e18cc..183d068d0 100644 --- a/tests/testsuite/rust_version.rs +++ b/tests/testsuite/rust_version.rs @@ -1,7 +1,8 @@ //! Tests for targets with `rust-version`. use crate::prelude::*; -use cargo_test_support::{cargo_process, project, registry::Package, str}; +use crate::utils::cargo_process; +use cargo_test_support::{project, registry::Package, str}; #[cargo_test] fn rust_version_satisfied() { diff --git a/tests/testsuite/rustup.rs b/tests/testsuite/rustup.rs index 7d47ca774..181a257e7 100644 --- a/tests/testsuite/rustup.rs +++ b/tests/testsuite/rustup.rs @@ -7,8 +7,9 @@ use std::fs; use std::path::{Path, PathBuf}; use crate::prelude::*; +use crate::utils::cargo_process; use cargo_test_support::paths::{home, root}; -use cargo_test_support::{cargo_process, process, project, str}; +use cargo_test_support::{process, project, str}; /// Helper to generate an executable. fn make_exe(dest: &Path, name: &str, contents: &str, env: &[(&str, PathBuf)]) -> PathBuf { @@ -207,7 +208,7 @@ fn custom_calls_other_cargo() { let custom_bin = root().join("custom-bin"); custom_bin.mkdir_p(); // `cargo` points to the real cargo. - let cargo_exe = cargo_test_support::cargo_exe(); + let cargo_exe = crate::utils::cargo_exe(); fs::hard_link(&cargo_exe, custom_bin.join(cargo_exe.file_name().unwrap())).unwrap(); // `rustc` executes the real rustc. real_rustc_wrapper(&custom_bin, "custom toolchain rustc running"); diff --git a/tests/testsuite/search.rs b/tests/testsuite/search.rs index a7ab0d988..e4de2cedb 100644 --- a/tests/testsuite/search.rs +++ b/tests/testsuite/search.rs @@ -3,8 +3,8 @@ use std::collections::HashSet; use crate::prelude::*; +use crate::utils::cargo_process; use cargo::util::cache_lock::CacheLockMode; -use cargo_test_support::cargo_process; use cargo_test_support::paths; use cargo_test_support::registry::{RegistryBuilder, Response}; use cargo_test_support::str; diff --git a/tests/testsuite/source_replacement.rs b/tests/testsuite/source_replacement.rs index aeee72bff..94fdfdca9 100644 --- a/tests/testsuite/source_replacement.rs +++ b/tests/testsuite/source_replacement.rs @@ -3,8 +3,9 @@ use std::fs; use crate::prelude::*; +use crate::utils::cargo_process; use cargo_test_support::registry::{Package, RegistryBuilder, TestRegistry}; -use cargo_test_support::{cargo_process, paths, project, str, t}; +use cargo_test_support::{paths, project, str, t}; fn setup_replacement(config: &str) -> TestRegistry { let crates_io = RegistryBuilder::new() diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index 17bc6f7f5..099a2bc7a 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -3,10 +3,9 @@ use std::fs; use crate::prelude::*; +use crate::utils::cargo_exe; use cargo_test_support::registry::Package; -use cargo_test_support::{ - basic_bin_manifest, basic_lib_manifest, basic_manifest, cargo_exe, project, str, -}; +use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, project, str}; use cargo_test_support::{cross_compile, paths}; use cargo_test_support::{rustc_host, rustc_host_env, sleep_ms}; use cargo_util::paths::dylib_path_envvar; @@ -3912,7 +3911,7 @@ test env_test ... ok .run(); // Check that `cargo test` propagates the environment's $CARGO - let cargo_exe = cargo_test_support::cargo_exe(); + let cargo_exe = cargo_exe(); let other_cargo_path = p.root().join(cargo_exe.file_name().unwrap()); std::fs::hard_link(&cargo_exe, &other_cargo_path).unwrap(); let stderr_other_cargo = format!( diff --git a/tests/testsuite/utils/ext.rs b/tests/testsuite/utils/ext.rs index f47a6d76e..19bc17733 100644 --- a/tests/testsuite/utils/ext.rs +++ b/tests/testsuite/utils/ext.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use cargo_test_support::{ArgLineCommandExt, Execs, Project}; +use cargo_test_support::{compare, ArgLineCommandExt, Execs, Project, TestEnvCommandExt}; pub trait CargoProjectExt { /// Creates a `ProcessBuilder` to run cargo. @@ -32,3 +32,18 @@ impl CargoProjectExt for Project { pub fn cargo_exe() -> PathBuf { snapbox::cmd::cargo_bin!("cargo").to_path_buf() } + +/// Test the cargo command +pub trait CargoCommandExt { + fn cargo_ui() -> Self; +} + +impl CargoCommandExt for snapbox::cmd::Command { + fn cargo_ui() -> Self { + Self::new(cargo_exe()) + .with_assert(compare::assert_ui()) + .env("CARGO_TERM_COLOR", "always") + .env("CARGO_TERM_HYPERLINKS", "true") + .test_env() + } +} diff --git a/tests/testsuite/utils/mod.rs b/tests/testsuite/utils/mod.rs index aac92e00d..c068ea335 100644 --- a/tests/testsuite/utils/mod.rs +++ b/tests/testsuite/utils/mod.rs @@ -1,3 +1,21 @@ +use std::path::PathBuf; + +use cargo_test_support::{execs, process, ArgLineCommandExt, Execs}; + pub mod cross_compile; pub mod ext; pub mod tools; + +/// Run `cargo $arg_line`, see [`Execs`] +pub fn cargo_process(arg_line: &str) -> Execs { + let cargo = cargo_exe(); + let mut p = process(&cargo); + p.env("CARGO", cargo); + p.arg_line(arg_line); + execs().with_process_builder(p) +} + +/// Path to the cargo binary +pub fn cargo_exe() -> PathBuf { + snapbox::cmd::cargo_bin!("cargo").to_path_buf() +} diff --git a/tests/testsuite/version.rs b/tests/testsuite/version.rs index 8ec5765f2..9dd4e3a2c 100644 --- a/tests/testsuite/version.rs +++ b/tests/testsuite/version.rs @@ -1,7 +1,8 @@ //! Tests for displaying the cargo version. use crate::prelude::*; -use cargo_test_support::{cargo_process, project}; +use crate::utils::cargo_process; +use cargo_test_support::project; #[cargo_test] fn simple() {