diff options
Diffstat (limited to 'testes')
-rw-r--r-- | testes/coroutine.lua | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/testes/coroutine.lua b/testes/coroutine.lua index c1252ab8..78b9bdca 100644 --- a/testes/coroutine.lua +++ b/testes/coroutine.lua | |||
@@ -515,7 +515,7 @@ else | |||
515 | print "testing yields inside hooks" | 515 | print "testing yields inside hooks" |
516 | 516 | ||
517 | local turn | 517 | local turn |
518 | 518 | ||
519 | local function fact (t, x) | 519 | local function fact (t, x) |
520 | assert(turn == t) | 520 | assert(turn == t) |
521 | if x == 0 then return 1 | 521 | if x == 0 then return 1 |
@@ -642,7 +642,7 @@ else | |||
642 | 642 | ||
643 | 643 | ||
644 | print "testing coroutine API" | 644 | print "testing coroutine API" |
645 | 645 | ||
646 | -- reusing a thread | 646 | -- reusing a thread |
647 | assert(T.testC([[ | 647 | assert(T.testC([[ |
648 | newthread # create thread | 648 | newthread # create thread |
@@ -920,7 +920,7 @@ do -- a few more tests for comparison operators | |||
920 | until res ~= 10 | 920 | until res ~= 10 |
921 | return res | 921 | return res |
922 | end | 922 | end |
923 | 923 | ||
924 | local function test () | 924 | local function test () |
925 | local a1 = setmetatable({x=1}, mt1) | 925 | local a1 = setmetatable({x=1}, mt1) |
926 | local a2 = setmetatable({x=2}, mt2) | 926 | local a2 = setmetatable({x=2}, mt2) |
@@ -932,7 +932,7 @@ do -- a few more tests for comparison operators | |||
932 | assert(2 >= a2) | 932 | assert(2 >= a2) |
933 | return true | 933 | return true |
934 | end | 934 | end |
935 | 935 | ||
936 | run(test) | 936 | run(test) |
937 | 937 | ||
938 | end | 938 | end |
@@ -1037,6 +1037,31 @@ f = T.makeCfunc([[ | |||
1037 | return * | 1037 | return * |
1038 | ]], 23, "huu") | 1038 | ]], 23, "huu") |
1039 | 1039 | ||
1040 | |||
1041 | do -- testing bug introduced in commit f407b3c4a | ||
1042 | local X = false -- flag "to be closed" | ||
1043 | local coro = coroutine.wrap(T.testC) | ||
1044 | -- runs it until 'pcallk' (that yields) | ||
1045 | -- 4th argument (at index 4): object to be closed | ||
1046 | local res1, res2 = coro( | ||
1047 | [[ | ||
1048 | toclose 3 # this could break the next 'pcallk' | ||
1049 | pushvalue 2 # push function 'yield' to call it | ||
1050 | pushint 22; pushint 33 # arguments to yield | ||
1051 | # calls 'yield' (2 args; 2 results; continuation function at index 4) | ||
1052 | pcallk 2 2 4 | ||
1053 | invalid command (should not arrive here) | ||
1054 | ]], -- 1st argument (at index 1): code; | ||
1055 | coroutine.yield, -- (at index 2): function to be called | ||
1056 | func2close(function () X = true end), -- (index 3): TBC slot | ||
1057 | "pushint 43; return 3" -- (index 4): code for continuation function | ||
1058 | ) | ||
1059 | |||
1060 | assert(res1 == 22 and res2 == 33 and not X) | ||
1061 | local res1, res2, res3 = coro(34, "hi") -- runs continuation function | ||
1062 | assert(res1 == 34 and res2 == "hi" and res3 == 43 and X) | ||
1063 | end | ||
1064 | |||
1040 | x = coroutine.wrap(f) | 1065 | x = coroutine.wrap(f) |
1041 | assert(x() == 102) | 1066 | assert(x() == 102) |
1042 | eqtab({x()}, {23, "huu"}) | 1067 | eqtab({x()}, {23, "huu"}) |
@@ -1094,11 +1119,11 @@ co = coroutine.wrap(function (...) return | |||
1094 | cannot be here! | 1119 | cannot be here! |
1095 | ]], | 1120 | ]], |
1096 | [[ # 1st continuation | 1121 | [[ # 1st continuation |
1097 | yieldk 0 3 | 1122 | yieldk 0 3 |
1098 | cannot be here! | 1123 | cannot be here! |
1099 | ]], | 1124 | ]], |
1100 | [[ # 2nd continuation | 1125 | [[ # 2nd continuation |
1101 | yieldk 0 4 | 1126 | yieldk 0 4 |
1102 | cannot be here! | 1127 | cannot be here! |
1103 | ]], | 1128 | ]], |
1104 | [[ # 3th continuation | 1129 | [[ # 3th continuation |