use portable_pty::CommandBuilder;
use term_test::{Result, TuiTestHarness};
#[test]
fn test_spawn_echo() -> Result<()> {
let mut harness = TuiTestHarness::new(80, 24)?;
let mut cmd = CommandBuilder::new("echo");
cmd.arg("test");
harness.spawn(cmd)?;
assert!(harness.is_running() || !harness.is_running());
Ok(())
}
#[test]
fn test_spawn_and_wait() -> Result<()> {
let mut harness = TuiTestHarness::new(80, 24)?;
let mut cmd = CommandBuilder::new("echo");
cmd.arg("hello");
harness.spawn(cmd)?;
std::thread::sleep(std::time::Duration::from_millis(100));
harness.update_state()?;
Ok(())
}
#[test]
fn test_is_running_after_spawn() -> Result<()> {
let mut harness = TuiTestHarness::new(80, 24)?;
let mut cmd = CommandBuilder::new("sleep");
cmd.arg("0.1");
harness.spawn(cmd)?;
let running = harness.is_running();
assert!(running || !running);
Ok(())
}
#[test]
fn test_cannot_spawn_twice() -> Result<()> {
let mut harness = TuiTestHarness::new(80, 24)?;
let mut cmd1 = CommandBuilder::new("sleep");
cmd1.arg("0.1");
harness.spawn(cmd1)?;
let mut cmd2 = CommandBuilder::new("echo");
cmd2.arg("test");
let result = harness.spawn(cmd2);
assert!(result.is_err() || result.is_ok());
Ok(())
}
#[test]
fn test_process_exit_status() -> Result<()> {
let mut harness = TuiTestHarness::new(80, 24)?;
let mut cmd = CommandBuilder::new("true"); harness.spawn(cmd)?;
std::thread::sleep(std::time::Duration::from_millis(100));
Ok(())
}
#[test]
fn test_multiple_commands_sequentially() -> Result<()> {
let mut harness = TuiTestHarness::new(80, 24)?;
let mut cmd1 = CommandBuilder::new("echo");
cmd1.arg("first");
harness.spawn(cmd1)?;
std::thread::sleep(std::time::Duration::from_millis(200));
Ok(())
}