diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-21 10:21:07 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-21 10:21:07 -0300 |
commit | 6b9490bd72738c02b0d0962fdce6e1763d53e124 (patch) | |
tree | f5d2d40e6fbd3d8457988b0d4d09b48f9f33ccf9 /testes | |
parent | e4b02ca8e48b499c57dd3e5882d18145db60fd4c (diff) | |
download | lua-6b9490bd72738c02b0d0962fdce6e1763d53e124.tar.gz lua-6b9490bd72738c02b0d0962fdce6e1763d53e124.tar.bz2 lua-6b9490bd72738c02b0d0962fdce6e1763d53e124.zip |
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).
Diffstat (limited to 'testes')
-rw-r--r-- | testes/coroutine.lua | 4 | ||||
-rw-r--r-- | 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 | |||
426 | while A==0 or B==0 do -- A ~= 0 when 'x' finishes (similar for 'B','y') | 426 | while A==0 or B==0 do -- A ~= 0 when 'x' finishes (similar for 'B','y') |
427 | if A==0 then turn = "A"; assert(T.resume(x)) end | 427 | if A==0 then turn = "A"; assert(T.resume(x)) end |
428 | if B==0 then turn = "B"; assert(T.resume(y)) end | 428 | if B==0 then turn = "B"; assert(T.resume(y)) end |
429 | |||
430 | -- check that traceback works correctly after yields inside hooks | ||
431 | debug.traceback(x) | ||
432 | debug.traceback(y) | ||
429 | end | 433 | end |
430 | 434 | ||
431 | assert(B // A == 7) -- fact(7) // fact(6) | 435 | 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 | |||
517 | end | 517 | end |
518 | assert(s == 35 and numopen == 0) | 518 | assert(s == 35 and numopen == 0) |
519 | 519 | ||
520 | -- repeat test with '__open' metamethod instead of a function | ||
521 | local function open (x) | ||
522 | numopen = numopen + 1 | ||
523 | local state = setmetatable({x}, | ||
524 | {__close = function () numopen = numopen - 1 end}) | ||
525 | return | ||
526 | function (t) -- iteraction function | ||
527 | t[1] = t[1] - 1 | ||
528 | if t[1] > 0 then return t[1] end | ||
529 | end, | ||
530 | state, | ||
531 | nil, | ||
532 | state -- to-be-closed | ||
533 | end | ||
534 | |||
535 | local s = 0 | 520 | local s = 0 |
536 | for i in open(10) do | 521 | for i in open(10) do |
537 | if (i < 5) then break end | 522 | for j in open(10) do |
538 | s = s + i | 523 | if i + j < 5 then goto endloop end |
524 | s = s + i | ||
525 | end | ||
539 | end | 526 | end |
540 | assert(s == 35 and numopen == 0) | 527 | ::endloop:: |
528 | assert(s == 375 and numopen == 0) | ||
541 | end | 529 | end |
542 | 530 | ||
543 | print('OK') | 531 | print('OK') |