Cotton code
75 lines · 2.4 KB · RustRaw
//! The pure halves of the supervisor. The pseudo-terminal itself is driven//! against `/bin/sh` in `tests/pty_supervisor.rs`, where a tokio runtime and a//! real child belong.use super::*;#[test]fn a_stop_gives_each_signal_ten_seconds_before_the_next() {    let schedule = StopSchedule::default();    assert_eq!(schedule.interrupt_grace, Duration::from_secs(10));    assert_eq!(schedule.terminate_grace, Duration::from_secs(10));}#[test]fn eio_is_a_hangup_because_that_is_what_macos_says_when_the_child_closed_the_slave() {    let eio = std::io::Error::from_raw_os_error(libc::EIO);    assert!(is_hangup(&eio));    let eof = std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "the far side went");    assert!(is_hangup(&eof));}#[test]fn an_error_that_is_not_a_hangup_is_not_read_as_one() {    let interrupted = std::io::Error::from_raw_os_error(libc::EINTR);    assert!(!is_hangup(&interrupted));    let denied = std::io::Error::from(std::io::ErrorKind::PermissionDenied);    assert!(!is_hangup(&denied));}#[test]fn this_process_is_alive_and_pid_zero_is_not_a_process_we_own() {    let mine = std::process::id();    assert!(alive(mine));}#[tokio::test]async fn a_plan_with_no_program_is_refused_by_name_rather_than_by_a_panic() {    let (output, _receiver) = mpsc::unbounded_channel();    let error = PtySession::spawn(        &SpawnPlan {            argv: Vec::new(),            env: BTreeMap::new(),            cwd: "/".to_string(),            cols: 80,            rows: 24,        },        output,    )    .expect_err("an empty argv is refused");    assert!(        matches!(error, PtyError::Spawn { .. }),        "an empty argv names itself — got {error}"    );}#[tokio::test]async fn a_program_this_mac_does_not_have_names_the_program_and_the_directory() {    let (output, _receiver) = mpsc::unbounded_channel();    let error = PtySession::spawn(        &SpawnPlan {            argv: vec!["/nonexistent/cotton-session-host-test-binary".to_string()],            env: BTreeMap::new(),            cwd: "/".to_string(),            cols: 80,            rows: 24,        },        output,    )    .expect_err("a missing program is refused");    let said = error.to_string();    assert!(        said.contains("/nonexistent/cotton-session-host-test-binary") && said.contains(" / "),        "the refusal names what it tried to run and where — got {said}"    );}