Skip to content

Commit 0055629

Browse files
author
Guilherme Salazar
committed
lua 5.3.1 test suite
1 parent 4c57785 commit 0055629

22 files changed

+408
-104
lines changed

all.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!../lua
2-
-- $Id: all.lua,v 1.91 2014/12/26 17:20:53 roberto Exp $
2+
-- $Id: all.lua,v 1.93 2015/05/15 12:28:08 roberto Exp $
33

44
local version = "Lua 5.3"
55
if _VERSION ~= version then
@@ -9,6 +9,9 @@ if _VERSION ~= version then
99
end
1010

1111

12+
_G._ARG = arg -- save arg for other tests
13+
14+
1215
-- next variables control the execution of some tests
1316
-- true means no test (so an undefined variable does not skip a test)
1417
-- defaults are for Linux; test everything.
@@ -203,8 +206,9 @@ _G.showmem = showmem
203206

204207
end --)
205208

206-
local _G, showmem, print, format, clock, time, assert, open =
207-
_G, showmem, print, string.format, os.clock, os.time, assert, io.open
209+
local _G, showmem, print, format, clock, time, difftime, assert, open =
210+
_G, showmem, print, string.format, os.clock, os.time, os.difftime,
211+
assert, io.open
208212

209213
-- file with time of last performed test
210214
local fname = T and "time-debug.txt" or "time.txt"
@@ -238,9 +242,9 @@ collectgarbage()
238242
collectgarbage();showmem()
239243

240244
local clocktime = clock() - initclock
241-
walltime = time() - walltime
245+
walltime = difftime(time(), walltime)
242246

243-
print(format("\n\ntotal time: %.2fs (wall time: %ds)\n", clocktime, walltime))
247+
print(format("\n\ntotal time: %.2fs (wall time: %gs)\n", clocktime, walltime))
244248

245249
if not usertests then
246250
lasttime = lasttime or clocktime -- if no last time, ignore difference

api.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- $Id: api.lua,v 1.139 2014/12/26 17:20:53 roberto Exp $
1+
-- $Id: api.lua,v 1.141 2015/05/15 12:25:38 roberto Exp $
22

33
if T==nil then
44
(Message or print)('\n >>> testC not active: skipping API tests <<<\n')
@@ -35,9 +35,9 @@ assert(T.testC("settop 10; absindex 1; return 1") == 1)
3535
assert(T.testC("settop 10; absindex R; return 1") < -10)
3636

3737
-- testing alignment
38-
a = T.d2s(12458954321123)
39-
assert(a == string.pack("d", 12458954321123))
40-
assert(T.s2d(a) == 12458954321123)
38+
a = T.d2s(12458954321123.0)
39+
assert(a == string.pack("d", 12458954321123.0))
40+
assert(T.s2d(a) == 12458954321123.0)
4141

4242
a,b,c = T.testC("pushnum 1; pushnum 2; pushnum 3; return 2")
4343
assert(a == 2 and b == 3 and not c)
@@ -369,8 +369,8 @@ do
369369

370370

371371
-- memory error
372-
T.totalmem(T.totalmem()+5000) -- set low memory limit (+5k)
373-
assert(T.checkpanic("newuserdata 10000") == "not enough memory")
372+
T.totalmem(T.totalmem()+10000) -- set low memory limit (+10k)
373+
assert(T.checkpanic("newuserdata 20000") == "not enough memory")
374374
T.totalmem(0) -- restore high limit
375375

376376
-- stack error

attrib.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- $Id: attrib.lua,v 1.61 2014/12/26 17:20:53 roberto Exp $
1+
-- $Id: attrib.lua,v 1.62 2015/04/30 14:15:57 roberto Exp $
22

33
print "testing require"
44

@@ -395,7 +395,7 @@ a[1].alo(a[2]==10 and b==10 and c==print)
395395
-- compute maximum integer where all bits fit in a float
396396
local maxint = math.maxinteger
397397

398-
while maxint - 1.0 == maxint do -- trim (if needed) to fit in a float
398+
while maxint - 1.0 == maxint - 0.0 do -- trim (if needed) to fit in a float
399399
maxint = maxint // 2
400400
end
401401

bitwise.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- $Id: bitwise.lua,v 1.24 2014/12/26 17:20:53 roberto Exp $
1+
-- $Id: bitwise.lua,v 1.25 2015/04/30 14:15:57 roberto Exp $
22

33
print("testing bitwise operations")
44

@@ -35,7 +35,7 @@ d = d << 32
3535
assert(a | b ~ c & d == 0xF4000000 << 32)
3636
assert(~~a == a and ~a == -1 ~ a and -d == ~d + 1)
3737

