[Tarantool-patches] [PATCH v2 luajit 20/30] test: adapt PUC Lua test for args in vararg func
Sergey Kaplun
skaplun at tarantool.org
Fri Mar 26 10:43:03 MSK 2021
Lua 5.1 interprets ... in the vararg functions like additional first
argument, unlike LuaJIT does. All extra arguments is set into `arg`
variable.
Implicit `arg` parameter for old-style vararg functions was finally
removed in Lua 5.2. This patch adjust tests in vararg.lua considering
Lua 5.2 test suite taken from
https://www.lua.org/tests/lua-5.2.0-tests.tar.gz.
Closes tarantool/tarantool#5712
Part of tarantool/tarantool#5845
Part of tarantool/tarantool#4473
---
test/PUC-Lua-5.1-tests/vararg.lua | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/test/PUC-Lua-5.1-tests/vararg.lua b/test/PUC-Lua-5.1-tests/vararg.lua
index ae068fa..efb76c5 100644
--- a/test/PUC-Lua-5.1-tests/vararg.lua
+++ b/test/PUC-Lua-5.1-tests/vararg.lua
@@ -2,9 +2,13 @@ print('testing vararg')
_G.arg = nil
+-- 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.
+-- LuaJIT: 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 +21,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 +48,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