lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 7d0f41df41e9c513e7282356541b54beaf9ed20d
parent 2b8b53864c6b8655aa7198699884075b3e2f15fa
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Mon,  3 Jun 2019 11:34:05 -0300

Improvements in 'testes/cstack.lua'

- tests show progress in real time, so that we can see maximum
stack levels even if test crashes.
- new test for recursion continuing into message handler.

Diffstat:
Mtestes/cstack.lua | 44++++++++++++++++++++++++++++++++------------
1 file changed, 32 insertions(+), 12 deletions(-)

diff --git a/testes/cstack.lua b/testes/cstack.lua @@ -13,20 +13,40 @@ local function checkerror (msg, f, ...) assert(not s and string.find(err, msg)) end +local count +local back = string.rep("\b", 8) +local function progress () + count = count + 1 + local n = string.format("%-8d", count) + io.stderr:write(back, n) +end + -do -- simple recursion - local count = 0 +do print("testing simple recursion:") + count = 0 local function foo () - count = count + 1 + progress() foo() end checkerror("stack overflow", foo) - print(" maximum recursion: " .. count) + print("\tfinal count: ", count) +end + + +do print("testing stack overflow in message handling") + count = 0 + local function loop (x, y, z) + progress() + return 1 + loop(x, y, z) + end + local res, msg = xpcall(loop, loop) + assert(msg == "error in error handling") + print("\tfinal count: ", count) end -- bug since 2.5 (C-stack overflow in recursion inside pattern matching) -do +do print("testing recursion inside pattern matching") local function f (size) local s = string.rep("a", size) local p = string.rep(".?", size) @@ -38,25 +58,25 @@ do end --- testing stack-overflow in recursive 'gsub' -do - local count = 0 +do print("testing stack-overflow in recursive 'gsub'") + count = 0 local function foo () - count = count + 1 + progress() string.gsub("a", ".", foo) end checkerror("stack overflow", foo) - print(" maximum 'gsub' nest (calls): " .. count) + print("\tfinal count: ", count) - -- can be done with metamethods, too + print("testing stack-overflow in recursive 'gsub' with metatables") count = 0 local t = setmetatable({}, {__index = foo}) foo = function () count = count + 1 + progress(count) string.gsub("a", ".", t) end checkerror("stack overflow", foo) - print(" maximum 'gsub' nest (metamethods): " .. count) + print("\tfinal count: ", count) end print'OK'