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-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/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 | |||
52 | print "testing large programs (>64k)" | 52 | print "testing large programs (>64k)" |
53 | 53 | ||
54 | -- template to create a very big test file | 54 | -- template to create a very big test file |
55 | prog = [[$ | 55 | local prog = [[$ |
56 | 56 | ||
57 | local a,b | 57 | local a,b |
58 | 58 | ||
@@ -85,7 +85,7 @@ function b:xxx (a,b) return a+b end | |||
85 | assert(b:xxx(10, 12) == 22) -- pushself with non-constant index | 85 | assert(b:xxx(10, 12) == 22) -- pushself with non-constant index |
86 | b["xxx"] = undef | 86 | b["xxx"] = undef |
87 | 87 | ||
88 | s = 0; n=0 | 88 | local s = 0; local n=0 |
89 | for a,b in pairs(b) do s=s+b; n=n+1 end | 89 | for a,b in pairs(b) do s=s+b; n=n+1 end |
90 | -- with 32-bit floats, exact value of 's' depends on summation order | 90 | -- with 32-bit floats, exact value of 's' depends on summation order |
91 | assert(81800000.0 < s and s < 81860000 and n == 70001) | 91 | assert(81800000.0 < s and s < 81860000 and n == 70001) |
@@ -93,7 +93,7 @@ assert(81800000.0 < s and s < 81860000 and n == 70001) | |||
93 | a = nil; b = nil | 93 | a = nil; b = nil |
94 | print'+' | 94 | print'+' |
95 | 95 | ||
96 | function f(x) b=x end | 96 | local function f(x) b=x end |
97 | 97 | ||
98 | a = f{$3$} or 10 | 98 | a = f{$3$} or 10 |
99 | 99 | ||
@@ -118,7 +118,7 @@ local function sig (x) | |||
118 | return (x % 2 == 0) and '' or '-' | 118 | return (x % 2 == 0) and '' or '-' |
119 | end | 119 | end |
120 | 120 | ||
121 | F = { | 121 | local F = { |
122 | function () -- $1$ | 122 | function () -- $1$ |
123 | for i=10,50009 do | 123 | for i=10,50009 do |
124 | io.write('a', i, ' = ', sig(i), 5+((i-10)/2), ',\n') | 124 | io.write('a', i, ' = ', sig(i), 5+((i-10)/2), ',\n') |
@@ -138,14 +138,14 @@ function () -- $3$ | |||
138 | end, | 138 | end, |
139 | } | 139 | } |
140 | 140 | ||
141 | file = os.tmpname() | 141 | local file = os.tmpname() |
142 | io.output(file) | 142 | io.output(file) |
143 | for s in string.gmatch(prog, "$([^$]+)") do | 143 | for s in string.gmatch(prog, "$([^$]+)") do |
144 | local n = tonumber(s) | 144 | local n = tonumber(s) |
145 | if not n then io.write(s) else F[n]() end | 145 | if not n then io.write(s) else F[n]() end |
146 | end | 146 | end |
147 | io.close() | 147 | io.close() |
148 | result = dofile(file) | 148 | local result = dofile(file) |
149 | assert(os.remove(file)) | 149 | assert(os.remove(file)) |
150 | print'OK' | 150 | print'OK' |
151 | return result | 151 | return result |