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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user