diff options
Diffstat (limited to 'testes/all.lua')
-rwxr-xr-x | testes/all.lua | 294 |
1 files changed, 294 insertions, 0 deletions
diff --git a/testes/all.lua b/testes/all.lua new file mode 100755 index 00000000..cfe21603 --- /dev/null +++ b/testes/all.lua | |||
@@ -0,0 +1,294 @@ | |||
1 | #!../lua | ||
2 | -- $Id: all.lua,v 1.100 2018/03/09 14:23:48 roberto Exp $ | ||
3 | -- See Copyright Notice at the end of this file | ||
4 | |||
5 | |||
6 | local version = "Lua 5.4" | ||
7 | if _VERSION ~= version then | ||
8 | io.stderr:write("\nThis test suite is for ", version, ", not for ", _VERSION, | ||
9 | "\nExiting tests\n") | ||
10 | return | ||
11 | end | ||
12 | |||
13 | |||
14 | _G.ARG = arg -- save arg for other tests | ||
15 | |||
16 | |||
17 | -- next variables control the execution of some tests | ||
18 | -- true means no test (so an undefined variable does not skip a test) | ||
19 | -- defaults are for Linux; test everything. | ||
20 | -- Make true to avoid long or memory consuming tests | ||
21 | _soft = rawget(_G, "_soft") or false | ||
22 | -- Make true to avoid non-portable tests | ||
23 | _port = rawget(_G, "_port") or false | ||
24 | -- Make true to avoid messages about tests not performed | ||
25 | _nomsg = rawget(_G, "_nomsg") or false | ||
26 | |||
27 | |||
28 | local usertests = rawget(_G, "_U") | ||
29 | |||
30 | if usertests then | ||
31 | -- tests for sissies ;) Avoid problems | ||
32 | _soft = true | ||
33 | _port = true | ||
34 | _nomsg = true | ||
35 | end | ||
36 | |||
37 | -- tests should require debug when needed | ||
38 | debug = nil | ||
39 | |||
40 | require"bwcoercion" | ||
41 | |||
42 | |||
43 | if usertests then | ||
44 | T = nil -- no "internal" tests for user tests | ||
45 | else | ||
46 | T = rawget(_G, "T") -- avoid problems with 'strict' module | ||
47 | end | ||
48 | |||
49 | math.randomseed(0) | ||
50 | |||
51 | --[=[ | ||
52 | example of a long [comment], | ||
53 | [[spanning several [lines]]] | ||
54 | |||
55 | ]=] | ||
56 | |||
57 | print("current path:\n****" .. package.path .. "****\n") | ||
58 | |||
59 | |||
60 | local initclock = os.clock() | ||
61 | local lastclock = initclock | ||
62 | local walltime = os.time() | ||
63 | |||
64 | local collectgarbage = collectgarbage | ||
65 | |||
66 | do -- ( | ||
67 | |||
68 | -- track messages for tests not performed | ||
69 | local msgs = {} | ||
70 | function Message (m) | ||
71 | if not _nomsg then | ||
72 | print(m) | ||
73 | msgs[#msgs+1] = string.sub(m, 3, -3) | ||
74 | end | ||
75 | end | ||
76 | |||
77 | assert(os.setlocale"C") | ||
78 | |||
79 | local T,print,format,write,assert,type,unpack,floor = | ||
80 | T,print,string.format,io.write,assert,type,table.unpack,math.floor | ||
81 | |||
82 | -- use K for 1000 and M for 1000000 (not 2^10 -- 2^20) | ||
83 | local function F (m) | ||
84 | local function round (m) | ||
85 | m = m + 0.04999 | ||
86 | return format("%.1f", m) -- keep one decimal digit | ||
87 | end | ||
88 | if m < 1000 then return m | ||
89 | else | ||
90 | m = m / 1000 | ||
91 | if m < 1000 then return round(m).."K" | ||
92 | else | ||
93 | return round(m/1000).."M" | ||
94 | end | ||
95 | end | ||
96 | end | ||
97 | |||
98 | local showmem | ||
99 | if not T then | ||
100 | local max = 0 | ||
101 | showmem = function () | ||
102 | local m = collectgarbage("count") * 1024 | ||
103 | max = (m > max) and m or max | ||
104 | print(format(" ---- total memory: %s, max memory: %s ----\n", | ||
105 | F(m), F(max))) | ||
106 | end | ||
107 | else | ||
108 | showmem = function () | ||
109 | T.checkmemory() | ||
110 | local total, numblocks, maxmem = T.totalmem() | ||
111 | local count = collectgarbage("count") | ||
112 | print(format( | ||
113 | "\n ---- total memory: %s (%.0fK), max use: %s, blocks: %d\n", | ||
114 | F(total), count, F(maxmem), numblocks)) | ||
115 | print(format("\t(strings: %d, tables: %d, functions: %d, ".. | ||
116 | "\n\tudata: %d, threads: %d)", | ||
117 | T.totalmem"string", T.totalmem"table", T.totalmem"function", | ||
118 | T.totalmem"userdata", T.totalmem"thread")) | ||
119 | end | ||
120 | end | ||
121 | |||
122 | |||
123 | -- | ||
124 | -- redefine dofile to run files through dump/undump | ||
125 | -- | ||
126 | local function report (n) print("\n***** FILE '"..n.."'*****") end | ||
127 | local olddofile = dofile | ||
128 | local dofile = function (n, strip) | ||
129 | showmem() | ||
130 | local c = os.clock() | ||
131 | print(string.format("time: %g (+%g)", c - initclock, c - lastclock)) | ||
132 | lastclock = c | ||
133 | report(n) | ||
134 | local f = assert(loadfile(n)) | ||
135 | local b = string.dump(f, strip) | ||
136 | f = assert(load(b)) | ||
137 | return f() | ||
138 | end | ||
139 | |||
140 | dofile('main.lua') | ||
141 | |||
142 | do | ||
143 | local next, setmetatable, stderr = next, setmetatable, io.stderr | ||
144 | -- track collections | ||
145 | local mt = {} | ||
146 | -- each time a table is collected, remark it for finalization | ||
147 | -- on next cycle | ||
148 | mt.__gc = function (o) | ||
149 | stderr:write'.' -- mark progress | ||
150 | local n = setmetatable(o, mt) -- remark it | ||
151 | end | ||
152 | local n = setmetatable({}, mt) -- create object | ||
153 | end | ||
154 | |||
155 | report"gc.lua" | ||
156 | local f = assert(loadfile('gc.lua')) | ||
157 | f() | ||
158 | |||
159 | dofile('db.lua') | ||
160 | assert(dofile('calls.lua') == deep and deep) | ||
161 | olddofile('strings.lua') | ||
162 | olddofile('literals.lua') | ||
163 | dofile('tpack.lua') | ||
164 | assert(dofile('attrib.lua') == 27) | ||
165 | |||
166 | assert(dofile('locals.lua') == 5) | ||
167 | dofile('constructs.lua') | ||
168 | dofile('code.lua', true) | ||
169 | if not _G._soft then | ||
170 | report('big.lua') | ||
171 | local f = coroutine.wrap(assert(loadfile('big.lua'))) | ||
172 | assert(f() == 'b') | ||
173 | assert(f() == 'a') | ||
174 | end | ||
175 | dofile('nextvar.lua') | ||
176 | dofile('pm.lua') | ||
177 | dofile('utf8.lua') | ||
178 | dofile('api.lua') | ||
179 | assert(dofile('events.lua') == 12) | ||
180 | dofile('vararg.lua') | ||
181 | dofile('closure.lua') | ||
182 | dofile('coroutine.lua') | ||
183 | dofile('goto.lua', true) | ||
184 | dofile('errors.lua') | ||
185 | dofile('math.lua') | ||
186 | dofile('sort.lua', true) | ||
187 | dofile('bitwise.lua') | ||
188 | assert(dofile('verybig.lua', true) == 10); collectgarbage() | ||
189 | dofile('files.lua') | ||
190 | |||
191 | if #msgs > 0 then | ||
192 | print("\ntests not performed:") | ||
193 | for i=1,#msgs do | ||
194 | print(msgs[i]) | ||
195 | end | ||
196 | print() | ||
197 | end | ||
198 | |||
199 | -- no test module should define 'debug' | ||
200 | assert(debug == nil) | ||
201 | |||
202 | local debug = require "debug" | ||
203 | |||
204 | print(string.format("%d-bit integers, %d-bit floats", | ||
205 | string.packsize("j") * 8, string.packsize("n") * 8)) | ||
206 | |||
207 | debug.sethook(function (a) assert(type(a) == 'string') end, "cr") | ||
208 | |||
209 | -- to survive outside block | ||
210 | _G.showmem = showmem | ||
211 | |||
212 | end --) | ||
213 | |||
214 | local _G, showmem, print, format, clock, time, difftime, assert, open = | ||
215 | _G, showmem, print, string.format, os.clock, os.time, os.difftime, | ||
216 | assert, io.open | ||
217 | |||
218 | -- file with time of last performed test | ||
219 | local fname = T and "time-debug.txt" or "time.txt" | ||
220 | local lasttime | ||
221 | |||
222 | if not usertests then | ||
223 | -- open file with time of last performed test | ||
224 | local f = io.open(fname) | ||
225 | if f then | ||
226 | lasttime = assert(tonumber(f:read'a')) | ||
227 | f:close(); | ||
228 | else -- no such file; assume it is recording time for first time | ||
229 | lasttime = nil | ||
230 | end | ||
231 | end | ||
232 | |||
233 | -- erase (almost) all globals | ||
234 | print('cleaning all!!!!') | ||
235 | for n in pairs(_G) do | ||
236 | if not ({___Glob = 1, tostring = 1})[n] then | ||
237 | _G[n] = undef | ||
238 | end | ||
239 | end | ||
240 | |||
241 | |||
242 | collectgarbage() | ||
243 | collectgarbage() | ||
244 | collectgarbage() | ||
245 | collectgarbage() | ||
246 | collectgarbage() | ||
247 | collectgarbage();showmem() | ||
248 | |||
249 | local clocktime = clock() - initclock | ||
250 | walltime = difftime(time(), walltime) | ||
251 | |||
252 | print(format("\n\ntotal time: %.2fs (wall time: %gs)\n", clocktime, walltime)) | ||
253 | |||
254 | if not usertests then | ||
255 | lasttime = lasttime or clocktime -- if no last time, ignore difference | ||
256 | -- check whether current test time differs more than 5% from last time | ||
257 | local diff = (clocktime - lasttime) / lasttime | ||
258 | local tolerance = 0.05 -- 5% | ||
259 | if (diff >= tolerance or diff <= -tolerance) then | ||
260 | print(format("WARNING: time difference from previous test: %+.1f%%", | ||
261 | diff * 100)) | ||
262 | end | ||
263 | assert(open(fname, "w")):write(clocktime):close() | ||
264 | end | ||
265 | |||
266 | print("final OK !!!") | ||
267 | |||
268 | |||
269 | |||
270 | --[[ | ||
271 | ***************************************************************************** | ||
272 | * Copyright (C) 1994-2016 Lua.org, PUC-Rio. | ||
273 | * | ||
274 | * Permission is hereby granted, free of charge, to any person obtaining | ||
275 | * a copy of this software and associated documentation files (the | ||
276 | * "Software"), to deal in the Software without restriction, including | ||
277 | * without limitation the rights to use, copy, modify, merge, publish, | ||
278 | * distribute, sublicense, and/or sell copies of the Software, and to | ||
279 | * permit persons to whom the Software is furnished to do so, subject to | ||
280 | * the following conditions: | ||
281 | * | ||
282 | * The above copyright notice and this permission notice shall be | ||
283 | * included in all copies or substantial portions of the Software. | ||
284 | * | ||
285 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
286 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
287 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
288 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
289 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
290 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
291 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
292 | ***************************************************************************** | ||
293 | ]] | ||
294 | |||