From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id EA54971862; Thu, 4 Mar 2021 13:25:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EA54971862 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1614853558; bh=53nezMF9EUaQr2sx5L6kxffuHboNLRPSz8aY/ELH9xA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=kDhRZ0+44Kr8YHutAp7y+8lCNbPr1DyxuPxm1w4eo7Jb6hZAEjv4a9Z7w9lytHISt ZhkSlihROjtm07qSyEmZtHziZvKv57GTx58TK61qcS+SPFnIhR6D+zWJxMyXbZfQed TEiVfw6Kexzqzyadbqqyn/QAiY8Ldfc/Y5QB4ITo= Received: from smtp48.i.mail.ru (smtp48.i.mail.ru [94.100.177.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 315666C186 for ; Thu, 4 Mar 2021 13:24:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 315666C186 Received: by smtp48.i.mail.ru with esmtpa (envelope-from ) id 1lHlA7-0000fx-4q; Thu, 04 Mar 2021 13:24:55 +0300 To: Sergey Ostanevich , Igor Munkin Date: Thu, 4 Mar 2021 13:23:49 +0300 Message-Id: X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92A98208ECBDD29F5A6709E93A77B8502A831FF4624BDF5D2182A05F5380850409F39048942F2700C0C866F7C93BD9C089977C885E87AC6CB913BB2FC8F706466 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE721AF84DC1D70954DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637B84F9009663064BD8638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC7FFBF58D524698ADF0AFAF961E0A2F4B6DDCD83F5A3A6F77389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0D9442B0B5983000E8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6D082881546D93491CC7F00164DA146DA6F5DAA56C3B73B23C77107234E2CFBA567F23339F89546C55F5C1EE8F4F765FCC6A536F79815AD9275ECD9A6C639B01BBD4B6F7A4D31EC0BC0CAF46E325F83A522CA9DD8327EE4930A3850AC1BE2E735F65A62F6C9828292C4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F5D41B9178041F3E72623479134186CDE6BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C4C7A0BC55FA0FE5FC7FFBF58D524698ADF0AFAF961E0A2F4B88FAFA95A60CE4C4B1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDB791E6C230873D55CDC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3498EF79680EE3725C74E8A29F11AE1F2942F53FC7050B8BFA062ECE2682EE37E0615A2BDA490A86241D7E09C32AA3244CEE753706086AE47DDD699287316485F3435BF7150578642F927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojSsmoOoMLSh1HRwG6uBxObA== X-Mailru-Sender: 3B9A0136629DC91206CBC582EFEF4CB43ED66D791259DA68ABF93359CF19A829EA962A18810D93AFF2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A89437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: [Tarantool-patches] [WIP luajit 02/15] test: adapt PUC-Rio Lua 5.1 test suite for LuaJIT X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" In some insignificant details LuaJIT's behaviour is not the same as the behaviour of Lua 5.1. Tests in the following files are disabled with corresponding comments: * closure.lua * constructs.lua * db.lua * errors.lua * literals.lua * main.lua * math.lua * nextvar.lua * pm.lua * strings.lua * vararg.lua jit.off() as prologue and jit.on() as epilogue is added to one test chunk in gc.lua for stable (JIT unrelated) GC test results. Part of tarantool/tarantool#5845 Part of tarantool/tarantool#4473 --- test/PUC-Lua-5.1-tests/closure.lua | 12 ++++- test/PUC-Lua-5.1-tests/constructs.lua | 7 +++ test/PUC-Lua-5.1-tests/db.lua | 75 ++++++++++++++++++++------- test/PUC-Lua-5.1-tests/errors.lua | 28 +++++++--- test/PUC-Lua-5.1-tests/gc.lua | 5 ++ test/PUC-Lua-5.1-tests/literals.lua | 5 ++ test/PUC-Lua-5.1-tests/main.lua | 56 ++++++++++++++------ test/PUC-Lua-5.1-tests/math.lua | 7 ++- test/PUC-Lua-5.1-tests/nextvar.lua | 7 +++ test/PUC-Lua-5.1-tests/pm.lua | 6 ++- test/PUC-Lua-5.1-tests/strings.lua | 17 +++++- test/PUC-Lua-5.1-tests/vararg.lua | 20 ++++--- 12 files changed, 195 insertions(+), 50 deletions(-) diff --git a/test/PUC-Lua-5.1-tests/closure.lua b/test/PUC-Lua-5.1-tests/closure.lua index 27ca0ad..e9bd564 100644 --- a/test/PUC-Lua-5.1-tests/closure.lua +++ b/test/PUC-Lua-5.1-tests/closure.lua @@ -174,7 +174,10 @@ f = coroutine.wrap(foo) local a = {} assert(f(a) == _G) local a,b = pcall(f) -assert(a and b == _G) +-- LuaJIT getfenv() behaviour is different in tail calls. +-- See also https://github.com/tarantool/tarantool/issues/5713. +-- Test is disabled for LuaJIT for now. +-- assert(a and b == _G) -- tests for multiple yield/resume arguments @@ -261,6 +264,12 @@ end local x = gen(100) local a = {} +-- In Lua 5.1 math.mod() is renamed to math.fmod() if build +-- Lua 5.1 without flag `-DLUA_COMPAT_MOD`. +-- LuaJIT also has math.fmod() instead math.mod() builtin. +-- See also https://github.com/tarantool/tarantool/issues/5711. +-- Test is disabled. +--[=[ while 1 do local n = x() if n == nil then break end @@ -269,6 +278,7 @@ while 1 do end assert(table.getn(a) == 25 and a[table.getn(a)] == 97) +--]=] -- errors in coroutines diff --git a/test/PUC-Lua-5.1-tests/constructs.lua b/test/PUC-Lua-5.1-tests/constructs.lua index 5fb3798..6776ee6 100644 --- a/test/PUC-Lua-5.1-tests/constructs.lua +++ b/test/PUC-Lua-5.1-tests/constructs.lua @@ -200,6 +200,12 @@ a,b = F(nil)==nil; assert(a == true and b == nil) function ID(x) return x end +-- In Lua 5.1 math.mod() is renamed to math.fmod() if build +-- Lua 5.1 without flag `-DLUA_COMPAT_MOD`. +-- LuaJIT also has math.fmod() instead math.mod() builtin. +-- See also https://github.com/tarantool/tarantool/issues/5711. +-- Test is disabled. +--[=[ function f(t, i) local b = t.n local res = math.mod(math.floor(i/c), b)+1 @@ -236,5 +242,6 @@ repeat if math.mod(i,4000) == 0 then print('+') end i = i+1 until i==c +--]=] print'OK' diff --git a/test/PUC-Lua-5.1-tests/db.lua b/test/PUC-Lua-5.1-tests/db.lua index 9d2c86f..591a006 100644 --- a/test/PUC-Lua-5.1-tests/db.lua +++ b/test/PUC-Lua-5.1-tests/db.lua @@ -95,6 +95,10 @@ repeat assert(g(f) == 'a') until 1 +-- LuaJIT interprets a return from calling result of loadstring() +-- with a new line number unlike Lua does. +-- See also https://github.com/tarantool/tarantool/issues/5693. +--[=[ test([[if math.sin(1) then @@ -149,7 +153,7 @@ end ]], {1,2,1,2,1,3}) test([[for i=1,4 do a=1 end]], {1,1,1,1,1}) - +--]=] print'+' @@ -178,8 +182,13 @@ function f(a,b) local _, x = debug.getlocal(1, 1) local _, y = debug.getlocal(1, 2) assert(x == a and y == b) - assert(debug.setlocal(2, 3, "pera") == "AA".."AA") - assert(debug.setlocal(2, 4, "maçã") == "B") + -- f() function is called only from g(...) vararg function. + -- Lua 5.1 interprets ... in the vararg functions like additional + -- first argument unlike LuaJIT does. + -- This extension is from Lua 5.2. + -- See also https://github.com/tarantool/tarantool/issues/5694. + -- assert(debug.setlocal(2, 3, "pera") == "AA".."AA") + -- assert(debug.setlocal(2, 4, "maçã") == "B") x = debug.getinfo(2) assert(x.func == g and x.what == "Lua" and x.name == 'g' and x.nups == 0 and string.find(x.source, "^@.*db%.lua")) @@ -208,11 +217,13 @@ function g(...) local feijao local AAAA,B = "xuxu", "mamão" f(AAAA,B) - assert(AAAA == "pera" and B == "maçã") + -- Test is disabled for LuaJIT for now. See comment in f(). + -- assert(AAAA == "pera" and B == "maçã") do local B = 13 local x,y = debug.getlocal(1,5) - assert(x == 'B' and y == 13) + -- Test is disabled for LuaJIT for now. See comment in f(). + -- assert(x == 'B' and y == 13) end end @@ -276,7 +287,8 @@ debug.sethook(function (e) end, "c") a:f(1,2,3,4,5) -assert(X.self == a and X.a == 1 and X.b == 2 and X.arg.n == 3 and X.c == nil) +-- Test is disabled for LuaJIT for now. See comment in f(). +-- assert(X.self == a and X.a == 1 and X.b == 2 and X.arg.n == 3 and X.c == nil) assert(XX == 12) assert(debug.gethook() == nil) @@ -314,12 +326,20 @@ assert(debug.setupvalue(io.read, 1, 10) == nil) -- testing count hooks local a=0 +-- LuaJIT does not check hooks at traces without defined +-- -DLUAJIT_ENABLE_CHECKHOOK. +-- For more information see or commit +-- 6bce6b118eeb2bb7f36157de158e5cccf0ea68e5 (Add compile-time +-- option LUAJIT_ENABLE_CHECKHOOK. Disabled by default.). +-- See also https://github.com/tarantool/tarantool/issues/5701. +--[[ debug.sethook(function (e) a=a+1 end, "", 1) a=0; for i=1,1000 do end; assert(1000 < a and a < 1012) debug.sethook(function (e) a=a+1 end, "", 4) a=0; for i=1,1000 do end; assert(250 < a and a < 255) local f,m,c = debug.gethook() assert(m == "" and c == 4) +--]] debug.sethook(function (e) a=a+1 end, "", 4000) a=0; for i=1,1000 do end; assert(a == 0) debug.sethook(print, "", 2^24 - 1) -- count upperbound @@ -352,18 +372,24 @@ function g1(x) g(x) end local function h (x) local f=g1; return f(x) end -h(true) +-- LuaJIT does not provide information about tail calls, +-- unlike Lua does. getfenv() behaviour is also different here. +-- Test is disabled for LuaJIT for now. +-- See also https://github.com/tarantool/tarantool/issues/5702. +-- h(true) local b = {} -debug.sethook(function (e) table.insert(b, e) end, "cr") -h(false) -debug.sethook() +-- Behavior is different for LuaJIT. See the comment above. +-- debug.sethook(function (e) table.insert(b, e) end, "cr") +-- h(false) +-- debug.sethook() local res = {"return", -- first return (from sethook) "call", "call", "call", "call", "return", "tail return", "return", "tail return", "call", -- last call (to sethook) } -for _, k in ipairs(res) do assert(k == table.remove(b, 1)) end +-- Behavior is different for LuaJIT. See the comment above. +-- for _, k in ipairs(res) do assert(k == table.remove(b, 1)) end lim = 30000 @@ -375,7 +401,8 @@ local function foo (x) end end -foo(lim) +-- Behavior is different for LuaJIT. See the comment above. +-- foo(lim) print"+" @@ -411,7 +438,11 @@ end local co = coroutine.create(f) coroutine.resume(co, 3) -checktraceback(co, {"yield", "db.lua", "tail", "tail", "tail"}) +-- LuaJIT does not provide information about tail calls, +-- unlike Lua does. +-- See also https://github.com/tarantool/tarantool/issues/5703. +-- Test is disabled for LuaJIT for now. +-- checktraceback(co, {"yield", "db.lua", "tail", "tail", "tail"}) co = coroutine.create(function (x) @@ -429,8 +460,12 @@ local _, l = coroutine.resume(co, 10) local x = debug.getinfo(co, 1, "lfLS") assert(x.currentline == l.currentline and x.activelines[x.currentline]) assert(type(x.func) == "function") +-- LuaJIT does not report line with single "end" statement as +-- an active line in debug.getinfo(), unlike Lua does. +-- See also https://github.com/tarantool/tarantool/issues/5708. +-- Test is disabled for LuaJIT for now. for i=x.linedefined + 1, x.lastlinedefined do - assert(x.activelines[i]) + -- assert(x.activelines[i]) x.activelines[i] = nil end assert(next(x.activelines) == nil) -- no 'extra' elements @@ -441,8 +476,10 @@ a,b = debug.getlocal(co, 1, 2) assert(a == "a" and b == 1) debug.setlocal(co, 1, 2, "hi") assert(debug.gethook(co) == foo) -assert(table.getn(tr) == 2 and - tr[1] == l.currentline-1 and tr[2] == l.currentline) +-- LuaJIT does not support per-coroutine hooks. +-- Test is disabled for LuaJIT. +-- assert(table.getn(tr) == 2 and +-- tr[1] == l.currentline-1 and tr[2] == l.currentline) a,b,c = pcall(coroutine.resume, co) assert(a and b and c == l.currentline+1) @@ -450,9 +487,11 @@ checktraceback(co, {"yield", "in function <"}) a,b = coroutine.resume(co) assert(a and b == "hi") -assert(table.getn(tr) == 4 and tr[4] == l.currentline+2) +-- Behavior is different for LuaJIT. See the comment above. +-- assert(table.getn(tr) == 4 and tr[4] == l.currentline+2) assert(debug.gethook(co) == foo) -assert(debug.gethook() == nil) +-- Behavior is different for LuaJIT. See the comment above. +-- assert(debug.gethook() == nil) checktraceback(co, {}) diff --git a/test/PUC-Lua-5.1-tests/errors.lua b/test/PUC-Lua-5.1-tests/errors.lua index e881211..3270033 100644 --- a/test/PUC-Lua-5.1-tests/errors.lua +++ b/test/PUC-Lua-5.1-tests/errors.lua @@ -72,8 +72,12 @@ checkmessage("b=1; local aaa='a'; x=aaa+b", "local 'aaa'") checkmessage("aaa={}; x=3/aaa", "global 'aaa'") checkmessage("aaa='2'; b=nil;x=aaa*b", "global 'b'") checkmessage("aaa={}; x=-aaa", "global 'aaa'") -assert(not string.find(doit"aaa={}; x=(aaa or aaa)+(aaa and aaa)", "'aaa'")) -assert(not string.find(doit"aaa={}; (aaa or aaa)()", "'aaa'")) +-- LuaJIT reports the error as the following here: +-- "attempt to perform arithmetic on global 'aaa' (a table value)" +-- Lua 5.1 doesn't report variable name here. +-- Test is disabled for LuaJIT. +-- assert(not string.find(doit"aaa={}; x=(aaa or aaa)+(aaa and aaa)", "'aaa'")) +-- assert(not string.find(doit"aaa={}; (aaa or aaa)()", "'aaa'")) checkmessage([[aaa=9 repeat until 3==3 @@ -100,9 +104,12 @@ while 1 do insert(prefix, a) end]], "global 'insert'") -checkmessage([[ -- tail call - return math.sin("a") -]], "'sin'") +-- Implementation of fast functions in LuaJIT does not provide +-- enough info on failure. +-- Test is disabled for LuaJIT. +-- checkmessage([[ -- tail call +-- return math.sin("a") +-- ]], "'sin'") checkmessage([[collectgarbage("nooption")]], "invalid option") @@ -193,7 +200,11 @@ checksyntax("[[a]]", "", "[[a]]", 1) checksyntax("'aa'", "", "'aa'", 1) -- test 255 as first char in a chunk -checksyntax("\255a = 1", "", "\255", 1) +-- LuaJIT does not avoid to use non-alphabetic symbols +-- as identifiers, unlike Lua does. +-- For more details see and . +-- Test is disabled for LuaJIT. +-- checksyntax("\255a = 1", "", "\255", 1) doit('I = loadstring("a=9+"); a=3') assert(a==3 and I == nil) @@ -215,7 +226,10 @@ local function testrep (init, rep) end testrep("a=", "{") testrep("a=", "(") -testrep("", "a(") +-- When compiled with LUAJIT_ENABLE_GC64 LJ_MAX_SLOTS limit +-- is reached and error is LJ_ERR_XSLOTS ("function or expression too +-- complex"). Test is disabled for LuaJIT. +-- testrep("", "a(") testrep("", "do ") testrep("", "while a do ") testrep("", "if a then else ") diff --git a/test/PUC-Lua-5.1-tests/gc.lua b/test/PUC-Lua-5.1-tests/gc.lua index 86a9f75..b767104 100644 --- a/test/PUC-Lua-5.1-tests/gc.lua +++ b/test/PUC-Lua-5.1-tests/gc.lua @@ -108,11 +108,16 @@ local function dosteps (siz) return i end +-- JIT compilation can unpredictable allocate or reference objects +-- (or traces itself). Disable it for this chunk for stable +-- GC results. +jit.off() assert(dosteps(0) > 10) assert(dosteps(6) < dosteps(2)) assert(dosteps(10000) == 1) assert(collectgarbage("step", 1000000) == true) assert(collectgarbage("step", 1000000)) +jit.on() do diff --git a/test/PUC-Lua-5.1-tests/literals.lua b/test/PUC-Lua-5.1-tests/literals.lua index 01d84d5..ee16a3e 100644 --- a/test/PUC-Lua-5.1-tests/literals.lua +++ b/test/PUC-Lua-5.1-tests/literals.lua @@ -158,6 +158,10 @@ end -- testing decimal point locale +-- LuaJIT doesn't use `strtod()` depended on the locale, unlike +-- Lua does. See for more info. +-- Tests are disabled for LuaJIT. +--[[ if os.setlocale("pt_BR") or os.setlocale("ptb") then assert(tonumber("3,4") == 3.4 and tonumber"3.4" == nil) assert(assert(loadstring("return 3.4"))() == 3.4) @@ -171,6 +175,7 @@ else (Message or print)( '\a\n >>> pt_BR locale not available: skipping decimal point tests <<<\n\a') end +--]] print('OK') diff --git a/test/PUC-Lua-5.1-tests/main.lua b/test/PUC-Lua-5.1-tests/main.lua index f520896..12f3981 100644 --- a/test/PUC-Lua-5.1-tests/main.lua +++ b/test/PUC-Lua-5.1-tests/main.lua @@ -65,9 +65,16 @@ a = string.format(a, progname) prepfile(a) RUN('lua "-e " -- %s a b c', prog) -prepfile"assert(arg==nil)" -prepfile("assert(arg)", otherprog) -RUN("lua -l%s - < %s", prog, otherprog) +-- test 'arg' availability in libraries +-- LuaJIT v2.1.0-beta3 has extension from Lua 5.3: +-- The argument table `arg` can be read (and modified) +-- by `LUA_INIT` and `-e` chunks. +-- See commit 92d9ff211ae864777a8580b5a7326d5f408161ce +-- (Set arg table before evaluating LUA_INIT and -e chunks.). +-- See also https://github.com/tarantool/tarantool/issues/5686. +-- prepfile"assert(arg==nil)" +-- prepfile("assert(arg)", otherprog) +-- RUN("lua -l%s - < %s", prog, otherprog) prepfile"" RUN("lua - < %s > %s", prog, out) @@ -89,26 +96,35 @@ prepfile[[ RUN("lua - < %s > %s", prog, out) checkout("1\tnil\n") +-- Version and status are printed in stdout instead stderr since +-- LuaJIT-2.0.0-beta11 (as it is not an error message). +-- See commit 0bd1a66f2f055211ef55834ccebca3b82d03c735 +-- (Print version and JIT status to stdout, not stderr.). +-- This behavior is the same as in Lua 5.2. +-- See also https://github.com/tarantool/tarantool/issues/5687. prepfile[[ = (6*2-6) -- === a = 10 print(a) = a]] -RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) -checkout("6\n10\n10\n\n") +-- Behavior is different for LuaJIT. See the comment above. +-- RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) +-- checkout("6\n10\n10\n\n") prepfile("a = [[b\nc\nd\ne]]\n=a") print(prog) -RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) -checkout("b\nc\nd\ne\n\n") +-- Behavior is different for LuaJIT. See the comment above. +-- RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) +-- checkout("b\nc\nd\ne\n\n") prompt = "alo" prepfile[[ -- a = 2 ]] -RUN([[lua "-e_PROMPT='%s'" -i < %s > %s]], prompt, prog, out) -checkout(string.rep(prompt, 3).."\n") +-- Behavior is different for LuaJIT. See the comment above. +-- RUN([[lua "-e_PROMPT='%s'" -i < %s > %s]], prompt, prog, out) +-- checkout(string.rep(prompt, 3).."\n") s = [=[ -- function f ( x ) @@ -126,19 +142,29 @@ assert( a == b ) =f( 11 ) ]=] s = string.gsub(s, ' ', '\n\n') prepfile(s) -RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) -checkout("11\n1\t2\n\n") +-- Behavior is different for LuaJIT. See the comment above. +-- RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) +-- checkout("11\n1\t2\n\n") prepfile[[#comment in 1st line without \n at the end]] RUN("lua %s", prog) +-- test loading and running bytecode files. +-- Loading bytecode with an extra header (BOM or "#") is disabled +-- for security reasons since LuaJIT-2.0.0-beta10. +-- For more information see comment for lj_lex_setup() +-- in . +-- Also see commit 53a285c0c3544ff5dea7c67b741c3c2d06d22b47 +-- (Disable loading bytecode with an extra header (BOM or #!).). +-- See also https://github.com/tarantool/tarantool/issues/5691. prepfile("#comment with a binary file\n"..string.dump(loadstring("print(1)"))) -RUN("lua %s > %s", prog, out) -checkout("1\n") +-- RUN("lua %s > %s", prog, out) +-- checkout("1\n") prepfile("#comment with a binary file\r\n"..string.dump(loadstring("print(1)"))) -RUN("lua %s > %s", prog, out) -checkout("1\n") +-- Behavior is different for LuaJIT. See the comment above. +-- RUN("lua %s > %s", prog, out) +-- checkout("1\n") -- close Lua with an open file prepfile(string.format([[io.output(%q); io.write('alo')]], out)) diff --git a/test/PUC-Lua-5.1-tests/math.lua b/test/PUC-Lua-5.1-tests/math.lua index 5076f38..b46a3f5 100644 --- a/test/PUC-Lua-5.1-tests/math.lua +++ b/test/PUC-Lua-5.1-tests/math.lua @@ -100,7 +100,12 @@ assert(math.abs(-10) == 10) assert(eq(math.atan2(1,0), math.pi/2)) assert(math.ceil(4.5) == 5.0) assert(math.floor(4.5) == 4.0) -assert(math.mod(10,3) == 1) +-- In Lua 5.1 math.mod() is renamed to math.fmod() if build +-- Lua 5.1 without flag `-DLUA_COMPAT_MOD`. +-- LuaJIT also has math.fmod() instead math.mod() builtin. +-- See also https://github.com/tarantool/tarantool/issues/5711. +-- Test is disabled. +-- assert(math.mod(10,3) == 1) assert(eq(math.sqrt(10)^2, 10)) assert(eq(math.log10(2), math.log(2)/math.log(10))) assert(eq(math.exp(0), 1)) diff --git a/test/PUC-Lua-5.1-tests/nextvar.lua b/test/PUC-Lua-5.1-tests/nextvar.lua index 7ceaa75..a63f97e 100644 --- a/test/PUC-Lua-5.1-tests/nextvar.lua +++ b/test/PUC-Lua-5.1-tests/nextvar.lua @@ -199,6 +199,12 @@ _G["xxx"] = 1 assert(xxx==find("xxx")) print('+') +-- In Lua 5.1 math.mod() is renamed to math.fmod() if build +-- Lua 5.1 without flag `-DLUA_COMPAT_MOD`. +-- LuaJIT also has math.fmod() instead math.mod() builtin. +-- See also https://github.com/tarantool/tarantool/issues/5711. +-- Test is disabled. +--[=[ a = {} for i=0,10000 do if math.mod(i,10) ~= 0 then @@ -213,6 +219,7 @@ for i,v in pairs(a) do end assert(n.n == 9000) a = nil +--]=] -- remove those 10000 new global variables for i=1,10000 do _G[i] = nil end diff --git a/test/PUC-Lua-5.1-tests/pm.lua b/test/PUC-Lua-5.1-tests/pm.lua index fa125dc..366a31c 100644 --- a/test/PUC-Lua-5.1-tests/pm.lua +++ b/test/PUC-Lua-5.1-tests/pm.lua @@ -223,7 +223,11 @@ assert(string.gsub("a alo b hi", "%w%w+", t) == "a ALO b HI") -- tests for gmatch -assert(string.gfind == string.gmatch) +-- In Lua 5.1 function string.gfind was renamed to string.gmatch. +-- You can use it if Lua 5.1 is built with compile-time option +-- `-DLUA_COMPAT_GFIND`. +-- This builtin is removed from LuaJIT. Test is disabled. +-- assert(string.gfind == string.gmatch) local a = 0 for i in string.gmatch('abcde', '()') do assert(i == a+1); a=i end assert(a==6) diff --git a/test/PUC-Lua-5.1-tests/strings.lua b/test/PUC-Lua-5.1-tests/strings.lua index 237dbad..a97c888 100644 --- a/test/PUC-Lua-5.1-tests/strings.lua +++ b/test/PUC-Lua-5.1-tests/strings.lua @@ -102,7 +102,18 @@ print('+') x = '"ílo"\n\\' assert(string.format('%q%s', x, x) == '"\\"ílo\\"\\\n\\\\""ílo"\n\\') -assert(string.format('%q', "\0") == [["\000"]]) +-- LuaJIT since v2.0.0-beta6 has extension from Lua 5.2: +-- string.format(): %q reversible. +-- In Lua 5.1 string.format() does not accept string values +-- containing embedded zeros, except as arguments to the q option. +-- In Lua 5.2 '\0' is not handled differently from other +-- control chars in string.format('%q', ...). +-- See commit 7cc981c14067d4b0e774a6bfb0acfc2f5c911f0d +-- (string.format("%q", str) is now fully reversible +-- (from Lua 5.2).). +-- See also https://github.com/tarantool/tarantool/issues/5710. +-- Test is disabled for LuaJIT for now. +-- assert(string.format('%q', "\0") == [["\000"]]) assert(string.format("\0%c\0%c%x\0", string.byte("á"), string.byte("b"), 140) == "\0á\0b8c\0") assert(string.format('') == "") @@ -152,6 +163,9 @@ local function trylocale (w) return false end +-- LuaJIT doesn't compare strings by `strcoll`, like Lua 5.1 does. +-- Tests are disabled for LuaJIT. +--[[ if not trylocale("collate") then print("locale not supported") else @@ -166,6 +180,7 @@ else assert(string.gsub("áÁéÉ", "%u", "x") == "áxéx") assert(string.upper"áÁé{xuxu}ção" == "ÁÁÉ{XUXU}ÇÃO") end +--]] os.setlocale("C") assert(os.setlocale() == 'C') diff --git a/test/PUC-Lua-5.1-tests/vararg.lua b/test/PUC-Lua-5.1-tests/vararg.lua index ae068fa..e2de1ad 100644 --- a/test/PUC-Lua-5.1-tests/vararg.lua +++ b/test/PUC-Lua-5.1-tests/vararg.lua @@ -21,9 +21,14 @@ function vararg (...) return arg end local call = function (f, args) return f(unpack(args, 1, args.n)) end -assert(f() == 0) -assert(f({1,2,3}, 1, 2, 3) == 3) -assert(f({"alo", nil, 45, f, nil}, "alo", nil, 45, f, nil) == 5) +-- Lua 5.1 interprets ... in the vararg functions like additional +-- first argument unlike LuaJIT does. All extra arguments is set +-- into `arg` variable. This extension is from Lua 5.2. +-- See also https://github.com/tarantool/tarantool/issues/5712. +-- Test is disabled for LuaJIT. +-- assert(f() == 0) +-- assert(f({1,2,3}, 1, 2, 3) == 3) +-- assert(f({"alo", nil, 45, f, nil}, "alo", nil, 45, f, nil) == 5) assert(c12(1,2)==55) a,b = assert(call(c12, {1,2})) @@ -35,15 +40,18 @@ assert(not a) assert(c12(1,2,3) == false) local a = vararg(call(next, {_G,nil;n=2})) local b,c = next(_G) -assert(a[1] == b and a[2] == c and a.n == 2) +-- Test is disabled for LuaJIT for now. See the comment above. +-- assert(a[1] == b and a[2] == c and a.n == 2) a = vararg(call(call, {c12, {1,2}})) -assert(a.n == 2 and a[1] == 55 and a[2] == 2) +-- Test is disabled for LuaJIT for now. See the comment above. +-- assert(a.n == 2 and a[1] == 55 and a[2] == 2) a = call(print, {'+'}) assert(a == nil) local t = {1, 10} function t:f (...) return self[arg[1]]+arg.n end -assert(t:f(1,4) == 3 and t:f(2) == 11) +-- Test is disabled for LuaJIT for now. See the comment above. +-- assert(t:f(1,4) == 3 and t:f(2) == 11) print('+') lim = 20 -- 2.28.0