always run unit tests for channels and tasks
This commit is contained in:
parent
42526cb15d
commit
891bced544
40
src/task.lua
40
src/task.lua
|
@ -383,14 +383,10 @@ _M.NOP = NOP
|
|||
----------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------
|
||||
-- Tests
|
||||
--
|
||||
-- To run:
|
||||
-- $ lua task.lua
|
||||
|
||||
local task = _M
|
||||
|
||||
local tests = {
|
||||
counter = function ()
|
||||
function test_counter()
|
||||
local done
|
||||
local function counter(c)
|
||||
local i = 1
|
||||
|
@ -412,9 +408,9 @@ local tests = {
|
|||
task.spawn(main)
|
||||
task.scheduler()
|
||||
assert(done)
|
||||
end,
|
||||
end
|
||||
|
||||
nonblocking_channel = function()
|
||||
function test_nonblocking_channel()
|
||||
local done
|
||||
local function main()
|
||||
local b = task.Channel:new()
|
||||
|
@ -434,9 +430,9 @@ local tests = {
|
|||
task.spawn(main)
|
||||
task.scheduler()
|
||||
assert(done)
|
||||
end,
|
||||
end
|
||||
|
||||
concurrent_send_and_recv = function()
|
||||
function test_concurrent_send_and_recv()
|
||||
local l = {}
|
||||
local function a(c, name)
|
||||
-- Blocking send and recv from the same process
|
||||
|
@ -465,9 +461,9 @@ local tests = {
|
|||
assert(l['a send'] > 0)
|
||||
assert(l['b recv'] > 0)
|
||||
assert(l['b send'] > 0)
|
||||
end,
|
||||
end
|
||||
|
||||
channels_from_a_coroutine = function()
|
||||
function test_channels_from_a_coroutine()
|
||||
local done
|
||||
local c = task.Channel:new()
|
||||
local function a()
|
||||
|
@ -489,9 +485,9 @@ local tests = {
|
|||
coroutine.resume(b_co)
|
||||
task.scheduler()
|
||||
assert(done)
|
||||
end,
|
||||
end
|
||||
|
||||
fibonacci = function()
|
||||
function test_fibonacci()
|
||||
local done
|
||||
local function fib(c)
|
||||
local x, y = 0, 1
|
||||
|
@ -519,9 +515,9 @@ local tests = {
|
|||
task.spawn(main, c)
|
||||
task.scheduler()
|
||||
assert(done)
|
||||
end,
|
||||
end
|
||||
|
||||
non_blocking_chanalt = function()
|
||||
function test_non_blocking_chanalt()
|
||||
local done
|
||||
local function main()
|
||||
local c = task.Channel:new()
|
||||
|
@ -545,11 +541,11 @@ local tests = {
|
|||
task.spawn(main)
|
||||
task.scheduler()
|
||||
assert(done)
|
||||
end,
|
||||
end
|
||||
|
||||
-- Apparently it's not really a Sieve of Eratosthenes:
|
||||
-- http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
|
||||
eratosthenes_sieve = function()
|
||||
function test_eratosthenes_sieve()
|
||||
local done
|
||||
local function counter(c)
|
||||
local i = 2
|
||||
|
@ -594,9 +590,9 @@ local tests = {
|
|||
task.spawn(main)
|
||||
task.scheduler()
|
||||
assert(done)
|
||||
end,
|
||||
end
|
||||
|
||||
channel_as_iterator = function()
|
||||
function test_channel_as_iterator()
|
||||
local done
|
||||
local function counter(c)
|
||||
local i = 2
|
||||
|
@ -617,7 +613,7 @@ local tests = {
|
|||
end
|
||||
end
|
||||
if _VERSION == "Lua 5.1" then
|
||||
-- sorry, this doesn't work in 5.1
|
||||
-- sorry, this test doesn't work in 5.1
|
||||
print('skipping... (5.1 unsupported)')
|
||||
done = true
|
||||
else
|
||||
|
@ -625,8 +621,6 @@ local tests = {
|
|||
task.scheduler()
|
||||
end
|
||||
assert(done)
|
||||
end,
|
||||
|
||||
}
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
Loading…
Reference in New Issue