Skip to content
Closed
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
34 changes: 11 additions & 23 deletions crates/terminal/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,7 @@ impl Terminal {
let task = match &mut self.task {
Some(task) => task,
None => {
if self.child_exited.is_none_or(|e| e.code() == Some(0)) {
if error_code.is_some() {
cx.emit(Event::CloseTerminal);
}
return;
Expand Down Expand Up @@ -2432,8 +2432,7 @@ mod tests {
);
}

// TODO should be tested on Linux too, but does not work there well
#[cfg(target_os = "macos")]
#[cfg(not(target_os = "windows"))]
#[gpui::test(iterations = 10)]
async fn test_terminal_eof(cx: &mut TestAppContext) {
cx.executor().allow_parking();
Expand Down Expand Up @@ -2466,38 +2465,27 @@ mod tests {
})
})
.detach();
cx.background_spawn(async move {
assert_eq!(
completion_rx.recv().await.unwrap(),
Some(ExitStatus::default()),
"EOF should result in the tty shell exiting successfully",
);
})
.detach();

let first_event = Event::Wakeup;
let wakeup = event_rx.recv().await.expect("No wakeup event received");
assert_eq!(wakeup, first_event, "Expected wakeup, got {wakeup:?}");
let _initial_event = event_rx.recv().await.expect("No initial event received");

// Send Ctrl-C
terminal.update(cx, |terminal, _| {
let success = terminal.try_keystroke(&Keystroke::parse("ctrl-c").unwrap(), false);
assert!(success, "Should have registered ctrl-c sequence");
});
smol::Timer::after(Duration::from_millis(100)).await;

// Send Ctrl-D
terminal.update(cx, |terminal, _| {
let success = terminal.try_keystroke(&Keystroke::parse("ctrl-d").unwrap(), false);
assert!(success, "Should have registered ctrl-d sequence");
});

let mut all_events = vec![first_event];
while let Ok(Ok(new_event)) = smol_timeout(Duration::from_secs(1), event_rx.recv()).await {
all_events.push(new_event.clone());
if new_event == Event::CloseTerminal {
break;
}
}
// Wait for terminal exit
let result = smol_timeout(Duration::from_millis(100), completion_rx.recv()).await;
assert!(
all_events.contains(&Event::CloseTerminal),
"EOF command sequence should have triggered a TTY terminal exit, but got events: {all_events:?}",
result.is_ok() && result.unwrap().unwrap().is_some(),
"EOF should result in the tty shell exiting",
);
}

Expand Down
Loading