From e6d0dea42b28a4814546bcf699ce277c365ebfc1 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Tue, 27 Nov 2018 16:29:43 +0100 Subject: test: Lua 5.2/5.3 compat #9280 Make the code run both on Lua 5.1 (which is the default for Neovim, and is what LuaJIT provides) and Lua 5.2+. --- runtime/lua/man.lua | 1 + test/functional/api/server_requests_spec.lua | 1 + test/functional/api/tabpage_spec.lua | 1 + test/functional/api/window_spec.lua | 1 + test/functional/eval/function_spec.lua | 1 + test/functional/eval/server_spec.lua | 1 + test/functional/ex_cmds/dict_notifications_spec.lua | 1 + test/functional/helpers.lua | 1 + test/functional/legacy/autocmd_option_spec.lua | 1 + test/functional/ui/screen.lua | 1 + test/functional/ui/tabline_spec.lua | 1 + test/helpers.lua | 1 + test/unit/eval/typval_spec.lua | 1 + test/unit/garray_spec.lua | 1 + test/unit/helpers.lua | 1 + 15 files changed, 15 insertions(+) diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua index b0fbe9cc35..0c67e45dc4 100644 --- a/runtime/lua/man.lua +++ b/runtime/lua/man.lua @@ -1,4 +1,5 @@ local buf_hls = {} +local unpack = table.unpack or unpack -- luacheck: ignore local function highlight_line(line, linenr) local chars = {} diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 4d25ba0819..8de71a56e9 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -2,6 +2,7 @@ -- `rpcrequest` calls we need the client event loop to be running. local helpers = require('test.functional.helpers')(after_each) local Paths = require('test.config.paths') +local unpack = table.unpack or unpack -- luacheck: ignore local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop diff --git a/test/functional/api/tabpage_spec.lua b/test/functional/api/tabpage_spec.lua index c49091db02..584bca7111 100644 --- a/test/functional/api/tabpage_spec.lua +++ b/test/functional/api/tabpage_spec.lua @@ -8,6 +8,7 @@ local request = helpers.request local NIL = helpers.NIL local meth_pcall = helpers.meth_pcall local command = helpers.command +local unpack = table.unpack or unpack -- luacheck: ignore describe('api/tabpage', function() before_each(clear) diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 4496e1f644..273991951c 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -12,6 +12,7 @@ local meth_pcall = helpers.meth_pcall local meths = helpers.meths local command = helpers.command local expect_err = helpers.expect_err +local unpack = table.unpack or unpack -- luacheck: ignore -- check if str is visible at the beginning of some line local function is_visible(str) diff --git a/test/functional/eval/function_spec.lua b/test/functional/eval/function_spec.lua index 776e760aaf..1a86576fde 100644 --- a/test/functional/eval/function_spec.lua +++ b/test/functional/eval/function_spec.lua @@ -1,4 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) +local unpack = table.unpack or unpack -- luacheck: ignore local clear = helpers.clear local eq = helpers.eq diff --git a/test/functional/eval/server_spec.lua b/test/functional/eval/server_spec.lua index 563e619b39..8a0831bba1 100644 --- a/test/functional/eval/server_spec.lua +++ b/test/functional/eval/server_spec.lua @@ -6,6 +6,7 @@ local iswin = helpers.iswin local ok = helpers.ok local matches = helpers.matches local expect_err = helpers.expect_err +local unpack = table.unpack or unpack -- luacheck: ignore local function clear_serverlist() for _, server in pairs(funcs.serverlist()) do diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua index 3d550588e7..f5920c3d11 100644 --- a/test/functional/ex_cmds/dict_notifications_spec.lua +++ b/test/functional/ex_cmds/dict_notifications_spec.lua @@ -4,6 +4,7 @@ local eq, next_msg = helpers.eq, helpers.next_msg local exc_exec = helpers.exc_exec local command = helpers.command local eval = helpers.eval +local unpack = table.unpack or unpack -- luacheck: ignore describe('dictionary change notifications', function() diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index a94e977cd0..7921cc05bf 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -2,6 +2,7 @@ require('coxpcall') local luv = require('luv') local lfs = require('lfs') local global_helpers = require('test.helpers') +local unpack = table.unpack or unpack -- luacheck: ignore -- nvim client: Found in .deps/usr/share/lua//nvim/ if "bundled". local Session = require('nvim.session') diff --git a/test/functional/legacy/autocmd_option_spec.lua b/test/functional/legacy/autocmd_option_spec.lua index 0c7e43bf31..de0e32c813 100644 --- a/test/functional/legacy/autocmd_option_spec.lua +++ b/test/functional/legacy/autocmd_option_spec.lua @@ -5,6 +5,7 @@ local curbuf, buf = helpers.curbuf, helpers.bufmeths local curwin = helpers.curwin local redir_exec = helpers.redir_exec local source, command = helpers.source, helpers.command +local unpack = table.unpack or unpack -- luacheck: ignore local function declare_hook_function() source([[ diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 75eb5bb4e3..32a8e69511 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -78,6 +78,7 @@ local helpers = require('test.functional.helpers')(nil) local request, run, uimeths = helpers.request, helpers.run, helpers.uimeths local eq = helpers.eq local dedent = helpers.dedent +local unpack = table.unpack or unpack -- luacheck: ignore local inspect = require('inspect') diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua index dcab9f7ef4..ac56a7c03f 100644 --- a/test/functional/ui/tabline_spec.lua +++ b/test/functional/ui/tabline_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear, command, eq = helpers.clear, helpers.command, helpers.eq +local unpack = table.unpack or unpack -- luacheck: ignore describe('ui/ext_tabline', function() local screen diff --git a/test/helpers.lua b/test/helpers.lua index 6ef7a456f4..30bae01216 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -2,6 +2,7 @@ local assert = require('luassert') local luv = require('luv') local lfs = require('lfs') local relpath = require('pl.path').relpath +local unpack = table.unpack or unpack -- luacheck: ignore local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote) local function shell_quote(str) diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 919a42fbb9..8c85ff3f34 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -2,6 +2,7 @@ local bit = require('bit') local helpers = require('test.unit.helpers')(after_each) local eval_helpers = require('test.unit.eval.helpers') local global_helpers = require('test.helpers') +local unpack = table.unpack or unpack -- luacheck: ignore local itp = helpers.gen_itp(it) diff --git a/test/unit/garray_spec.lua b/test/unit/garray_spec.lua index 28df8a6e3f..e1839d1811 100644 --- a/test/unit/garray_spec.lua +++ b/test/unit/garray_spec.lua @@ -13,6 +13,7 @@ local garray = cimport('./src/nvim/garray.h') local itemsize = 14 local growsize = 95 +local unpack = table.unpack or unpack -- luacheck: ignore -- define a basic interface to garray. We could make it a lot nicer by -- constructing a class wrapper around garray. It could for example associate diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index f8143a0125..81847abc36 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -9,6 +9,7 @@ local say = require('say') local posix = nil local syscall = nil +local unpack = table.unpack or unpack -- luacheck: ignore local check_cores = global_helpers.check_cores local dedent = global_helpers.dedent -- cgit From 221f6fffad12beaa928ccedae336d64b7b1c1208 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 29 Nov 2018 22:51:20 +0100 Subject: runtime/lua/vim/compat.lua ref #9280 Introduce the `vim.compat` module, to help environments with system Lua 5.2+ run the build/tests. Include the module implicitly in all tests. ref #8677 legacy `vim` module: beep buffer command dict eval firstline lastline line list open type window --- CMakeLists.txt | 15 +++++++++++++-- cmake/RunTests.cmake | 5 ++++- runtime/lua/man.lua | 3 ++- runtime/lua/vim/compat.lua | 12 ++++++++++++ test/functional/api/server_requests_spec.lua | 1 - test/functional/api/tabpage_spec.lua | 1 - test/functional/api/window_spec.lua | 1 - test/functional/eval/function_spec.lua | 1 - test/functional/eval/server_spec.lua | 1 - test/functional/ex_cmds/dict_notifications_spec.lua | 1 - test/functional/helpers.lua | 2 +- test/functional/legacy/autocmd_option_spec.lua | 1 - test/functional/ui/screen.lua | 1 - test/functional/ui/tabline_spec.lua | 1 - test/helpers.lua | 1 - test/unit/eval/typval_spec.lua | 1 - test/unit/garray_spec.lua | 1 - test/unit/helpers.lua | 1 - 18 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 runtime/lua/vim/compat.lua diff --git a/CMakeLists.txt b/CMakeLists.txt index 15718c94cf..5a8aef2be2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -688,7 +688,7 @@ if(LUACHECK_PRG) -P ${PROJECT_SOURCE_DIR}/cmake/RunLuacheck.cmake) add_custom_target( - blobcodelint + lintbuiltinlua COMMAND ${CMAKE_COMMAND} -DLUACHECK_PRG=${LUACHECK_PRG} @@ -697,10 +697,21 @@ if(LUACHECK_PRG) -DREAD_GLOBALS=vim -P ${PROJECT_SOURCE_DIR}/cmake/RunLuacheck.cmake ) + add_custom_target( + lintruntimelua + COMMAND + ${CMAKE_COMMAND} + -DLUACHECK_PRG=${LUACHECK_PRG} + -DLUAFILES_DIR=${CMAKE_CURRENT_SOURCE_DIR}/runtime/lua + -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} + -DREAD_GLOBALS=vim + -P ${PROJECT_SOURCE_DIR}/cmake/RunLuacheck.cmake + ) # TODO(ZyX-I): Run linter for all lua code in src add_custom_target( lualint - DEPENDS blobcodelint + DEPENDS lintruntimelua + DEPENDS lintbuiltinlua ) endif() diff --git a/cmake/RunTests.cmake b/cmake/RunTests.cmake index a764b19850..05c429c1f5 100644 --- a/cmake/RunTests.cmake +++ b/cmake/RunTests.cmake @@ -38,7 +38,10 @@ set(ENV{SYSTEM_NAME} ${SYSTEM_NAME}) execute_process( COMMAND ${BUSTED_PRG} ${TEST_TAG} ${TEST_FILTER} -v -o ${BUSTED_OUTPUT_TYPE} --lua=${LUA_PRG} --lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua - --lpath=${BUILD_DIR}/?.lua --lpath=?.lua ${TEST_PATH} + --lpath=${BUILD_DIR}/?.lua + --lpath=${WORKING_DIR}/runtime/lua/?.lua + --lpath=?.lua + ${TEST_PATH} WORKING_DIRECTORY ${WORKING_DIR} ERROR_VARIABLE err RESULT_VARIABLE res diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua index 0c67e45dc4..e9f60138f4 100644 --- a/runtime/lua/man.lua +++ b/runtime/lua/man.lua @@ -1,5 +1,6 @@ +require('vim.compat') + local buf_hls = {} -local unpack = table.unpack or unpack -- luacheck: ignore local function highlight_line(line, linenr) local chars = {} diff --git a/runtime/lua/vim/compat.lua b/runtime/lua/vim/compat.lua new file mode 100644 index 0000000000..168979bb95 --- /dev/null +++ b/runtime/lua/vim/compat.lua @@ -0,0 +1,12 @@ +-- Lua 5.1 forward-compatibility layer. +-- For background see https://github.com/neovim/neovim/pull/9280 +-- +-- Reference the lua-compat-5.2 project for hints: +-- https://github.com/keplerproject/lua-compat-5.2/blob/c164c8f339b95451b572d6b4b4d11e944dc7169d/compat52/mstrict.lua +-- https://github.com/keplerproject/lua-compat-5.2/blob/c164c8f339b95451b572d6b4b4d11e944dc7169d/tests/test.lua + +local lua_version = _VERSION:sub(-3) + +if lua_version >= "5.2" then + unpack = table.unpack -- luacheck: ignore 121 143 +end diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 8de71a56e9..4d25ba0819 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -2,7 +2,6 @@ -- `rpcrequest` calls we need the client event loop to be running. local helpers = require('test.functional.helpers')(after_each) local Paths = require('test.config.paths') -local unpack = table.unpack or unpack -- luacheck: ignore local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop diff --git a/test/functional/api/tabpage_spec.lua b/test/functional/api/tabpage_spec.lua index 584bca7111..c49091db02 100644 --- a/test/functional/api/tabpage_spec.lua +++ b/test/functional/api/tabpage_spec.lua @@ -8,7 +8,6 @@ local request = helpers.request local NIL = helpers.NIL local meth_pcall = helpers.meth_pcall local command = helpers.command -local unpack = table.unpack or unpack -- luacheck: ignore describe('api/tabpage', function() before_each(clear) diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 273991951c..4496e1f644 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -12,7 +12,6 @@ local meth_pcall = helpers.meth_pcall local meths = helpers.meths local command = helpers.command local expect_err = helpers.expect_err -local unpack = table.unpack or unpack -- luacheck: ignore -- check if str is visible at the beginning of some line local function is_visible(str) diff --git a/test/functional/eval/function_spec.lua b/test/functional/eval/function_spec.lua index 1a86576fde..776e760aaf 100644 --- a/test/functional/eval/function_spec.lua +++ b/test/functional/eval/function_spec.lua @@ -1,5 +1,4 @@ local helpers = require('test.functional.helpers')(after_each) -local unpack = table.unpack or unpack -- luacheck: ignore local clear = helpers.clear local eq = helpers.eq diff --git a/test/functional/eval/server_spec.lua b/test/functional/eval/server_spec.lua index 8a0831bba1..563e619b39 100644 --- a/test/functional/eval/server_spec.lua +++ b/test/functional/eval/server_spec.lua @@ -6,7 +6,6 @@ local iswin = helpers.iswin local ok = helpers.ok local matches = helpers.matches local expect_err = helpers.expect_err -local unpack = table.unpack or unpack -- luacheck: ignore local function clear_serverlist() for _, server in pairs(funcs.serverlist()) do diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua index f5920c3d11..3d550588e7 100644 --- a/test/functional/ex_cmds/dict_notifications_spec.lua +++ b/test/functional/ex_cmds/dict_notifications_spec.lua @@ -4,7 +4,6 @@ local eq, next_msg = helpers.eq, helpers.next_msg local exc_exec = helpers.exc_exec local command = helpers.command local eval = helpers.eval -local unpack = table.unpack or unpack -- luacheck: ignore describe('dictionary change notifications', function() diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 7921cc05bf..272b80466c 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -1,8 +1,8 @@ +require('vim.compat') require('coxpcall') local luv = require('luv') local lfs = require('lfs') local global_helpers = require('test.helpers') -local unpack = table.unpack or unpack -- luacheck: ignore -- nvim client: Found in .deps/usr/share/lua//nvim/ if "bundled". local Session = require('nvim.session') diff --git a/test/functional/legacy/autocmd_option_spec.lua b/test/functional/legacy/autocmd_option_spec.lua index de0e32c813..0c7e43bf31 100644 --- a/test/functional/legacy/autocmd_option_spec.lua +++ b/test/functional/legacy/autocmd_option_spec.lua @@ -5,7 +5,6 @@ local curbuf, buf = helpers.curbuf, helpers.bufmeths local curwin = helpers.curwin local redir_exec = helpers.redir_exec local source, command = helpers.source, helpers.command -local unpack = table.unpack or unpack -- luacheck: ignore local function declare_hook_function() source([[ diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 32a8e69511..75eb5bb4e3 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -78,7 +78,6 @@ local helpers = require('test.functional.helpers')(nil) local request, run, uimeths = helpers.request, helpers.run, helpers.uimeths local eq = helpers.eq local dedent = helpers.dedent -local unpack = table.unpack or unpack -- luacheck: ignore local inspect = require('inspect') diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua index ac56a7c03f..dcab9f7ef4 100644 --- a/test/functional/ui/tabline_spec.lua +++ b/test/functional/ui/tabline_spec.lua @@ -1,7 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear, command, eq = helpers.clear, helpers.command, helpers.eq -local unpack = table.unpack or unpack -- luacheck: ignore describe('ui/ext_tabline', function() local screen diff --git a/test/helpers.lua b/test/helpers.lua index 30bae01216..6ef7a456f4 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -2,7 +2,6 @@ local assert = require('luassert') local luv = require('luv') local lfs = require('lfs') local relpath = require('pl.path').relpath -local unpack = table.unpack or unpack -- luacheck: ignore local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote) local function shell_quote(str) diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 8c85ff3f34..919a42fbb9 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -2,7 +2,6 @@ local bit = require('bit') local helpers = require('test.unit.helpers')(after_each) local eval_helpers = require('test.unit.eval.helpers') local global_helpers = require('test.helpers') -local unpack = table.unpack or unpack -- luacheck: ignore local itp = helpers.gen_itp(it) diff --git a/test/unit/garray_spec.lua b/test/unit/garray_spec.lua index e1839d1811..28df8a6e3f 100644 --- a/test/unit/garray_spec.lua +++ b/test/unit/garray_spec.lua @@ -13,7 +13,6 @@ local garray = cimport('./src/nvim/garray.h') local itemsize = 14 local growsize = 95 -local unpack = table.unpack or unpack -- luacheck: ignore -- define a basic interface to garray. We could make it a lot nicer by -- constructing a class wrapper around garray. It could for example associate diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 81847abc36..f8143a0125 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -9,7 +9,6 @@ local say = require('say') local posix = nil local syscall = nil -local unpack = table.unpack or unpack -- luacheck: ignore local check_cores = global_helpers.check_cores local dedent = global_helpers.dedent -- cgit From 127b8569e63d57321fc4cd77b7e55781f1447365 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 30 Nov 2018 21:30:05 +0100 Subject: lint --- runtime/lua/man.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua index e9f60138f4..1da8ed85fc 100644 --- a/runtime/lua/man.lua +++ b/runtime/lua/man.lua @@ -12,9 +12,9 @@ local function highlight_line(line, linenr) local attr = NONE local byte = 0 -- byte offset - local function end_attr_hl(attr) + local function end_attr_hl(attr_) for i, hl in ipairs(hls) do - if hl.attr == attr and hl.final == -1 then + if hl.attr == attr_ and hl.final == -1 then hl.final = byte hls[i] = hl end @@ -108,7 +108,7 @@ local function highlight_line(line, linenr) -- the range 0x20 - 0x3f, then 'm'. (See ECMA-48, sections 5.4 & 8.3.117) local sgr = prev_char:match("^%[([\032-\063]*)m$") if sgr then - local match = '' + local match while sgr and #sgr > 0 do -- Match against SGR parameters, which may be separated by ';' match, sgr = sgr:match("^(%d*);?(.*)") -- cgit