#![cfg(windows)]
use std::time::Duration;
use rust_expect::Session;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn kill_after_exit_is_safe() {
let mut session = Session::spawn("cmd.exe", &["/c", "exit 0"])
.await
.expect("spawn cmd.exe");
session
.wait_timeout(Duration::from_secs(10))
.await
.expect("child should exit");
let first = session.kill();
let second = session.kill();
let _ = (first, second);
assert!(
!session.is_running(),
"child must report not-running post-exit"
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn kill_live_child_terminates_it() {
let mut session = Session::spawn("cmd.exe", &["/c", "pause"])
.await
.expect("spawn cmd.exe");
tokio::time::sleep(Duration::from_millis(150)).await;
session.kill().expect("kill of a live child should succeed");
let waited = session.wait_timeout(Duration::from_secs(10)).await;
assert!(
waited.is_ok(),
"wait after kill should resolve, got {waited:?}"
);
assert!(!session.is_running());
}
#[cfg(feature = "screen")]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn screen_ingests_conpty_escapes_without_panic() {
let mut session = Session::spawn("cmd.exe", &["/c", "exit 0"])
.await
.expect("spawn cmd.exe");
session.attach_screen();
session
.wait_timeout(Duration::from_secs(10))
.await
.expect("child should exit");
let screen = session.screen().expect("screen should be attached");
let guard = screen.lock().unwrap();
assert_eq!(guard.cols(), 80, "default screen width");
assert_eq!(guard.rows(), 24, "default screen height");
let _ = guard.text();
}
#[cfg(feature = "screen")]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn scrollback_api_is_wired_on_windows() {
use std::sync::{Arc, Mutex};
let mut session = Session::spawn("cmd.exe", &["/c", "exit 0"])
.await
.expect("spawn cmd.exe");
let scrolled: Arc<Mutex<Vec<String>>> = Arc::new(Mutex::new(Vec::new()));
let sink = Arc::clone(&scrolled);
session.attach_screen_with_scrollback(1000);
assert!(
session.on_screen_line_scrolled_out(move |row| {
sink.lock().unwrap().push(row.text());
}),
"callback registration should succeed on an attached scrollback screen"
);
session
.wait_timeout(Duration::from_secs(10))
.await
.expect("child should exit");
let full = session.screen().unwrap().lock().unwrap().full_text();
let _ = full;
}