summaryrefslogtreecommitdiff
path: root/tests/std
diff options
context:
space:
mode:
Diffstat (limited to 'tests/std')
-rw-r--r--tests/std/test_thread.zc42
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");
+}