Skip to content

Commit ec40e08

Browse files
committed
test: fix tests errors on macOS
1 parent 8167994 commit ec40e08

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

tests/cli.rs

+28-9
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,25 @@ fn set_command_global() -> Result<(), Box<dyn std::error::Error>> {
210210
.arg("--global");
211211
cmd.assert().success();
212212

213-
// Verify using a new shell instance
213+
// Verify using shell commands
214214
#[cfg(target_os = "windows")]
215215
{
216216
let output = std::process::Command::new("cmd")
217217
.args(&["/C", "reg", "query", "HKCU\\Environment", "/v", var_name])
218218
.output()?;
219-
let stdout = String::from_utf8_lossy(&output.stdout);
220-
assert!(stdout.contains(var_value));
219+
assert!(String::from_utf8_lossy(&output.stdout).contains(var_value));
221220
}
222221

223-
#[cfg(not(target_os = "windows"))]
222+
#[cfg(target_os = "macos")]
223+
{
224+
let output = std::process::Command::new("zsh")
225+
.args(&["-c", &format!("source ~/.zshrc 2>/dev/null || source ~/.bashrc 2>/dev/null; echo ${}", var_name)])
226+
.output()?;
227+
assert!(String::from_utf8_lossy(&output.stdout).contains(var_value),
228+
"Variable not found in shell output: {}", String::from_utf8_lossy(&output.stdout));
229+
}
230+
231+
#[cfg(all(not(target_os = "windows"), not(target_os = "macos")))]
224232
{
225233
let output = std::process::Command::new("bash")
226234
.args(&["-c", &format!("source ~/.bashrc && echo ${}", var_name)])
@@ -358,14 +366,25 @@ fn load_command_global() -> Result<(), Box<dyn std::error::Error>> {
358366
assert!(String::from_utf8_lossy(&output2.stdout).contains("Hello"));
359367
}
360368

361-
#[cfg(not(target_os = "windows"))]
369+
#[cfg(target_os = "macos")]
362370
{
363-
let output = std::process::Command::new("sh")
364-
.args(&["-c", "echo $GLOBAL_TEST_VAR $GLOBAL_TEST_VAR2"])
371+
// On macOS, we need to source both potential config files
372+
let output = std::process::Command::new("zsh")
373+
.args(&["-c", "source ~/.zshrc 2>/dev/null || source ~/.bashrc 2>/dev/null; echo $GLOBAL_TEST_VAR $GLOBAL_TEST_VAR2"])
374+
.output()?;
375+
let stdout = String::from_utf8_lossy(&output.stdout);
376+
assert!(stdout.contains("GlobalTest") && stdout.contains("Hello"),
377+
"Variables not found in shell output: {}", stdout);
378+
}
379+
380+
#[cfg(all(not(target_os = "windows"), not(target_os = "macos")))]
381+
{
382+
let output = std::process::Command::new("bash")
383+
.args(&["-c", "source ~/.bashrc && echo $GLOBAL_TEST_VAR $GLOBAL_TEST_VAR2"])
365384
.output()?;
366385
let stdout = String::from_utf8_lossy(&output.stdout);
367-
assert!(stdout.contains("GlobalTest"));
368-
assert!(stdout.contains("Hello"));
386+
assert!(stdout.contains("GlobalTest") && stdout.contains("Hello"),
387+
"Variables not found in shell output: {}", stdout);
369388
}
370389

371390
// Clean up

0 commit comments

Comments
 (0)