diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-12-28 18:34:11 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-12-28 18:34:11 -0300 |
commit | 314745ed8438d1276c6c928d5f9d4be018dfadb6 (patch) | |
tree | 594b7e873f2c29113d95c75147ab10865cdd772c /testes/gc.lua | |
parent | 0825cf237d9d3505155f8b40bcf83ea1b135e8da (diff) | |
download | lua-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.lua | 42 |
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 | |
129 | end | 129 | end |
130 | 130 | ||
131 | 131 | ||
@@ -134,7 +134,7 @@ do local f = function () end end | |||
134 | 134 | ||
135 | 135 | ||
136 | print("functions with errors") | 136 | print("functions with errors") |
137 | prog = [[ | 137 | local prog = [[ |
138 | do | 138 | do |
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 |
155 | end | 155 | end |
156 | rawset(_G, "a", nil) | ||
157 | _G.x = nil | ||
156 | 158 | ||
157 | foo = nil | 159 | do |
158 | print('long strings') | 160 | foo = nil |
159 | x = "01234567890123456789012345678901234567890123456789012345678901234567890123456789" | 161 | print('long strings') |
160 | assert(string.len(x)==80) | 162 | local x = "01234567890123456789012345678901234567890123456789012345678901234567890123456789" |
161 | s = '' | 163 | assert(string.len(x)==80) |
162 | k = math.min(300, (math.maxinteger // 80) // 2) | 164 | local s = '' |
163 | for n = 1, k do s = s..x; j=tostring(n) end | 165 | local k = math.min(300, (math.maxinteger // 80) // 2) |
164 | assert(string.len(s) == k*80) | 166 | for n = 1, k do s = s..x; local j=tostring(n) end |
165 | s = string.sub(s, 1, 10000) | 167 | assert(string.len(s) == k*80) |
166 | s, i = string.gsub(s, '(%d%d%d%d)', '') | 168 | s = string.sub(s, 1, 10000) |
167 | assert(i==10000 // 4) | 169 | local s, i = string.gsub(s, '(%d%d%d%d)', '') |
168 | s = nil | 170 | assert(i==10000 // 4) |
169 | x = nil | 171 | |
170 | 172 | assert(_G["while"] == 234) | |
171 | assert(_G["while"] == 234) | 173 | _G["while"] = nil |
174 | end | ||
172 | 175 | ||
173 | 176 | ||
174 | -- | 177 | -- |
@@ -227,8 +230,8 @@ end | |||
227 | 230 | ||
228 | 231 | ||
229 | print("clearing tables") | 232 | print("clearing tables") |
230 | lim = 15 | 233 | local lim = 15 |
231 | a = {} | 234 | local a = {} |
232 | -- fill a with `collectable' indices | 235 | -- fill a with `collectable' indices |
233 | for i=1,lim do a[{}] = i end | 236 | for i=1,lim do a[{}] = i end |
234 | b = {} | 237 | b = {} |
@@ -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 | ||
555 | end | 559 | end |
556 | 560 | ||
557 | 561 | ||