diff options
Diffstat (limited to 'testes')
-rw-r--r-- | testes/locals.lua | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/testes/locals.lua b/testes/locals.lua index 8506195e..24a95d18 100644 --- a/testes/locals.lua +++ b/testes/locals.lua | |||
@@ -539,15 +539,17 @@ if rawget(_G, "T") then | |||
539 | local _, msg = pcall(foo) | 539 | local _, msg = pcall(foo) |
540 | assert(msg == "not enough memory") | 540 | assert(msg == "not enough memory") |
541 | 541 | ||
542 | local closemsg | ||
542 | local close = func2close(function (self, msg) | 543 | local close = func2close(function (self, msg) |
543 | T.alloccount() | 544 | T.alloccount() |
544 | assert(msg == "not enough memory") | 545 | closemsg = msg |
545 | end) | 546 | end) |
546 | 547 | ||
547 | -- set a memory limit and return a closing object to remove the limit | 548 | -- set a memory limit and return a closing object to remove the limit |
548 | local function enter (count) | 549 | local function enter (count) |
549 | stack(10) -- reserve some stack space | 550 | stack(10) -- reserve some stack space |
550 | T.alloccount(count) | 551 | T.alloccount(count) |
552 | closemsg = nil | ||
551 | return close | 553 | return close |
552 | end | 554 | end |
553 | 555 | ||
@@ -558,12 +560,7 @@ if rawget(_G, "T") then | |||
558 | end | 560 | end |
559 | 561 | ||
560 | local _, msg = pcall(test) | 562 | local _, msg = pcall(test) |
561 | assert(msg == "not enough memory") | 563 | assert(msg == "not enough memory" and closemsg == "not enough memory") |
562 | |||
563 | -- now use metamethod for closing | ||
564 | close = setmetatable({}, {__close = function () | ||
565 | T.alloccount() | ||
566 | end}) | ||
567 | 564 | ||
568 | -- repeat test with extra closing upvalues | 565 | -- repeat test with extra closing upvalues |
569 | local function test () | 566 | local function test () |
@@ -580,7 +577,7 @@ if rawget(_G, "T") then | |||
580 | end | 577 | end |
581 | 578 | ||
582 | local _, msg = pcall(test) | 579 | local _, msg = pcall(test) |
583 | assert(msg == 1000) | 580 | assert(msg == 1000 and closemsg == "not enough memory") |
584 | 581 | ||
585 | do -- testing 'toclose' in C string buffer | 582 | do -- testing 'toclose' in C string buffer |
586 | collectgarbage() | 583 | collectgarbage() |