use super::Cmd;
use crate::cmd;
use std::ffi::OsString;
#[test]
fn test_command_not_found_error() {
let result = cmd!("nonexistent_command_12345").no_echo().run();
assert!(result.is_err());
let error = result.unwrap_err();
assert!(error.message.contains("Failed to spawn command"));
assert!(error.message.contains("nonexistent_command_12345"));
let result = cmd!("this_command_definitely_does_not_exist")
.no_echo()
.run();
assert!(result.is_err());
let error = result.unwrap_err();
assert!(error.message.contains("Failed to spawn command"));
assert!(
error
.message
.contains("this_command_definitely_does_not_exist")
);
let result = cmd!("missing_command").no_echo().output();
assert!(result.is_err());
}
#[test]
fn test_exit_code_handling() {
for exit_code in [1, 2, 127, 255] {
let result = cmd!("sh", "-c", &format!("exit {}", exit_code))
.no_echo()
.run();
assert!(
result.is_err(),
"Exit code {} should result in error",
exit_code
);
}
let result = cmd!("sh", "-c", "exit 42").no_echo().output();
assert!(result.is_err());
let result = cmd!("sh", "-c", "exit 0").no_echo().run();
assert!(result.is_ok());
}
#[test]
fn test_empty_command_handling() {
let cmd = Cmd::new("");
assert_eq!(cmd.program, OsString::from(""));
let result = cmd.no_echo().run();
assert!(result.is_err());
let result = Cmd::new("").no_echo().output();
assert!(result.is_err());
}
#[test]
fn test_pipeline_error_propagation() {
let result = cmd!("nonexistent_command")
.pipe(cmd!("cat"))
.no_echo()
.run();
assert!(result.is_err());
let result = cmd!("echo", "test")
.pipe(cmd!("nonexistent_command"))
.no_echo()
.run();
assert!(result.is_err());
let result = cmd!("sh", "-c", "exit 1").pipe(cmd!("cat")).no_echo().run();
assert!(result.is_err());
}