diff options
| author | Lam Wei Lun <weilun.lam@gmail.com> | 2026-02-01 14:46:46 +0800 |
|---|---|---|
| committer | Lam Wei Lun <weilun.lam@gmail.com> | 2026-02-01 14:46:46 +0800 |
| commit | fcc9210aa32d671e16b392cf48546c4e2001ff8f (patch) | |
| tree | f8df9cdfe3d2f422a31ab62e6685c30814067760 /tests/std/test_thread.zc | |
| parent | aafd7e8739b14dd89b2e81148f2b07710f3c2c42 (diff) | |
Added detach/cancel and equality check for std/thread
Diffstat (limited to 'tests/std/test_thread.zc')
| -rw-r--r-- | tests/std/test_thread.zc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/std/test_thread.zc b/tests/std/test_thread.zc new file mode 100644 index 0000000..42fa82e --- /dev/null +++ b/tests/std/test_thread.zc @@ -0,0 +1,42 @@ +import "std/thread.zc" + +test "Thread Spawn and Join" { + "Testing thread spawn and join"; + + let spawn_result = Thread::spawn(fn(){ + "Running on a separate thread"; + }); + assert(spawn_result.is_ok(), "Thread spawn has failed"); + + let thr = spawn_result.unwrap(); + let join_result = thr.join(); + assert(join_result.is_ok(), "Thread join has failed"); +} + +test "Thread Spawn and Detach" { + "Testing thread spawn and detach"; + + let spawn_result = Thread::spawn(fn(){ + "Detached thread, this line might print later."; + }); + assert(spawn_result.is_ok(), "Thread spawn has failed"); + + let thr = spawn_result.unwrap(); + let detach_result = thr.detach(); + assert(detach_result.is_ok(), "Thread detach has failed"); +} + +test "Thread Spawn and Cancel" { + "Testing thread spawn and cancel"; + + let spawn_result = Thread::spawn(fn(){ + "Thread running indefinitely..."; + while true { + } + }); + assert(spawn_result.is_ok(), "Thread spawn has failed"); + + let thr = spawn_result.unwrap(); + let cancel_result = thr.cancel(); + assert(cancel_result.is_ok(), "Thread cancel has failed"); +} |
