[Tarantool-patches] [PATCH luajit v3 10/29] test: adapt PUC-Rio tests with vararg functions

Sergey Kaplun skaplun at tarantool.org
Tue Apr 13 16:27:10 MSK 2021


Lua 5.1 interprets `...` in the vararg functions as an additional
local argument unlike LuaJIT does. This behaviour is extension from
Lua 5.2.

This patch adapted tests considering behaviour of LuaJIT and Lua 5.2.
The tests are adapted like it done in Lua 5.2 test suite taken from
https://www.lua.org/tests/lua-5.2.0-tests.tar.gz.

Tests in the following files are adapted:
* db.lua
* vararg.lua

Resolves tarantool/tarantool#5712
Part of tarantool/tarantool#5694
Part of tarantool/tarantool#5845
Part of tarantool/tarantool#4473
---
 test/PUC-Rio-Lua-5.1-tests/db.lua     |  7 +++++++
 test/PUC-Rio-Lua-5.1-tests/vararg.lua | 17 +++++++++++++----
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/test/PUC-Rio-Lua-5.1-tests/db.lua b/test/PUC-Rio-Lua-5.1-tests/db.lua
index c9741981..82d1cfa6 100644
--- a/test/PUC-Rio-Lua-5.1-tests/db.lua
+++ b/test/PUC-Rio-Lua-5.1-tests/db.lua
@@ -224,6 +224,13 @@ assert(debug.getinfo(1, "l").currentline == L+11)  -- check count of lines
 
 
 function g(...)
+  -- LuaJIT: Lua 5.1 interprets `...` in the vararg functions like
+  -- an additional local argument unlike LuaJIT does.
+  -- This extension is from Lua 5.2.
+  -- See also https://github.com/tarantool/tarantool/issues/5694.
+  -- Test is adapted from PUC-Rio Lua 5.2 test suite by adding
+  -- additional variable `arg`.
+  local arg = {...}
   do local a,b,c; a=math.sin(40); end
   local feijao
   local AAAA,B = "xuxu", "mamão"
diff --git a/test/PUC-Rio-Lua-5.1-tests/vararg.lua b/test/PUC-Rio-Lua-5.1-tests/vararg.lua
index ae068fac..a9c3a6a2 100644
--- a/test/PUC-Rio-Lua-5.1-tests/vararg.lua
+++ b/test/PUC-Rio-Lua-5.1-tests/vararg.lua
@@ -2,9 +2,14 @@ print('testing vararg')
 
 _G.arg = nil
 
+-- LuaJIT: Lua 5.1 interprets ... in the vararg functions as an
+-- additional local argument, unlike LuaJIT does. All extra
+-- arguments are set into `arg` variable. This extension
+-- is from Lua 5.2.
+-- See also https://github.com/tarantool/tarantool/issues/5712.
+-- Test is adapted from PUC-Rio Lua 5.2 test suite.
 function f(a, ...)
-  assert(type(arg) == 'table')
-  assert(type(arg.n) == 'number')
+  local arg = {n = select('#', ...), ...}
   for i=1,arg.n do assert(a[i]==arg[i]) end
   return arg.n
 end
@@ -17,7 +22,9 @@ function c12 (...)
   return res, 2
 end
 
-function vararg (...) return arg end
+-- LuaJIT: Test chunk is adapted from PUC-Rio Lua 5.2 test suite.
+-- See the comment above.
+function vararg (...) return {n = select('#', ...), ...} end
 
 local call = function (f, args) return f(unpack(args, 1, args.n)) end
 
@@ -42,7 +49,9 @@ a = call(print, {'+'})
 assert(a == nil)
 
 local t = {1, 10}
-function t:f (...) return self[arg[1]]+arg.n end
+-- LuaJIT: Test chunk is adapted from PUC-Rio Lua 5.2 test suite.
+-- See the comment above.
+function t:f (...) local arg = {...}; return self[...]+#arg end
 assert(t:f(1,4) == 3 and t:f(2) == 11)
 print('+')
 
-- 
2.31.0



More information about the Tarantool-patches mailing list