aboutsummaryrefslogtreecommitdiff
path: root/testes/gc.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-12-28 18:34:11 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-12-28 18:34:11 -0300
commit314745ed8438d1276c6c928d5f9d4be018dfadb6 (patch)
tree594b7e873f2c29113d95c75147ab10865cdd772c /testes/gc.lua
parent0825cf237d9d3505155f8b40bcf83ea1b135e8da (diff)
downloadlua-314745ed8438d1276c6c928d5f9d4be018dfadb6.tar.gz
lua-314745ed8438d1276c6c928d5f9d4be018dfadb6.tar.bz2
lua-314745ed8438d1276c6c928d5f9d4be018dfadb6.zip
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.
Diffstat (limited to 'testes/gc.lua')
-rw-r--r--testes/gc.lua42
1 files changed, 23 insertions, 19 deletions
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
125 end 125 end
126 126
127 a:test() 127 a:test()
128 128 _G.temp = nil
129end 129end
130 130
131 131
@@ -134,7 +134,7 @@ do local f = function () end end
134 134
135 135
136print("functions with errors") 136print("functions with errors")
137prog = [[ 137local prog = [[
138do 138do
139 a = 10; 139 a = 10;
140 function foo(x,y) 140 function foo(x,y)
@@ -153,22 +153,25 @@ do
153 end 153 end
154 end 154 end
155end 155end
156rawset(_G, "a", nil)
157_G.x = nil
156 158
157foo = nil 159do
158print('long strings') 160 foo = nil
159x = "01234567890123456789012345678901234567890123456789012345678901234567890123456789" 161 print('long strings')
160assert(string.len(x)==80) 162 local x = "01234567890123456789012345678901234567890123456789012345678901234567890123456789"
161s = '' 163 assert(string.len(x)==80)
162k = math.min(300, (math.maxinteger // 80) // 2) 164 local s = ''
163for n = 1, k do s = s..x; j=tostring(n) end 165 local k = math.min(300, (math.maxinteger // 80) // 2)
164assert(string.len(s) == k*80) 166 for n = 1, k do s = s..x; local j=tostring(n) end
165s = string.sub(s, 1, 10000) 167 assert(string.len(s) == k*80)
166s, i = string.gsub(s, '(%d%d%d%d)', '') 168 s = string.sub(s, 1, 10000)
167assert(i==10000 // 4) 169 local s, i = string.gsub(s, '(%d%d%d%d)', '')
168s = nil 170 assert(i==10000 // 4)
169x = nil 171
170 172 assert(_G["while"] == 234)
171assert(_G["while"] == 234) 173 _G["while"] = nil
174end
172 175
173 176
174-- 177--
@@ -227,8 +230,8 @@ end
227 230
228 231
229print("clearing tables") 232print("clearing tables")
230lim = 15 233local lim = 15
231a = {} 234local a = {}
232-- fill a with `collectable' indices 235-- fill a with `collectable' indices
233for i=1,lim do a[{}] = i end 236for i=1,lim do a[{}] = i end
234b = {} 237b = {}
@@ -552,6 +555,7 @@ do
552 for i=1,1000 do _ENV.a = {} end -- no collection during the loop 555 for i=1,1000 do _ENV.a = {} end -- no collection during the loop
553 until gcinfo() > 2 * x 556 until gcinfo() > 2 * x
554 collectgarbage"restart" 557 collectgarbage"restart"
558 _ENV.a = nil
555end 559end
556 560
557 561