diff --git a/crates/thing-tui/src/terminal/guard_tests.rs b/crates/thing-tui/src/terminal/guard_tests.rs index c85d312..7e6e9b3 100644 --- a/crates/thing-tui/src/terminal/guard_tests.rs +++ b/crates/thing-tui/src/terminal/guard_tests.rs @@ -296,3 +296,17 @@ fn an_error_mid_draw_does_not_leave_the_synchronized_update_open() { let end = bytes.rfind("\x1b[?2026l").expect("the restore closes the open update"); assert!(end < bytes.rfind(LEAVE).unwrap(), "closed before the alternate screen is left"); } + +#[test] +fn dropping_one_guard_leaves_the_others_registered() { + let (kept, dropped) = (Shared::default(), Shared::default()); + let other = Terminal::start(dropped.clone(), false).unwrap(); + let live = guard(&kept); + drop(other); + let caught = catch_unwind(AssertUnwindSafe(move || { + let _live = live; + panic!("forced with a guard that outlived another"); + })); + assert!(caught.is_err()); + assert_eq!(count(&at_hand_over().expect("hook ran"), LEAVE), 1, "the surviving guard is still restored by the hook"); +}