use flash_watcher::CommandRunner;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_command_runner_new() {
let cmd = vec!["cargo".to_string(), "test".to_string()];
let runner = CommandRunner::new(cmd.clone(), true, false);
assert_eq!(runner.command, cmd);
assert!(runner.restart);
assert!(!runner.clear);
assert!(runner.current_process.is_none());
}
#[test]
fn test_command_runner_dry_run_empty_command() {
let mut runner = CommandRunner::new(vec![], false, false);
let result = runner.dry_run();
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("Empty command"));
}
#[test]
fn test_command_runner_dry_run_success() {
let mut runner =
CommandRunner::new(vec!["echo".to_string(), "test".to_string()], false, false);
let result = runner.dry_run();
assert!(result.is_ok());
assert!(runner.current_process.is_none()); }
#[test]
fn test_command_runner_restart_mode() {
let mut runner =
CommandRunner::new(vec!["echo".to_string(), "test".to_string()], true, false);
let result = runner.dry_run();
assert!(result.is_ok());
assert!(runner.current_process.is_none());
let result = runner.dry_run();
assert!(result.is_ok());
assert!(runner.current_process.is_none());
}
#[test]
fn test_command_runner_run_simple_command() {
let mut runner =
CommandRunner::new(vec!["echo".to_string(), "hello".to_string()], false, false);
let result = runner.run();
assert!(result.is_ok());
assert!(runner.current_process.is_none()); }
#[test]
fn test_command_runner_run_with_restart() {
let mut runner =
CommandRunner::new(vec!["echo".to_string(), "hello".to_string()], true, false);
let result = runner.run();
assert!(result.is_ok());
}
#[test]
fn test_command_runner_run_with_clear() {
let mut runner =
CommandRunner::new(vec!["echo".to_string(), "hello".to_string()], false, true);
let result = runner.run();
assert!(result.is_ok());
}
#[test]
fn test_command_runner_run_invalid_command() {
let mut runner =
CommandRunner::new(vec!["nonexistent_command_12345".to_string()], false, false);
let result = runner.run();
assert!(result.is_ok());
}
#[test]
fn test_command_runner_run_failing_command() {
let mut runner = CommandRunner::new(
vec!["sh".to_string(), "-c".to_string(), "exit 1".to_string()],
false,
false,
);
let result = runner.run();
assert!(result.is_ok());
}
#[test]
fn test_command_runner_restart_with_multiple_runs() {
let mut runner =
CommandRunner::new(vec!["sleep".to_string(), "0.1".to_string()], true, false);
let result1 = runner.run();
assert!(result1.is_ok());
let result2 = runner.run();
assert!(result2.is_ok());
}
}