mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
test: Remove run-functional-tests.py
Now that the lua client is available, python/lupa are no longer necessary to run the functional tests. The helper functions previously defined in run-functional-tests.py were adapted to test/functional/helpers.lua.
This commit is contained in:
parent
201e1512a1
commit
69561ea922
@ -228,17 +228,9 @@ if(BUSTED_PRG)
|
||||
-P ${CMAKE_MODULE_PATH}/RunTests.cmake
|
||||
DEPENDS nvim-test unittest-headers)
|
||||
|
||||
# For the functional tests we need the full path to the real busted script,
|
||||
# which will be included by run-functional-tests.py.
|
||||
get_filename_component(LUA_PRG_DIR ${LUA_PRG} PATH)
|
||||
get_filename_component(LUA_PREFIX_DIR ${LUA_PRG_DIR} PATH)
|
||||
file(GLOB_RECURSE BUSTED_REAL_PRG
|
||||
${LUA_PREFIX_DIR}/lib/luarocks/rocks/busted/*busted)
|
||||
|
||||
add_custom_target(test
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DBUSTED_PRG=${PROJECT_SOURCE_DIR}/scripts/run-functional-tests.py
|
||||
-DBUSTED_REAL_PRG=${BUSTED_REAL_PRG}
|
||||
-DBUSTED_PRG=${BUSTED_PRG}
|
||||
-DWORKING_DIR=${CMAKE_CURRENT_SOURCE_DIR}
|
||||
-DBUSTED_OUTPUT_TYPE=${BUSTED_OUTPUT_TYPE}
|
||||
-DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test
|
||||
|
@ -6,8 +6,8 @@ endif()
|
||||
|
||||
if(TEST_TYPE STREQUAL "functional")
|
||||
execute_process(
|
||||
COMMAND python ${BUSTED_PRG} ${BUSTED_REAL_PRG} -v -o
|
||||
${BUSTED_OUTPUT_TYPE} --lpath=${BUILD_DIR}/?.lua ${TEST_DIR}/functional
|
||||
COMMAND ${BUSTED_PRG} -v -o ${BUSTED_OUTPUT_TYPE}
|
||||
--lpath=${BUILD_DIR}/?.lua ${TEST_DIR}/functional
|
||||
WORKING_DIRECTORY ${WORKING_DIR}
|
||||
RESULT_VARIABLE res)
|
||||
else()
|
||||
|
@ -1,93 +0,0 @@
|
||||
# Run functional tests using lua, busted and the python client
|
||||
|
||||
import os
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
from lupa import LuaRuntime, as_attrgetter
|
||||
from neovim import Nvim, spawn_session
|
||||
|
||||
|
||||
# Extract arguments
|
||||
busted_script = sys.argv[1]
|
||||
busted_argv = sys.argv[2:]
|
||||
|
||||
# Setup a lua state for running busted
|
||||
lua = LuaRuntime(unpack_returned_tuples=True)
|
||||
lua_globals = lua.globals()
|
||||
|
||||
# helper to transform iterables into lua tables
|
||||
list_to_table = lua.eval('''
|
||||
function(l)
|
||||
local t = {}
|
||||
for i, item in python.enumerate(l) do t[i + 1] = item end
|
||||
return t
|
||||
end
|
||||
''')
|
||||
|
||||
dict_to_table = lua.eval('''
|
||||
function(d)
|
||||
local t = {}
|
||||
for k, v in python.iterex(d.items()) do t[k] = v end
|
||||
return t
|
||||
end
|
||||
''')
|
||||
|
||||
def to_table(obj):
|
||||
if type(obj) in [tuple, list]:
|
||||
return list_to_table(list(to_table(e) for e in obj))
|
||||
if type(obj) is dict:
|
||||
return dict_to_table(as_attrgetter(
|
||||
dict((k, to_table(v)) for k, v in obj.items())))
|
||||
return obj
|
||||
|
||||
nvim_prog = os.environ.get('NVIM_PROG', 'build/bin/nvim')
|
||||
nvim_argv = [nvim_prog, '-u', 'NONE', '--embed']
|
||||
|
||||
if 'VALGRIND' in os.environ:
|
||||
log_file = os.environ.get('VALGRIND_LOG', 'valgrind-%p.log')
|
||||
valgrind_argv = ['valgrind', '-q', '--tool=memcheck', '--leak-check=yes',
|
||||
'--track-origins=yes', '--suppressions=.valgrind.supp',
|
||||
'--log-file={0}'.format(log_file)]
|
||||
if 'VALGRIND_GDB' in os.environ:
|
||||
valgrind_argv += ['--vgdb=yes', '--vgdb-error=0']
|
||||
nvim_argv = valgrind_argv + nvim_argv
|
||||
|
||||
session = spawn_session(nvim_argv)
|
||||
nvim = Nvim.from_session(session)
|
||||
|
||||
def nvim_command(cmd):
|
||||
nvim.command(cmd)
|
||||
|
||||
def nvim_eval(expr):
|
||||
return to_table(nvim.eval(expr))
|
||||
|
||||
def nvim_feed(input, mode=''):
|
||||
nvim.feedkeys(input)
|
||||
|
||||
def buffer_slice(start=None, stop=None, buffer_idx=None):
|
||||
rv = '\n'.join(nvim.buffers[buffer_idx or 0][start:stop])
|
||||
return rv
|
||||
|
||||
def nvim_replace_termcodes(input, *opts):
|
||||
return nvim.replace_termcodes(input, *opts)
|
||||
|
||||
expose = [
|
||||
nvim_command,
|
||||
nvim_eval,
|
||||
nvim_feed,
|
||||
nvim_replace_termcodes,
|
||||
buffer_slice,
|
||||
textwrap.dedent,
|
||||
]
|
||||
|
||||
for fn in expose:
|
||||
lua_globals[fn.__name__] = fn
|
||||
|
||||
# Set 'arg' global to let busted parse arguments
|
||||
lua_globals['arg'] = list_to_table(busted_argv)
|
||||
|
||||
# Read the busted script and execute in the lua state
|
||||
with open(busted_script) as f:
|
||||
busted_setup = f.read()
|
||||
lua.execute(busted_setup)
|
@ -1,3 +1,96 @@
|
||||
local Loop = require('nvim.loop')
|
||||
local MsgpackStream = require('nvim.msgpack_stream')
|
||||
local AsyncSession = require('nvim.async_session')
|
||||
local Session = require('nvim.session')
|
||||
|
||||
local nvim_prog = os.getenv('NVIM_PROG') or 'build/bin/nvim'
|
||||
local nvim_argv = {nvim_prog, '-u', 'NONE', '-N', '--embed'}
|
||||
|
||||
if os.getenv('VALGRIND') then
|
||||
local log_file = os.getenv('VALGRIND_LOG') or 'valgrind-%p.log'
|
||||
local valgrind_argv = {'valgrind', '-q', '--tool=memcheck',
|
||||
'--leak-check=yes', '--track-origins=yes',
|
||||
'--suppressions=.valgrind.supp',
|
||||
'--log-file='..log_file}
|
||||
if os.getenv('VALGRIND_GDB') then
|
||||
table.insert(valgrind_argv, '--vgdb=yes')
|
||||
table.insert(valgrind_argv, '--vgdb-error=0')
|
||||
end
|
||||
local len = #valgrind_argv
|
||||
for i = 1, #nvim_argv do
|
||||
valgrind_argv[i + len] = nvim_argv[i]
|
||||
end
|
||||
nvim_argv = valgrind_argv
|
||||
end
|
||||
|
||||
local session
|
||||
do
|
||||
local loop = Loop.new()
|
||||
local msgpack_stream = MsgpackStream.new(loop)
|
||||
local async_session = AsyncSession.new(msgpack_stream)
|
||||
session = Session.new(async_session)
|
||||
loop:spawn(nvim_argv)
|
||||
end
|
||||
|
||||
local function request(method, ...)
|
||||
local status, rv = session:request(method, ...)
|
||||
if not status then
|
||||
error(rv[2])
|
||||
end
|
||||
return rv
|
||||
end
|
||||
|
||||
local function nvim_command(cmd)
|
||||
request('vim_command', cmd)
|
||||
end
|
||||
|
||||
local function nvim_eval(expr)
|
||||
return request('vim_eval', expr)
|
||||
end
|
||||
|
||||
local function nvim_feed(input, mode)
|
||||
mode = mode or ''
|
||||
request('vim_feedkeys', input, mode)
|
||||
end
|
||||
|
||||
local function buffer_slice(start, stop, buffer_idx)
|
||||
local include_end = false
|
||||
if not stop then
|
||||
stop = -1
|
||||
include_end = true
|
||||
end
|
||||
local buffer = request('vim_get_buffers')[buffer_idx or 1]
|
||||
local slice = request('buffer_get_line_slice', buffer, start or 0, stop,
|
||||
true, include_end)
|
||||
return table.concat(slice, '\n')
|
||||
end
|
||||
|
||||
local function nvim_replace_termcodes(input)
|
||||
return request('vim_replace_termcodes', input, false, true, true )
|
||||
end
|
||||
|
||||
local function dedent(str)
|
||||
-- find minimum common indent across lines
|
||||
local indent = nil
|
||||
for line in str:gmatch('[^\n]+') do
|
||||
local line_indent = line:match('^%s+') or ''
|
||||
if indent == nil or #line_indent < #indent then
|
||||
indent = line_indent
|
||||
end
|
||||
end
|
||||
if #indent == 0 then
|
||||
-- no minimum common indent
|
||||
return str
|
||||
end
|
||||
-- create a pattern for the indent
|
||||
indent = indent:gsub('%s', '%%s')
|
||||
-- strip it from the first line
|
||||
str = str:gsub('^'..indent, '')
|
||||
-- strip it from the remaining lines
|
||||
str = str:gsub('[\n]'..indent, '\n')
|
||||
return str
|
||||
end
|
||||
|
||||
local function clear()
|
||||
nvim_command('call BeforeEachTest()')
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user