#![cfg(all(windows, feature = "blocking"))]
pub mod helpers;
use std::time::Duration;
use conpty_oxide::blocking::Command;
use helpers::sync::Session;
use helpers::with_timeout;
const BUDGET: Duration = Duration::from_secs(30);
const ESC: u8 = 0x1b;
#[test]
fn echoed_text_comes_back_with_a_successful_status() {
with_timeout(BUDGET, || {
const MARKER: &str = "conpty-oxide-basic-echo";
let (output, status) =
Session::start(Command::new("cmd.exe").args(["/c", "echo", MARKER])).finish();
assert!(
output.contains(MARKER),
"the echoed marker is missing from the rendered output: {output:?}"
);
assert!(status.success(), "unexpected status: {status}");
assert_eq!(status.code(), 0);
});
}
#[test]
fn a_nonzero_exit_code_is_reported_verbatim() {
with_timeout(BUDGET, || {
let (_output, status) =
Session::start(Command::new("cmd.exe").args(["/c", "exit", "42"])).finish();
assert_eq!(status.code(), 42);
assert!(!status.success());
assert_ne!(status.code(), 259);
});
}
#[test]
fn the_output_is_a_virtual_terminal_stream() {
with_timeout(BUDGET, || {
let (bytes, status) =
Session::start(Command::new("cmd.exe").args(["/c", "echo", "vt"])).finish_raw();
assert!(
bytes.contains(&ESC),
"no escape sequences in the output, so this was not a pseudoconsole: {:?}",
String::from_utf8_lossy(&bytes)
);
assert!(status.success());
});
}