From 276200225b5c158de2b4a6d86783b10ddf4049d5 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sun, 22 Jan 2023 17:06:35 -0500 Subject: [PATCH] Ensure threads get returned from task lib in unit tests --- src/tests/task/defer.luau | 5 +++++ src/tests/task/delay.luau | 5 +++++ src/tests/task/spawn.luau | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/src/tests/task/defer.luau b/src/tests/task/defer.luau index 11e164e..22ba647 100644 --- a/src/tests/task/defer.luau +++ b/src/tests/task/defer.luau @@ -1,3 +1,8 @@ +-- Deferring a task should return the thread that can then be cancelled + +local thread = task.defer(function() end) +assert(type(thread) == "thread", "Defer should return the thread spawned") + -- Deferred functions should run after other threads local flag: boolean = false diff --git a/src/tests/task/delay.luau b/src/tests/task/delay.luau index b5c9f2c..fa0327e 100644 --- a/src/tests/task/delay.luau +++ b/src/tests/task/delay.luau @@ -1,3 +1,8 @@ +-- Delaying a task should return the thread that can then be cancelled + +local thread = task.delay(0, function() end) +assert(type(thread) == "thread", "Delay should return the thread spawned") + -- Delayed functions should never run right away local flag: boolean = false diff --git a/src/tests/task/spawn.luau b/src/tests/task/spawn.luau index 99cb7bd..24f8c00 100644 --- a/src/tests/task/spawn.luau +++ b/src/tests/task/spawn.luau @@ -1,3 +1,8 @@ +-- Spawning a task should return the thread that can then be cancelled + +local thread = task.spawn(function() end) +assert(type(thread) == "thread", "Spawn should return the thread spawned") + -- Spawned functions should run right away local flag: boolean = false