Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): Move 'cargo_home' from 'install' to 'paths' #14270

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions crates/cargo-test-support/src/install.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::paths;
use std::env::consts::EXE_SUFFIX;
use std::path::{Path, PathBuf};
use std::path::Path;

/// Used by `cargo install` tests to assert an executable binary
/// has been installed. Example usage:
/// ```no_run
/// use cargo_test_support::install::assert_has_installed_exe;
/// use cargo_test_support::install::cargo_home;
/// use cargo_test_support::paths;
///
/// assert_has_installed_exe(cargo_home(), "foo");
/// assert_has_installed_exe(paths::cargo_home(), "foo");
/// ```
#[track_caller]
pub fn assert_has_installed_exe<P: AsRef<Path>>(path: P, name: &'static str) {
Expand All @@ -24,10 +23,6 @@ fn check_has_installed_exe<P: AsRef<Path>>(path: P, name: &'static str) -> bool
path.as_ref().join("bin").join(exe(name)).is_file()
}

pub fn cargo_home() -> PathBuf {
paths::home().join(".cargo")
}

pub fn exe(name: &str) -> String {
format!("{}{}", name, EXE_SUFFIX)
}
2 changes: 1 addition & 1 deletion crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ pub trait TestEnvCommandExt: Sized {
self = self
.current_dir(&paths::root())
.env("HOME", paths::home())
.env("CARGO_HOME", paths::home().join(".cargo"))
.env("CARGO_HOME", paths::cargo_home())
.env("__CARGO_TEST_ROOT", paths::global_root())
// Force Cargo to think it's on the stable channel for all tests, this
// should hopefully not surprise us as we add cargo features over time and
Expand Down
4 changes: 4 additions & 0 deletions crates/cargo-test-support/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ pub fn home() -> PathBuf {
path
}

pub fn cargo_home() -> PathBuf {
home().join(".cargo")
}

pub trait CargoPathExt {
fn to_url(&self) -> url::Url;

Expand Down
6 changes: 3 additions & 3 deletions crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl RegistryBuilder {
/// Initializes the registry.
#[must_use]
pub fn build(self) -> TestRegistry {
let config_path = paths::home().join(".cargo/config.toml");
let config_path = paths::cargo_home().join("config.toml");
t!(fs::create_dir_all(config_path.parent().unwrap()));
let prefix = if let Some(alternative) = &self.alternative {
format!("{alternative}-")
Expand Down Expand Up @@ -391,7 +391,7 @@ impl RegistryBuilder {
}

if self.configure_token {
let credentials = paths::home().join(".cargo/credentials.toml");
let credentials = paths::cargo_home().join("credentials.toml");
match &registry.token {
Token::Plaintext(token) => {
if let Some(alternative) = &self.alternative {
Expand Down Expand Up @@ -1195,7 +1195,7 @@ impl Package {
/// Creates a new package builder.
/// Call `publish()` to finalize and build the package.
pub fn new(name: &str, vers: &str) -> Package {
let config = paths::home().join(".cargo/config.toml");
let config = paths::cargo_home().join("config.toml");
if !config.exists() {
init();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/binary_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use cargo_test_support::install::assert_has_installed_exe;
use cargo_test_support::install::assert_has_not_installed_exe;
use cargo_test_support::install::cargo_home;
use cargo_test_support::paths;
use cargo_test_support::prelude::*;
use cargo_test_support::project;
use cargo_test_support::str;
Expand Down Expand Up @@ -221,7 +221,7 @@ Hello, crabs!
.masquerade_as_nightly_cargo(&["different-binary-name"])
.run();

assert_has_installed_exe(cargo_home(), "007bar");
assert_has_installed_exe(paths::cargo_home(), "007bar");

p.cargo("uninstall")
.with_stderr_data(str![[r#"
Expand All @@ -231,7 +231,7 @@ Hello, crabs!
.masquerade_as_nightly_cargo(&["different-binary-name"])
.run();

assert_has_not_installed_exe(cargo_home(), "007bar");
assert_has_not_installed_exe(paths::cargo_home(), "007bar");
}

#[cargo_test]
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::io;
use std::thread;

use cargo_test_support::compare::assert_e2e;
use cargo_test_support::install::cargo_home;
use cargo_test_support::paths::cargo_home;
use cargo_test_support::prelude::*;
use cargo_test_support::registry::Package;
use cargo_test_support::str;
Expand Down
13 changes: 7 additions & 6 deletions tests/testsuite/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use std::{env, str};

use cargo_test_support::cargo_process;
use cargo_test_support::git;
use cargo_test_support::install::{assert_has_installed_exe, cargo_home};
use cargo_test_support::install::assert_has_installed_exe;
use cargo_test_support::paths;
use cargo_test_support::prelude::*;
use cargo_test_support::registry::Package;
use cargo_test_support::str;
Expand Down Expand Up @@ -46,8 +47,8 @@ fn multiple_installs() {
execs().run_output(&a);
execs().run_output(&b);

assert_has_installed_exe(cargo_home(), "foo");
assert_has_installed_exe(cargo_home(), "bar");
assert_has_installed_exe(paths::cargo_home(), "foo");
assert_has_installed_exe(paths::cargo_home(), "bar");
}

#[cargo_test]
Expand Down Expand Up @@ -75,8 +76,8 @@ fn concurrent_installs() {
execs().run_output(&a);
execs().run_output(&b);

assert_has_installed_exe(cargo_home(), "foo");
assert_has_installed_exe(cargo_home(), "bar");
assert_has_installed_exe(paths::cargo_home(), "foo");
assert_has_installed_exe(paths::cargo_home(), "bar");
}

#[cargo_test]
Expand Down Expand Up @@ -104,7 +105,7 @@ fn one_install_should_be_bad() {
execs().run_output(&a);
execs().run_output(&b);

assert_has_installed_exe(cargo_home(), "foo");
assert_has_installed_exe(paths::cargo_home(), "foo");
}

#[cargo_test]
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/features2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::fs::File;

use cargo_test_support::cross_compile::{self, alternate};
use cargo_test_support::install::cargo_home;
use cargo_test_support::paths;
use cargo_test_support::prelude::*;
use cargo_test_support::publish::validate_crate_contents;
use cargo_test_support::registry::{Dependency, Package};
Expand Down Expand Up @@ -2208,8 +2208,8 @@ fn minimal_download() {
.build();

let clear = || {
cargo_home().join("registry/cache").rm_rf();
cargo_home().join("registry/src").rm_rf();
paths::cargo_home().join("registry/cache").rm_rf();
paths::cargo_home().join("registry/src").rm_rf();
p.build_dir().rm_rf();
};

Expand Down
Loading