Skip to content

Commit e8de9cc

Browse files
Set USERPROFILE in cargo home tests on Windows (#1814)
#1779 made cargo_home() read the home the way cargo does: HOME on Unix, USERPROFILE on Windows. The two crawler_cargo_e2e fallback tests still pointed only HOME at their temp dir, so on Windows the crawler found the runner's real ~/.cargo and both tests failed in the nightly CI run on main. Point the platform's home variable at the temp dir instead. Co-authored-by: Claude <noreply@anthropic.com>
1 parent ce11f43 commit e8de9cc

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

‎crates/socket-patch-core/tests/crawler_cargo_e2e.rs‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ use socket_patch_core::formats::cargo::manifest::package_name_version;
88

99
const ORG_PURL: &str = "pkg:cargo/serde@1.0.200";
1010

11+
/// The variable cargo reads the user home from: `HOME` on Unix,
12+
/// `USERPROFILE` on Windows (it ignores `HOME` there).
13+
const HOME_VAR: &str = if cfg!(windows) { "USERPROFILE" } else { "HOME" };
14+
1115
fn options_at(root: &Path) -> CrawlerOptions {
1216
CrawlerOptions {
1317
cwd: root.to_path_buf(),
@@ -143,9 +147,9 @@ async fn cargo_home_fallback_to_home_dot_cargo() {
143147
tokio::fs::create_dir_all(&stamp_dir).await.unwrap();
144148

145149
let prev_cargo = std::env::var("CARGO_HOME").ok();
146-
let prev_home = std::env::var("HOME").ok();
150+
let prev_home = std::env::var(HOME_VAR).ok();
147151
std::env::remove_var("CARGO_HOME");
148-
std::env::set_var("HOME", tmp.path());
152+
std::env::set_var(HOME_VAR, tmp.path());
149153

150154
let crawler = CargoCrawler;
151155
let opts = CrawlerOptions {
@@ -159,9 +163,9 @@ async fn cargo_home_fallback_to_home_dot_cargo() {
159163
std::env::set_var("CARGO_HOME", v);
160164
}
161165
if let Some(v) = prev_home {
162-
std::env::set_var("HOME", v);
166+
std::env::set_var(HOME_VAR, v);
163167
} else {
164-
std::env::remove_var("HOME");
168+
std::env::remove_var(HOME_VAR);
165169
}
166170

167171
// Exactly the one staged index dir — proves the fallback resolved to
@@ -198,9 +202,9 @@ async fn empty_cargo_home_falls_back_to_home_dot_cargo() {
198202
tokio::fs::create_dir_all(&stamp_dir).await.unwrap();
199203

200204
let prev_cargo = std::env::var("CARGO_HOME").ok();
201-
let prev_home = std::env::var("HOME").ok();
205+
let prev_home = std::env::var(HOME_VAR).ok();
202206
std::env::set_var("CARGO_HOME", "");
203-
std::env::set_var("HOME", tmp.path());
207+
std::env::set_var(HOME_VAR, tmp.path());
204208

205209
let crawler = CargoCrawler;
206210
let opts = CrawlerOptions {
@@ -215,8 +219,8 @@ async fn empty_cargo_home_falls_back_to_home_dot_cargo() {
215219
None => std::env::remove_var("CARGO_HOME"),
216220
}
217221
match prev_home {
218-
Some(v) => std::env::set_var("HOME", v),
219-
None => std::env::remove_var("HOME"),
222+
Some(v) => std::env::set_var(HOME_VAR, v),
223+
None => std::env::remove_var(HOME_VAR),
220224
}
221225

222226
assert_eq!(

0 commit comments

Comments
 (0)