[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 17:54:11 MSK 2021


I've changed s/first/local/ in the commit message and the comment,
considering comment by Sergos for the previous patch.

===================================================================
test: adapt PUC Lua test for args in vararg func

Lua 5.1 interprets ... in the vararg functions like additional local
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
===================================================================

===================================================================
diff --git a/test/PUC-Lua-5.1-tests/vararg.lua b/test/PUC-Lua-5.1-tests/vararg.lua
index efb76c5..4d6ec6d 100644
--- a/test/PUC-Lua-5.1-tests/vararg.lua
+++ b/test/PUC-Lua-5.1-tests/vararg.lua
@@ -3,7 +3,7 @@ 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
+-- local 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.
===================================================================


On 26.03.21, Sergey Kaplun wrote:
> 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
> 

-- 
Best regards,
Sergey Kaplun


More information about the Tarantool-patches mailing list