From 4d475bd28063ec63029ac38db6979964aeffcef1 Mon Sep 17 00:00:00 2001 From: muou000 Date: Mon, 17 Nov 2025 12:32:29 +0800 Subject: [PATCH] test: add tests for process and session --- tests/process.rs | 24 ++++++++++++++++++++++++ tests/session.rs | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/tests/process.rs b/tests/process.rs index 5b10b34..b91eb0d 100644 --- a/tests/process.rs +++ b/tests/process.rs @@ -47,3 +47,27 @@ fn reap() { parent.exit(); assert!(Arc::ptr_eq(&init, &child.parent().unwrap())); } + +#[test] +fn thread_exit() { + let parent = init_proc(); + let child = parent.new_child(); + + child.add_thread(101); + child.add_thread(102); + + let mut threads = child.threads(); + threads.sort(); + assert_eq!(threads, vec![101, 102]); + + let last = child.exit_thread(101, 7); + assert!(!last); + assert_eq!(child.exit_code(), 7); + + child.group_exit(); + assert!(child.is_group_exited()); + + let last2 = child.exit_thread(102, 3); + assert!(last2); + assert_eq!(child.exit_code(), 7); +} \ No newline at end of file diff --git a/tests/session.rs b/tests/session.rs index 207d31b..71269ee 100644 --- a/tests/session.rs +++ b/tests/session.rs @@ -1,4 +1,5 @@ use std::sync::Arc; +use std::any::Any; use starry_process::init_proc; @@ -106,3 +107,26 @@ fn cleanup_groups() { assert!(session.process_groups().is_empty()); } + +#[test] +fn terminal_set_unset() { + let init = init_proc(); + let session = init.group().session(); + + let term: Arc = Arc::new(0u32); + + let ok = session.set_terminal_with(|| term.clone()); + assert!(ok); + + let ok2 = session.set_terminal_with(|| Arc::new(1u32)); + assert!(!ok2); + + let got = session.terminal().unwrap(); + assert!(Arc::ptr_eq(&got, &term)); + + let other: Arc = Arc::new(2u32); + assert!(!session.unset_terminal(&other)); + + assert!(session.unset_terminal(&term)); + assert!(session.terminal().is_none()); +} \ No newline at end of file