issue #86 merge all remaining tests from Lua 5.3.3

pull/93/merge
Dibyendu Majumdar 8 years ago
parent 5cb71a81ef
commit c3c11c04e7

@ -1,5 +1,5 @@
#!../lua
-- $Id: all.lua,v 1.93 2015/05/15 12:28:08 roberto Exp $
-- $Id: all.lua,v 1.94 2015/09/17 16:45:19 roberto Exp $
local version = "Ravi 5.3"
if _VERSION ~= version then
@ -254,7 +254,7 @@ print(format("\n\ntotal time: %.2fs (wall time: %gs)\n", clocktime, walltime))
if not usertests then
lasttime = lasttime or clocktime -- if no last time, ignore difference
-- check whether current test time differs more than 5% from last time
local diff = (clocktime - lasttime) / clocktime
local diff = (clocktime - lasttime) / lasttime
local tolerance = 0.05 -- 5%
if (diff >= tolerance or diff <= -tolerance) then
print(format("WARNING: time difference from previous test: %+.1f%%",

@ -1,4 +1,4 @@
-- $Id: api.lua,v 1.145 2015/11/13 13:45:58 roberto Exp $
-- $Id: api.lua,v 1.146 2016/01/07 16:45:45 roberto Exp $
if T==nil then
(Message or print)('\n >>> testC not active: skipping API tests <<<\n')
@ -395,7 +395,7 @@ if not _soft then
-- too deep (with no message)
checkerr("^stack overflow$", T.testC, "checkstack 1000023 ''")
local s = string.rep("pushnil;checkstack 1 XX;", 1000000)
checkerr("XX", T.testC, s)
checkerr("overflow", T.testC, s)
collectgarbage("restart")
print'+'
end

@ -1,4 +1,4 @@
-- $Id: attrib.lua,v 1.63 2015/10/08 15:57:22 roberto Exp $
-- $Id: attrib.lua,v 1.64 2016/01/07 16:46:37 roberto Exp $
print "testing require"
@ -360,6 +360,10 @@ assert(not not a == true)
assert(not not (6 or nil) == true)
assert(not not (nil and 56) == false)
assert(not not (nil and true) == false)
assert(not 10 == false)
assert(not {} == false)
assert(not 0.5 == false)
assert(not "x" == false)
assert({} ~= {})
print('+')

@ -554,6 +554,8 @@ assert(t.isvararg == true and t.nparams == 0 and t.nups == 1 and
debug.getupvalue(t.func, 1) == "_ENV")
-- testing debugging of coroutines
local function checktraceback (co, p, level)

@ -1,4 +1,4 @@
-- $Id: errors.lua,v 1.91 2015/10/12 16:39:56 roberto Exp $
-- $Id: errors.lua,v 1.92 2016/03/07 19:27:08 roberto Exp $
print("testing errors")
@ -144,11 +144,16 @@ checkmessage([[
]], "light userdata")
_G.D = nil
do -- named userdata
do -- named objects (field '__name')
checkmessage("math.sin(io.input())", "(number expected, got FILE*)")
_ENV.XX = setmetatable({}, {__name = "My Type"})
_G.XX = setmetatable({}, {__name = "My Type"})
checkmessage("io.input(XX)", "(FILE* expected, got My Type)")
_ENV.XX = nil
checkmessage("return XX + 1", "on a My Type value")
checkmessage("return ~io.stdin", "on a FILE* value")
checkmessage("return XX < XX", "two My Type values")
checkmessage("return {} < XX", "table with My Type")
checkmessage("return XX < io.stdin", "My Type with FILE*")
_G.XX = nil
end
-- global functions

@ -1,4 +1,4 @@
-- $Id: events.lua,v 1.42 2015/10/08 15:58:34 roberto Exp $
-- $Id: events.lua,v 1.43 2016/01/14 16:27:25 roberto Exp $
print('testing metatables')
@ -57,6 +57,14 @@ t.__newindex = f
a[1] = 30; a.x = "101"; a[5] = 200
assert(a[1] == 27 and a.x == 98 and a[5] == 197)
do -- bug in Lua 5.3.2
local mt = {}
mt.__newindex = mt
local t = setmetatable({}, mt)
t[1] = 10 -- will segfault on some machines
assert(mt[1] == 10)
end
local c = {}
a = setmetatable({}, t)

@ -1,4 +1,4 @@
-- $Id: files.lua,v 1.91 2015/10/08 15:58:59 roberto Exp $
-- $Id: files.lua,v 1.93 2016/04/13 16:25:31 roberto Exp $
local debug = require "debug"
@ -710,9 +710,9 @@ if not _port then
-- test out-of-range dates (at least for Unix)
if maxint >= 2^62 then -- cannot do these tests in Small Lua
-- no arith overflows
checkerr("out-of-bounds", os.time, {year = -maxint, month = 1, day = 1})
checkerr("out-of-bound", os.time, {year = -maxint, month = 1, day = 1})
if string.packsize("i") == 4 then -- 4-byte ints
if testerr("out-of-bounds", os.date, "%Y", 2^40) then
if testerr("out-of-bound", os.date, "%Y", 2^40) then
-- time_t has 4 bytes and therefore cannot represent year 4000
print(" 4-byte time_t")
checkerr("cannot be represented", os.time, {year=4000, month=1, day=1})
@ -769,14 +769,23 @@ local t1 = os.time{year=2000, month=10, day=1, hour=23, min=12}
local t2 = os.time{year=2000, month=10, day=1, hour=23, min=10, sec=19}
assert(os.difftime(t1,t2) == 60*2-19)
-- since 5.3.3, 'os.time' normalizes table fields
t1 = {year = 2005, month = 1, day = 1, hour = 1, min = 0, sec = -3602}
os.time(t1)
assert(t1.day == 31 and t1.month == 12 and t1.year == 2004 and
t1.hour == 23 and t1.min == 59 and t1.sec == 58 and
t1.yday == 366)
io.output(io.stdout)
local d = tonumber(os.date('%d'))
local m = tonumber(os.date('%m'))
local a = tonumber(os.date('%Y'))
local ds = tonumber(os.date('%w')) + 1
local h = tonumber(os.date('%H'))
local min = tonumber(os.date('%M'))
local s = tonumber(os.date('%S'))
local t = os.date('%d %m %Y %H %M %S')
local d, m, a, h, min, s = string.match(t,
"(%d+) (%d+) (%d+) (%d+) (%d+) (%d+)")
d = tonumber(d)
m = tonumber(m)
a = tonumber(a)
h = tonumber(h)
min = tonumber(min)
s = tonumber(s)
io.write(string.format('test done on %2.2d/%2.2d/%d', d, m, a))
io.write(string.format(', at %2.2d:%2.2d:%2.2d\n', h, min, s))
io.write(string.format('%s\n', _VERSION))

@ -1,4 +1,4 @@
-- $Id: gc.lua,v 1.70 2015/03/04 13:09:38 roberto Exp $
-- $Id: gc.lua,v 1.71 2016/03/07 19:31:35 roberto Exp $
print('testing garbage collection')
@ -547,8 +547,8 @@ if T then -- tests for weird cases collecting upvalues
collectgarbage()
collectgarbage"stop"
T.gcstate"atomic"
local x = {}
T.gcstate"sweepallgc"
local x = {}
assert(T.gccolor(u) == "black") -- upvalue is "old" (black)
assert(T.gccolor(x) == "white") -- table is "new" (white)
debug.setuservalue(u, x) -- trigger barrier

@ -1,4 +1,4 @@
-- $Id: goto.lua,v 1.11 2014/12/26 17:20:53 roberto Exp $
-- $Id: goto.lua,v 1.12 2016/03/07 19:26:18 roberto Exp $
collectgarbage()
@ -112,6 +112,20 @@ end
::l6:: foo()
do -- bug in 5.2 -> 5.3.2
local x
::L1::
local y -- cannot join this SETNIL with previous one
assert(y == nil)
y = true
if x == nil then
x = 1
goto L1
else
x = x + 1
end
assert(x == 2 and y == true)
end
--------------------------------------------------------------------------------
-- testing closing of upvalues

@ -1,5 +1,5 @@
# testing special comment on first line
-- $Id: main.lua,v 1.63 2015/09/08 17:16:34 roberto Exp $
-- $Id: main.lua,v 1.64 2016/04/13 16:25:59 roberto Exp $
-- most (all?) tests here assume a reasonable "Unix-like" shell
if _port then return end
@ -132,7 +132,7 @@ RUN('env LUA_INIT="@%s" lua %s > %s', prog, prog, out)
checkout("10\n11\n")
-- test errors in LUA_INIT
NoRun('LUA_INIT:1: 10', 'env LUA_INIT="error(10)" lua')
NoRun('LUA_INIT:1: msg', 'env LUA_INIT="error(\'msg\')" lua')
-- test option '-E'
local defaultpath, defaultCpath

@ -1,4 +1,4 @@
-- $Id: math.lua,v 1.72 2015/06/09 15:55:13 roberto Exp $
-- $Id: math.lua,v 1.76 2016/05/30 15:55:38 roberto Exp $
print("testing numbers and math lib")
@ -21,6 +21,11 @@ do
end
end
local function isNaN (x)
return (x ~= x)
-- return true
end
do
local x = 2.0^floatbits
@ -93,7 +98,7 @@ do -- tests for 'modf'
a,b = math.modf(1/0) -- inf
assert(a == 1/0 and b == 0.0)
a,b = math.modf(0/0) -- NaN
assert(a ~= a and b ~= b)
assert(isNaN(a) and isNaN(b))
a,b = math.modf(3) -- integer argument
assert(eqT(a, 3) and eqT(b, 0.0))
a,b = math.modf(minint)
@ -314,12 +319,48 @@ assert(" -2 " + 1 == -1)
assert(" -0xa " + 1 == -9)
-- Literal integer Overflows (new behavior in 5.3.3)
do
-- no overflows
assert(eqT(tonumber(tostring(maxint)), maxint))
assert(eqT(tonumber(tostring(minint)), minint))
-- add 1 to last digit as a string (it cannot be 9...)
local function incd (n)
local s = string.format("%d", n)
s = string.gsub(s, "%d$", function (d)
assert(d ~= '9')
return string.char(string.byte(d) + 1)
end)
return s
end
-- 'tonumber' with overflow by 1
assert(eqT(tonumber(incd(maxint)), maxint + 1.0))
assert(eqT(tonumber(incd(minint)), minint - 1.0))
-- large numbers
assert(eqT(tonumber("1"..string.rep("0", 30)), 1e30))
assert(eqT(tonumber("-1"..string.rep("0", 30)), -1e30))
-- hexa format still wraps around
assert(eqT(tonumber("0x1"..string.rep("0", 30)), 0))
-- lexer in the limits
assert(minint == load("return " .. minint)())
assert(eqT(maxint, load("return " .. maxint)()))
assert(eqT(10000000000000000000000.0, 10000000000000000000000))
assert(eqT(-10000000000000000000000.0, -10000000000000000000000))
end
-- testing 'tonumber'
-- 'tonumber' with numbers
assert(tonumber(3.4) == 3.4)
assert(tonumber(3) == 3 and math.type(tonumber(3)) == "integer")
assert(tonumber(maxint) == maxint and tonumber(minint) == minint)
assert(eqT(tonumber(3), 3))
assert(eqT(tonumber(maxint), maxint) and eqT(tonumber(minint), minint))
assert(tonumber(1/0) == 1/0)
-- 'tonumber' with strings
@ -457,10 +498,9 @@ assert(0Xabcdef.0 == 0x.ABCDEFp+24)
assert(1.1 == 1.+.1)
assert(100.0 == 1E2 and .01 == 1e-2)
assert(1111111111111111-1111111111111110== 1000.00e-03)
-- 1234567890123456
assert(1111111111 - 1111111110 == 1000.00e-03)
assert(1.1 == '1.'+'.1')
assert(tonumber'1111111111111111'-tonumber'1111111111111110' ==
assert(tonumber'1111111111' - tonumber'1111111110' ==
tonumber" +0.001e+3 \n\t")
assert(0.1e-30 > 0.9E-31 and 0.9E30 < 0.1e31)
@ -501,7 +541,7 @@ assert(maxint % -2 == -1)
-- non-portable tests because Windows C library cannot compute
-- fmod(1, huge) correctly
if not _port then
local function anan (x) assert(x ~= x) end -- assert Not a Number
local function anan (x) assert(isNaN(x)) end -- assert Not a Number
anan(0.0 % 0)
anan(1.3 % 0)
anan(math.huge % 1)

@ -1,4 +1,4 @@
-- $Id: sort.lua,v 1.36 2015/11/23 16:42:56 roberto Exp $
-- $Id: sort.lua,v 1.37 2016/03/07 19:27:51 roberto Exp $
print "testing (parts of) table library"
@ -104,13 +104,20 @@ do
a = table.move({10, 20, 30}, 1, 3, 3)
eqT(a, {10, 20, 10, 20, 30})
-- moving to the same table (not being explicit about it)
a = {10, 20, 30, 40}
table.move(a, 1, 4, 2, a)
eqT(a, {10, 10, 20, 30, 40})
a = table.move({10,20,30}, 2, 3, 1) -- move backward
eqT(a, {20,30,30})
a = table.move({10,20,30}, 1, 3, 1, {}) -- move to new table
a = {} -- move to new table
assert(table.move({10,20,30}, 1, 3, 1, a) == a)
eqT(a, {10,20,30})
a = table.move({10,20,30}, 1, 0, 3, {}) -- empty move (no move)
a = {}
assert(table.move({10,20,30}, 1, 0, 3, a) == a) -- empty move (no move)
eqT(a, {})
a = table.move({10,20,30}, 1, 10, 1) -- move to the same place

@ -1,4 +1,4 @@
-- $Id: strings.lua,v 1.81 2015/11/25 16:56:54 roberto Exp $
-- $Id: strings.lua,v 1.85 2016/05/20 14:15:57 roberto Exp $
print('testing strings and string library')
@ -130,10 +130,10 @@ assert(tostring(-1203) == "-1203")
assert(tostring(1203.125) == "1203.125")
assert(tostring(-0.5) == "-0.5")
assert(tostring(-32767) == "-32767")
if 2147483647 > 0 then -- no overflow? (32 bits)
if math.tointeger(2147483647) then -- no overflow? (32 bits)
assert(tostring(-2147483647) == "-2147483647")
end
if 4611686018427387904 > 0 then -- no overflow? (64 bits)
if math.tointeger(4611686018427387904) then -- no overflow? (64 bits)
assert(tostring(4611686018427387904) == "4611686018427387904")
assert(tostring(-4611686018427387904) == "-4611686018427387904")
end
@ -171,6 +171,23 @@ assert(string.format("-%.20s.20s", string.rep("%", 2000)) ==
assert(string.format('"-%20s.20s"', string.rep("%", 2000)) ==
string.format("%q", "-"..string.rep("%", 2000)..".20s"))
do
local function checkQ (v)
local s = string.format("%q", v)
local nv = load("return " .. s)()
assert(v == nv and math.type(v) == math.type(nv))
end
checkQ("\0\0\1\255\u{234}")
checkQ(math.maxinteger)
checkQ(math.mininteger)
checkQ(math.pi)
checkQ(0.1)
checkQ(true)
checkQ(nil)
checkQ(false)
checkerror("no literal", string.format, "%q", {})
end
assert(string.format("\0%s\0", "\0\0\1") == "\0\0\0\1\0")
checkerror("contains zeros", string.format, "%10s", "\0")
@ -184,7 +201,7 @@ assert(string.format("%s %.10s", m, m) == "hello hello")
assert(string.format("%x", 0.0) == "0")
assert(string.format("%02x", 0.0) == "00")
assert(string.format("%08X", 4294967295) == "FFFFFFFF")
assert(string.format("%08X", 0xFFFFFFFF) == "FFFFFFFF")
assert(string.format("%+08d", 31501) == "+0031501")
assert(string.format("%+08d", -30927) == "-0030927")
@ -312,23 +329,23 @@ assert(table.concat(a, ",", 4) == "")
if not _port then
local locales = { "ptb", "ISO-8859-1", "pt_BR" }
local locales = { "ptb", "pt_BR.iso88591", "ISO-8859-1" }
local function trylocale (w)
for i = 1, #locales do
if os.setlocale(locales[i], w) then return true end
if os.setlocale(locales[i], w) then
print(string.format("'%s' locale set to '%s'", w, locales[i]))
return locales[i]
end
end
print(string.format("'%s' locale not found", w))
return false
end
if not trylocale("collate") then
print("locale not supported")
else
if trylocale("collate") then
assert("alo" < "álo" and "álo" < "amo")
end
if not trylocale("ctype") then
print("locale not supported")
else
if trylocale("ctype") then
assert(string.gsub("áéíóú", "%a", "x") == "xxxxx")
assert(string.gsub("áÁéÉ", "%l", "x") == "xÁxÉ")
assert(string.gsub("áÁéÉ", "%u", "x") == "áxéx")
@ -341,5 +358,15 @@ if not _port then
end
-- bug in Lua 5.3.2
-- 'gmatch' iterator does not work across coroutines
do
local f = string.gmatch("1 2 3 4 5", "%d+")
assert(f() == "1")
co = coroutine.wrap(f)
assert(co() == "2")
end
print('OK')

Loading…
Cancel
Save