aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/func_is_string.lua46
1 files changed, 27 insertions, 19 deletions
diff --git a/tests/func_is_string.lua b/tests/func_is_string.lua
index 3c91603..3378a91 100644
--- a/tests/func_is_string.lua
+++ b/tests/func_is_string.lua
@@ -1,6 +1,6 @@
1local lanes = require "lanes" 1local lanes = require "lanes".configure()
2 2
3-- Lua 5.4 specific: 3-- Lua 5.4+ specific:
4if _VERSION >= "Lua 5.4" then 4if _VERSION >= "Lua 5.4" then
5 -- go through a string so that the script we are in doesn't trigger a parse error with older Lua 5 -- go through a string so that the script we are in doesn't trigger a parse error with older Lua
6 local res = assert(load [[ 6 local res = assert(load [[
@@ -14,24 +14,32 @@ if _VERSION >= "Lua 5.4" then
14 ]])() 14 ]])()
15 -- when the do...end block is exited, the to-be-closed variable h is closed, which internally calls h:join() 15 -- when the do...end block is exited, the to-be-closed variable h is closed, which internally calls h:join()
16 -- therefore the status of the lane should be "done" 16 -- therefore the status of the lane should be "done"
17 assert(res == "done") 17 assert(res == "done", "got " .. tostring(res))
18 print("close result:", res)
19end 18end
20 19
20-- TEST: a string with a parse error is handled properly
21do
22 -- the generator does not compile the string yet
23 local g = lanes.gen("*", { name = 'auto' }, "retrun true")
24 -- invoking the generator compiles the string
25 local s, r = pcall(g)
26 assert(s == false and type(r) == 'string' and string.find(r, "error when parsing lane function code"), "got " .. r)
27end
21 28
22local options = {globals = { b = 666 }} 29-- TEST: lane executes fine, raises the expected error
23 30do
24local gen1 = lanes.gen("*", { name = 'auto' }, "return true, error('bob')") 31 local g = lanes.gen("*", { name = 'auto' }, "return true, error('bob')")
25 32 fibLane = g()
26fibLane = gen1() 33 lanes.sleep(0.1)
27lanes.sleep(0.1) 34 assert(fibLane.status == "error")
28print(fibLane, fibLane.status) 35 local _r, _err, _stk = fibLane:join()
29local _r, _err, _stk = fibLane:join() 36 assert(_r == nil and _err == [[[string "return true, error('bob')"]:1: bob]], "got " .. tostring(_r) .. " " .. tostring(_err) .. " " .. tostring(_stk))
30assert(_r == nil, "got " .. tostring(_r) .. " " .. tostring(_err) .. " " .. tostring(_stk)) 37end
31
32local gen2 = lanes.gen(options, { name = 'auto' }, "return b")
33local retLane1, retLane2 = gen2(), gen2()
34 38
35print( retLane1[1], retLane2[1]) 39-- TEST: lanes execute and return the expected value obtained from the provided globals
36assert(retLane1[1] == 666 and retLane2[1] == 666) 40do
37print "TEST OK" 41 local options = {globals = { b = 666 }}
42 local g = lanes.gen(options, { name = 'auto' }, "return b")
43 local retLane1, retLane2 = g(), g()
44 assert(retLane1[1] == 666 and retLane2[1] == 666)
45end