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