diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 960812da00060a..5d780decbf2710 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -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; @@ -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(); @@ -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", ); }