From 314745ed8438d1276c6c928d5f9d4be018dfadb6 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 28 Dec 2022 18:34:11 -0300 Subject: Avoid excessive name pollution in test files Test files are more polite regarding the use of globals when locals would do, and when globals are necessary deleting them after use. --- testes/gc.lua | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'testes/gc.lua') diff --git a/testes/gc.lua b/testes/gc.lua index 381c5548..03093e34 100644 --- a/testes/gc.lua +++ b/testes/gc.lua @@ -125,7 +125,7 @@ do end a:test() - + _G.temp = nil end @@ -134,7 +134,7 @@ do local f = function () end end print("functions with errors") -prog = [[ +local prog = [[ do a = 10; function foo(x,y) @@ -153,22 +153,25 @@ do end end end +rawset(_G, "a", nil) +_G.x = nil -foo = nil -print('long strings') -x = "01234567890123456789012345678901234567890123456789012345678901234567890123456789" -assert(string.len(x)==80) -s = '' -k = math.min(300, (math.maxinteger // 80) // 2) -for n = 1, k do s = s..x; j=tostring(n) end -assert(string.len(s) == k*80) -s = string.sub(s, 1, 10000) -s, i = string.gsub(s, '(%d%d%d%d)', '') -assert(i==10000 // 4) -s = nil -x = nil - -assert(_G["while"] == 234) +do + foo = nil + print('long strings') + local x = "01234567890123456789012345678901234567890123456789012345678901234567890123456789" + assert(string.len(x)==80) + local s = '' + local k = math.min(300, (math.maxinteger // 80) // 2) + for n = 1, k do s = s..x; local j=tostring(n) end + assert(string.len(s) == k*80) + s = string.sub(s, 1, 10000) + local s, i = string.gsub(s, '(%d%d%d%d)', '') + assert(i==10000 // 4) + + assert(_G["while"] == 234) + _G["while"] = nil +end -- @@ -227,8 +230,8 @@ end print("clearing tables") -lim = 15 -a = {} +local lim = 15 +local a = {} -- fill a with `collectable' indices for i=1,lim do a[{}] = i end b = {} @@ -552,6 +555,7 @@ do for i=1,1000 do _ENV.a = {} end -- no collection during the loop until gcinfo() > 2 * x collectgarbage"restart" + _ENV.a = nil end -- cgit v1.2.3-55-g6feb