#[cfg(unix)]
mod unix_tests {
#[test]
fn test_unix_shell_detection() {
assert!(cfg!(unix), "This test should only run on Unix platforms");
assert!(
std::path::Path::new("/bin/sh").exists()
|| std::path::Path::new("/usr/bin/sh").exists(),
"Expected to find a shell at /bin/sh or /usr/bin/sh on Unix"
);
}
#[test]
fn test_unix_signals() {
use nix::sys::signal::{SigSet, Signal};
let mut set = SigSet::empty();
set.add(Signal::SIGTERM);
assert!(set.contains(Signal::SIGTERM));
assert!(!set.contains(Signal::SIGINT));
}
}
#[cfg(windows)]
mod windows_tests {
#[test]
fn test_windows_platform() {
assert!(
cfg!(windows),
"This test should only run on Windows platforms"
);
}
}
#[test]
fn test_process_creation() {
use std::process::Command;
let output = if cfg!(windows) {
Command::new("cmd").args(["/C", "echo hello"]).output()
} else {
Command::new("sh").args(["-c", "echo hello"]).output()
};
assert!(output.is_ok(), "Should be able to create a basic process");
if let Ok(output) = output {
let stdout = String::from_utf8_lossy(&output.stdout);
let expected = if cfg!(windows) {
"hello\r\n"
} else {
"hello\n"
};
assert!(stdout.contains("hello"), "Expected 'hello' in output");
assert!(
stdout.trim() == "hello" || stdout == expected,
"Output should be exactly 'hello' with optional newline formatting"
);
}
}
#[test]
fn test_environment_detection() {
if cfg!(unix) {
assert!(
std::path::Path::new("/").exists(),
"Root directory should exist on Unix"
);
} else if cfg!(windows) {
assert!(
std::path::Path::new("C:\\").exists() || std::path::Path::new("D:\\").exists(),
"Expected to find C: or D: drive on Windows"
);
}
}