From 6b9490bd72738c02b0d0962fdce6e1763d53e124 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy <roberto@inf.puc-rio.br> Date: Fri, 21 Jun 2019 10:21:07 -0300 Subject: Details in tests - Added a test for calling 'debug.traceback' after yields inside hooks. (Lua 5.3 seems to have a bug there.) - Removed test "repeat test with '__open' metamethod instead of a function", as the previous test already uses the '__open' metamethod. (It changed when functions were removed as possible to-be-closed variables). --- testes/coroutine.lua | 4 ++++ testes/locals.lua | 24 ++++++------------------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/testes/coroutine.lua b/testes/coroutine.lua index f2c0da8b..e04207c8 100644 --- a/testes/coroutine.lua +++ b/testes/coroutine.lua @@ -426,6 +426,10 @@ else while A==0 or B==0 do -- A ~= 0 when 'x' finishes (similar for 'B','y') if A==0 then turn = "A"; assert(T.resume(x)) end if B==0 then turn = "B"; assert(T.resume(y)) end + + -- check that traceback works correctly after yields inside hooks + debug.traceback(x) + debug.traceback(y) end assert(B // A == 7) -- fact(7) // fact(6) diff --git a/testes/locals.lua b/testes/locals.lua index dccda28f..a41b6f0e 100644 --- a/testes/locals.lua +++ b/testes/locals.lua @@ -517,27 +517,15 @@ do end assert(s == 35 and numopen == 0) - -- repeat test with '__open' metamethod instead of a function - local function open (x) - numopen = numopen + 1 - local state = setmetatable({x}, - {__close = function () numopen = numopen - 1 end}) - return - function (t) -- iteraction function - t[1] = t[1] - 1 - if t[1] > 0 then return t[1] end - end, - state, - nil, - state -- to-be-closed - end - local s = 0 for i in open(10) do - if (i < 5) then break end - s = s + i + for j in open(10) do + if i + j < 5 then goto endloop end + s = s + i + end end - assert(s == 35 and numopen == 0) + ::endloop:: + assert(s == 375 and numopen == 0) end print('OK') -- cgit v1.2.3-55-g6feb