Skip to content

Commit b0e515a

Browse files
committed
fix(test): Move 'cargo_home' from 'install' to 'paths'
This is used outside of `cargo install` contexts and this makes it more discoverable for those use cases.
1 parent dad331c commit b0e515a

File tree

14 files changed

+142
-143
lines changed

14 files changed

+142
-143
lines changed
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
use crate::paths;
21
use std::env::consts::EXE_SUFFIX;
3-
use std::path::{Path, PathBuf};
2+
use std::path::Path;
43

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

27-
pub fn cargo_home() -> PathBuf {
28-
paths::home().join(".cargo")
29-
}
30-
3126
pub fn exe(name: &str) -> String {
3227
format!("{}{}", name, EXE_SUFFIX)
3328
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ pub fn home() -> PathBuf {
110110
path
111111
}
112112

113+
pub fn cargo_home() -> PathBuf {
114+
home().join(".cargo")
115+
}
116+
113117
pub trait CargoPathExt {
114118
fn to_url(&self) -> url::Url;
115119

tests/testsuite/binary_name.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use cargo_test_support::install::assert_has_installed_exe;
44
use cargo_test_support::install::assert_has_not_installed_exe;
5-
use cargo_test_support::install::cargo_home;
5+
use cargo_test_support::paths;
66
use cargo_test_support::prelude::*;
77
use cargo_test_support::project;
88
use cargo_test_support::str;
@@ -221,7 +221,7 @@ Hello, crabs!
221221
.masquerade_as_nightly_cargo(&["different-binary-name"])
222222
.run();
223223

224-
assert_has_installed_exe(cargo_home(), "007bar");
224+
assert_has_installed_exe(paths::cargo_home(), "007bar");
225225

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

234-
assert_has_not_installed_exe(cargo_home(), "007bar");
234+
assert_has_not_installed_exe(paths::cargo_home(), "007bar");
235235
}
236236

237237
#[cargo_test]

tests/testsuite/build_script.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::io;
66
use std::thread;
77

88
use cargo_test_support::compare::assert_e2e;
9-
use cargo_test_support::install::cargo_home;
9+
use cargo_test_support::paths::cargo_home;
1010
use cargo_test_support::prelude::*;
1111
use cargo_test_support::registry::Package;
1212
use cargo_test_support::str;

tests/testsuite/concurrent.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use std::{env, str};
99

1010
use cargo_test_support::cargo_process;
1111
use cargo_test_support::git;
12-
use cargo_test_support::install::{assert_has_installed_exe, cargo_home};
12+
use cargo_test_support::install::assert_has_installed_exe;
13+
use cargo_test_support::paths;
1314
use cargo_test_support::prelude::*;
1415
use cargo_test_support::registry::Package;
1516
use cargo_test_support::str;
@@ -46,8 +47,8 @@ fn multiple_installs() {
4647
execs().run_output(&a);
4748
execs().run_output(&b);
4849

49-
assert_has_installed_exe(cargo_home(), "foo");
50-
assert_has_installed_exe(cargo_home(), "bar");
50+
assert_has_installed_exe(paths::cargo_home(), "foo");
51+
assert_has_installed_exe(paths::cargo_home(), "bar");
5152
}
5253

5354
#[cargo_test]
@@ -75,8 +76,8 @@ fn concurrent_installs() {
7576
execs().run_output(&a);
7677
execs().run_output(&b);
7778

78-
assert_has_installed_exe(cargo_home(), "foo");
79-
assert_has_installed_exe(cargo_home(), "bar");
79+
assert_has_installed_exe(paths::cargo_home(), "foo");
80+
assert_has_installed_exe(paths::cargo_home(), "bar");
8081
}
8182

8283
#[cargo_test]
@@ -104,7 +105,7 @@ fn one_install_should_be_bad() {
104105
execs().run_output(&a);
105106
execs().run_output(&b);
106107

107-
assert_has_installed_exe(cargo_home(), "foo");
108+
assert_has_installed_exe(paths::cargo_home(), "foo");
108109
}
109110

110111
#[cargo_test]

tests/testsuite/features2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::fs::File;
44

55
use cargo_test_support::cross_compile::{self, alternate};
6-
use cargo_test_support::install::cargo_home;
6+
use cargo_test_support::paths;
77
use cargo_test_support::prelude::*;
88
use cargo_test_support::publish::validate_crate_contents;
99
use cargo_test_support::registry::{Dependency, Package};
@@ -2208,8 +2208,8 @@ fn minimal_download() {
22082208
.build();
22092209

22102210
let clear = || {
2211-
cargo_home().join("registry/cache").rm_rf();
2212-
cargo_home().join("registry/src").rm_rf();
2211+
paths::cargo_home().join("registry/cache").rm_rf();
2212+
paths::cargo_home().join("registry/src").rm_rf();
22132213
p.build_dir().rm_rf();
22142214
};
22152215

0 commit comments

Comments
 (0)