Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/support/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ impl PtyCapture {
drop(self.file);
let _ = self.done.recv_timeout(Duration::from_secs(1));
}

/// Closes the PTY and returns all output after the capture thread drains it.
pub(crate) fn finish(self) -> String {
drop(self.file);
self.done
.recv_timeout(Duration::from_secs(3))
.expect("PTY capture thread did not finish");
String::from_utf8_lossy(&self.buffer.lock().unwrap()).into_owned()
}
}

pub(crate) fn configure_pty_child(cmd: &mut Command, slave: &fs::File) {
Expand Down
6 changes: 4 additions & 2 deletions tests/support/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ pub(crate) fn run_binary_pty_with_custom_body(
cmd.env("NO_PROXY", "*");
configure_pty_child(&mut cmd, &pty.slave);
let mut child = cmd.spawn().expect("spawn fetch under PTY");
// Command keeps its configured stdio handles after spawning. Drop it so
// the parent does not keep the PTY slave open after the child exits.
drop(cmd);
drop(pty.slave);
let capture = start_pty_capture(&pty.master);
let status = wait_child(&mut child, Duration::from_secs(5))
Expand All @@ -301,9 +304,8 @@ pub(crate) fn run_binary_pty_with_custom_body(
"fetch exited with {status}; PTY output:\n{}",
capture.output()
);
let output = capture.output();
drop(pty.master);
capture.close();
let output = capture.finish();
(
output,
fs::read_to_string(less_args).ok(),
Expand Down
Loading