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/verybig.lua | |
parent | 0825cf237d9d3505155f8b40bcf83ea1b135e8da (diff) | |
download | lua-github-314745ed8438d1276c6c928d5f9d4be018dfadb6.tar.gz |
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/verybig.lua')
-rw-r--r-- | testes/verybig.lua | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/testes/verybig.lua b/testes/verybig.lua index 8fb7b13e..250ea795 100644 --- a/testes/verybig.lua +++ b/testes/verybig.lua @@ -52,7 +52,7 @@ if _soft then return 10 end print "testing large programs (>64k)" -- template to create a very big test file -prog = [[$ +local prog = [[$ local a,b @@ -85,7 +85,7 @@ function b:xxx (a,b) return a+b end assert(b:xxx(10, 12) == 22) -- pushself with non-constant index b["xxx"] = undef -s = 0; n=0 +local s = 0; local n=0 for a,b in pairs(b) do s=s+b; n=n+1 end -- with 32-bit floats, exact value of 's' depends on summation order assert(81800000.0 < s and s < 81860000 and n == 70001) @@ -93,7 +93,7 @@ assert(81800000.0 < s and s < 81860000 and n == 70001) a = nil; b = nil print'+' -function f(x) b=x end +local function f(x) b=x end a = f{$3$} or 10 @@ -118,7 +118,7 @@ local function sig (x) return (x % 2 == 0) and '' or '-' end -F = { +local F = { function () -- $1$ for i=10,50009 do io.write('a', i, ' = ', sig(i), 5+((i-10)/2), ',\n') @@ -138,14 +138,14 @@ function () -- $3$ end, } -file = os.tmpname() +local file = os.tmpname() io.output(file) for s in string.gmatch(prog, "$([^$]+)") do local n = tonumber(s) if not n then io.write(s) else F[n]() end end io.close() -result = dofile(file) +local result = dofile(file) assert(os.remove(file)) print'OK' return result |