Skip to content

Commit 627d924

Browse files
committed
Use temp-env to prevent the modification of shared state in tests
1 parent 469c0c0 commit 627d924

3 files changed

Lines changed: 67 additions & 8 deletions

File tree

Cargo.lock

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ureq = "2"
3232
hostname = "0.4"
3333

3434
[dev-dependencies]
35+
temp-env = "0.3"
3536

3637
[profile.release]
3738
opt-level = 3

src/config.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,18 @@ history_days = 90
201201

202202
#[test]
203203
fn test_claude_config_dir_env_override() {
204-
std::env::set_var("CLAUDE_CONFIG_DIR", "/tmp/custom-claude");
205-
let dir = claude_config_dir().unwrap();
206-
std::env::remove_var("CLAUDE_CONFIG_DIR");
207-
assert_eq!(dir, PathBuf::from("/tmp/custom-claude"));
204+
temp_env::with_var("CLAUDE_CONFIG_DIR", Some("/tmp/custom-claude"), || {
205+
let dir = claude_config_dir().unwrap();
206+
assert_eq!(dir, PathBuf::from("/tmp/custom-claude"));
207+
});
208208
}
209209

210210
#[test]
211211
fn test_claude_config_dir_default() {
212-
std::env::remove_var("CLAUDE_CONFIG_DIR");
213-
let dir = claude_config_dir().unwrap();
214-
let home = dirs::home_dir().unwrap();
215-
assert_eq!(dir, home.join(".claude"));
212+
temp_env::with_var_unset("CLAUDE_CONFIG_DIR", || {
213+
let dir = claude_config_dir().unwrap();
214+
let home = dirs::home_dir().unwrap();
215+
assert_eq!(dir, home.join(".claude"));
216+
});
216217
}
217218
}

0 commit comments

Comments
 (0)