chore: Moved remaining cargo_exe logic to testsuite

This commit is contained in:
Ross Sullivan 2025-06-25 22:54:47 +09:00
parent 15f755cefd
commit 30b6707135
No known key found for this signature in database
GPG Key ID: A7D198C212395322
34 changed files with 93 additions and 80 deletions

View File

@ -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");

View File

@ -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;

View File

@ -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};

View File

@ -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<PathBuf> {
@ -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));

View File

@ -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")

View File

@ -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;

View File

@ -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('\\', "\\\\")

View File

@ -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};

View File

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

View File

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

View File

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

View File

@ -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 = || {

View File

@ -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;

View File

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

View File

@ -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;

View File

@ -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)

View File

@ -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};

View File

@ -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

View File

@ -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;

View File

@ -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");

View File

@ -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]

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 {

View File

@ -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,

View File

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

View File

@ -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");

View File

@ -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;

View File

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

View File

@ -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!(

View File

@ -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()
}
}

View File

@ -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()
}

View File

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