aboutsummaryrefslogtreecommitdiff
path: root/testes/all.lua
diff options
context:
space:
mode:
Diffstat (limited to 'testes/all.lua')
-rwxr-xr-xtestes/all.lua294
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
6local version = "Lua 5.4"
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
40require"bwcoercion"
41
42
43if usertests then
44 T = nil -- no "internal" tests for user tests
45else
46 T = rawget(_G, "T") -- avoid problems with 'strict' module
47end
48
49math.randomseed(0)
50
51--[=[
52 example of a long [comment],
53 [[spanning several [lines]]]
54
55]=]
56
57print("current path:\n****" .. package.path .. "****\n")
58
59
60local initclock = os.clock()
61local lastclock = initclock
62local walltime = os.time()
63
64local collectgarbage = collectgarbage
65
66do -- (
67
68-- track messages for tests not performed
69local msgs = {}
70function Message (m)
71 if not _nomsg then
72 print(m)
73 msgs[#msgs+1] = string.sub(m, 3, -3)
74 end
75end
76
77assert(os.setlocale"C")
78
79local 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)
83local 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
96end
97
98local showmem
99if 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
107else
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
120end
121
122
123--
124-- redefine dofile to run files through dump/undump
125--
126local function report (n) print("\n***** FILE '"..n.."'*****") end
127local olddofile = dofile
128local 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()
138end
139
140dofile('main.lua')
141
142do
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
153end
154
155report"gc.lua"
156local f = assert(loadfile('gc.lua'))
157f()
158
159dofile('db.lua')
160assert(dofile('calls.lua') == deep and deep)
161olddofile('strings.lua')
162olddofile('literals.lua')
163dofile('tpack.lua')
164assert(dofile('attrib.lua') == 27)
165
166assert(dofile('locals.lua') == 5)
167dofile('constructs.lua')
168dofile('code.lua', true)
169if 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')
174end
175dofile('nextvar.lua')
176dofile('pm.lua')
177dofile('utf8.lua')
178dofile('api.lua')
179assert(dofile('events.lua') == 12)
180dofile('vararg.lua')
181dofile('closure.lua')
182dofile('coroutine.lua')
183dofile('goto.lua', true)
184dofile('errors.lua')
185dofile('math.lua')
186dofile('sort.lua', true)
187dofile('bitwise.lua')
188assert(dofile('verybig.lua', true) == 10); collectgarbage()
189dofile('files.lua')
190
191if #msgs > 0 then
192 print("\ntests not performed:")
193 for i=1,#msgs do
194 print(msgs[i])
195 end
196 print()
197end
198
199-- no test module should define 'debug'
200assert(debug == nil)
201
202local debug = require "debug"
203
204print(string.format("%d-bit integers, %d-bit floats",
205 string.packsize("j") * 8, string.packsize("n") * 8))
206
207debug.sethook(function (a) assert(type(a) == 'string') end, "cr")
208
209-- to survive outside block
210_G.showmem = showmem
211
212end --)
213
214local _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
219local fname = T and "time-debug.txt" or "time.txt"
220local lasttime
221
222if 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
231end
232
233-- erase (almost) all globals
234print('cleaning all!!!!')
235for n in pairs(_G) do
236 if not ({___Glob = 1, tostring = 1})[n] then
237 _G[n] = undef
238 end
239end
240
241
242collectgarbage()
243collectgarbage()
244collectgarbage()
245collectgarbage()
246collectgarbage()
247collectgarbage();showmem()
248
249local clocktime = clock() - initclock
250walltime = difftime(time(), walltime)
251
252print(format("\n\ntotal time: %.2fs (wall time: %gs)\n", clocktime, walltime))
253
254if 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()
264end
265
266print("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