38-
assert(-1 >> 1 == 2^(numbits - 1) - 1 and 1 << 31 == 0x80000000)
38+
assert(-1 >> 1 == (1 << (numbits - 1)) - 1 and 1 << 31 == 0x80000000)
3939
assert(-1 >> (numbits - 1) == 1)
4040
assert(-1 >> numbits == 0 and
4141
-1 >> -numbits == 0 and
@@ -218,7 +218,7 @@ assert(bit32.rshift(0x12345678, 8) == 0x00123456)
218218
assert(bit32.rshift(0x12345678, 32) == 0)
219219
assert(bit32.rshift(0x12345678, -32) == 0)
220220
assert(bit32.arshift(0x12345678, 0) == 0x12345678)
221-
assert(bit32.arshift(0x12345678, 1) == 0x12345678 / 2)
221+
assert(bit32.arshift(0x12345678, 1) == 0x12345678 // 2)
222222
assert(bit32.arshift(0x12345678, -1) == 0x12345678 * 2)
223223
assert(bit32.arshift(-1, 1) == 0xffffffff)
224224
assert(bit32.arshift(-1, 24) == 0xffffffff)

calls.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- $Id: calls.lua,v 1.56 2014/12/26 17:20:53 roberto Exp $
1+
-- $Id: calls.lua,v 1.57 2015/03/04 13:09:38 roberto Exp $
22

33
print("testing functions and calls")
44

@@ -87,7 +87,7 @@ assert(t[1] == 1 and t[2] == 2 and t[3] == 3 and t[4] == 'a')
8787

8888
function fat(x)
8989
if x <= 1 then return 1
90-
else return x*load("return fat(" .. x-1 .. ")")()
90+
else return x*load("return fat(" .. x-1 .. ")", "")()
9191
end
9292
end
9393

constructs.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- $Id: constructs.lua,v 1.37 2014/12/26 17:20:53 roberto Exp $
1+
-- $Id: constructs.lua,v 1.39 2015/03/04 13:09:38 roberto Exp $
22

33
;;print "testing syntax";;
44

@@ -228,7 +228,7 @@ a,b = F(nil)==nil; assert(a == true and b == nil)
228228
------------------------------------------------------------------
229229

230230
-- sometimes will be 0, sometimes will not...
231-
_ENV.GLOB1 = os.time() % 2
231+
_ENV.GLOB1 = math.floor(os.time()) % 2
232232

233233
-- basic expressions with their respective values
234234
local basiccases = {
@@ -284,7 +284,7 @@ local i = 0
284284
for n = 1, level do
285285
for _, v in pairs(cases[n]) do
286286
local s = v[1]
287-
local p = load(string.format(prog, s, s))
287+
local p = load(string.format(prog, s, s), "")
288288
IX = false
289289
assert(p() == v[2] and IX == not not v[2])
290290
i = i + 1

coroutine.lua

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- $Id: coroutine.lua,v 1.37 2014/12/26 17:20:53 roberto Exp $
1+
-- $Id: coroutine.lua,v 1.39 2015/04/14 18:05:03 roberto Exp $
22

33
print "testing coroutines"
44

@@ -362,6 +362,44 @@ else
362362
assert(_G.XX == 20 and c == 5)
363363
_G.X = nil; _G.XX = nil
364364

365+
do
366+
-- testing debug library on a coroutine suspended inside a hook
367+
-- (bug in 5.2/5.3)
368+
c = coroutine.create(function (a, ...)
369+
T.sethook("yield 0", "l") -- will yield on next two lines
370+
assert(a == 10)
371+
return ...
372+
end)
373+
374+
assert(coroutine.resume(c, 1, 2, 3)) -- start coroutine
375+
local n,v = debug.getlocal(c, 0, 1) -- check its local
376+
assert(n == "a" and v == 1)
377+
n,v = debug.getlocal(c, 0, -1) -- check varargs
378+
assert(v == 2)
379+
n,v = debug.getlocal(c, 0, -2)
380+
assert(v == 3)
381+
assert(debug.setlocal(c, 0, 1, 10)) -- test 'setlocal'
382+
assert(debug.setlocal(c, 0, -2, 20))
383+
local t = debug.getinfo(c, 0) -- test 'getinfo'
384+
assert(t.currentline == t.linedefined + 1)
385+
assert(not debug.getinfo(c, 1)) -- no other level
386+
assert(coroutine.resume(c)) -- run next line
387+
v = {coroutine.resume(c)} -- finish coroutine
388+
assert(v[1] == true and v[2] == 2 and v[3] == 20 and v[4] == nil)
389+
assert(not coroutine.resume(c))
390+
end
391+
392+
do
393+
-- testing debug library on last function in a suspended coroutine
394+
-- (bug in 5.2/5.3)
395+
local c = coroutine.create(function () T.testC("yield 1", 10, 20) end)
396+
local a, b = coroutine.resume(c)
397+
assert(a and b == 20)
398+
assert(debug.getinfo(c, 0).linedefined == -1)
399+
a, b = debug.getlocal(c, 0, 2)
400+
assert(b == 10)
401+
end
402+
365403

366404
print "testing coroutine API"
367405

@@ -567,6 +605,47 @@ assert(run(function() return a .. b .. c .. a end,
567605
assert(run(function() return "a" .. "b" .. a .. "c" .. c .. b .. "x" end,
568606
{"concat", "concat", "concat"}) == "ab10chello12x")
569607

608+
609+
do -- a few more tests for comparsion operators
610+
local mt1 = {
611+
__le = function (a,b)
612+
coroutine.yield(10)
613+
return
614+
(type(a) == "table" and a.x or a) <= (type(b) == "table" and b.x or b)
615+
end,
616+
__lt = function (a,b)
617+
coroutine.yield(10)
618+
return
619+
(type(a) == "table" and a.x or a) < (type(b) == "table" and b.x or b)
620+
end,
621+
}
622+
local mt2 = { __lt = mt1.__lt } -- no __le
623+
624+
local function run (f)
625+
local co = coroutine.wrap(f)
626+
local res
627+
repeat
628+
res = co()
629+
until res ~= 10
630+
return res
631+
end
632+
633+
local function test ()
634+
local a1 = setmetatable({x=1}, mt1)
635+
local a2 = setmetatable({x=2}, mt2)
636+
assert(a1 < a2)
637+
assert(a1 <= a2)
638+
assert(1 < a2)
639+
assert(1 <= a2)
640+
assert(2 > a1)
641+
assert(2 >= a2)
642+
return true
643+
end
644+
645+
run(test)
646+
647+
end
648+
570649
assert(run(function ()
571650
a.BB = print
572651
return a.BB

db.lua

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- $Id: db.lua,v 1.76 2015/01/01 13:52:01 roberto Exp $
1+
-- $Id: db.lua,v 1.77 2015/06/01 16:39:11 roberto Exp $
22

33
-- testing debug library
44

@@ -331,6 +331,19 @@ assert(debug.gethook() == nil)
331331

332332
-- testing access to function arguments
333333

334+
local function collectlocals (level)
335+
local tab = {}
336+
for i = 1, math.huge do
337+
local n, v = debug.getlocal(level + 1, i)
338+
if not (n and string.find(n, "^[a-zA-Z0-9_]+$")) then
339+
break -- consider only real variables
340+
end
341+
tab[n] = v
342+
end
343+
return tab
344+
end
345+
346+
334347
X = nil
335348
a = {}
336349
function a:f (a, b, ...) local arg = {...}; local c = 13 end
@@ -346,14 +359,7 @@ debug.sethook(function (e)
346359
assert(m == 'l' and c == 0)
347360
debug.sethook(nil) -- hook is called only once
348361
assert(not X) -- check that
349-
X = {}; local i = 1
350-
local x,y
351-
while 1 do
352-
x,y = debug.getlocal(2, i)
353-
if x==nil then break end
354-
X[x] = y
355-
i = i+1
356-
end
362+
X = collectlocals(2)
357363
end, "l")
358364
end, "c")
359365

@@ -363,6 +369,30 @@ assert(XX == 12)
363369
assert(debug.gethook() == nil)
364370

365371

372+
-- testing access to local variables in return hook (bug in 5.2)
373+
do
374+
local function foo (a, b)
375+
do local x,y,z end
376+
local c, d = 10, 20
377+
return
378+
end
379+
380+
local function aux ()
381+
if debug.getinfo(2).name == "foo" then
382+
foo = nil -- to signal that it found 'foo'
383+
local tab = {a = 100, b = 200, c = 10, d = 20}
384+
for n, v in pairs(collectlocals(2)) do
385+
assert(tab[n] == v)
386+
tab[n] = nil
387+
end
388+
assert(next(tab) == nil) -- 'tab' must be empty
389+
end
390+
end
391+
392+
debug.sethook(aux, "r"); foo(100, 200); debug.sethook()
393+
assert(foo == nil)
394+
end
395+
366396
-- testing upvalue access
367397
local function getupvalues (f)
368398
local t = {}

errors.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- $Id: errors.lua,v 1.89 2014/12/26 17:20:53 roberto Exp $
1+
-- $Id: errors.lua,v 1.90 2015/04/30 14:16:36 roberto Exp $
22

33
print("testing errors")
44

@@ -488,8 +488,7 @@ testrep("", "function foo () ", "", " end")
488488
testrep("a=", "a..", "a", "")
489489
testrep("a=", "a^", "a", "")
490490

491-
checkmessage("a = f(x" .. string.rep(",x", 260) .. ")",
492-
"expression too complex")
491+
checkmessage("a = f(x" .. string.rep(",x", 260) .. ")", "too many registers")
493492

494493

495494
-- testing other limits

0 commit comments

Comments
 (0)