diff options
Diffstat (limited to '')
-rw-r--r-- | tests/func_is_string.lua | 46 |
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 @@ | |||
1 | local lanes = require "lanes" | 1 | local lanes = require "lanes".configure() |
2 | 2 | ||
3 | -- Lua 5.4 specific: | 3 | -- Lua 5.4+ specific: |
4 | if _VERSION >= "Lua 5.4" then | 4 | if _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) | ||
19 | end | 18 | end |
20 | 19 | ||
20 | -- TEST: a string with a parse error is handled properly | ||
21 | do | ||
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) | ||
27 | end | ||
21 | 28 | ||
22 | local options = {globals = { b = 666 }} | 29 | -- TEST: lane executes fine, raises the expected error |
23 | 30 | do | |
24 | local gen1 = lanes.gen("*", { name = 'auto' }, "return true, error('bob')") | 31 | local g = lanes.gen("*", { name = 'auto' }, "return true, error('bob')") |
25 | 32 | fibLane = g() | |
26 | fibLane = gen1() | 33 | lanes.sleep(0.1) |
27 | lanes.sleep(0.1) | 34 | assert(fibLane.status == "error") |
28 | print(fibLane, fibLane.status) | 35 | local _r, _err, _stk = fibLane:join() |
29 | local _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)) |
30 | assert(_r == nil, "got " .. tostring(_r) .. " " .. tostring(_err) .. " " .. tostring(_stk)) | 37 | end |
31 | |||
32 | local gen2 = lanes.gen(options, { name = 'auto' }, "return b") | ||
33 | local retLane1, retLane2 = gen2(), gen2() | ||
34 | 38 | ||
35 | print( retLane1[1], retLane2[1]) | 39 | -- TEST: lanes execute and return the expected value obtained from the provided globals |
36 | assert(retLane1[1] == 666 and retLane2[1] == 666) | 40 | do |
37 | print "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) | ||
45 | end | ||