diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-09-29 09:43:52 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-09-30 17:37:16 -0300 |
commit | 42d5b526b9cbd067509e68ce6514a37e04df928a (patch) | |
tree | 0f5883a0dd231ed42222bf79ccb4cac7392de318 /scripts/run-functional-tests.py | |
parent | 4b0f524915ee0e94bf9ca24fb1c1014921e610d5 (diff) | |
download | rneovim-42d5b526b9cbd067509e68ce6514a37e04df928a.tar.gz rneovim-42d5b526b9cbd067509e68ce6514a37e04df928a.tar.bz2 rneovim-42d5b526b9cbd067509e68ce6514a37e04df928a.zip |
test: Replace vroom by lua/busted for functional tests
The 'lupa' python package provides a simple way to seamless integrate lua and
python code.
This commit replaces vroom by a python script that exposes the 'neovim' package
to a lua state, and invokes busted to run functional tests. This is a temporary
solution that will enable writing functional tests using lua/bused while a lua
client library is not available.
The reason for dropping vroom is flexibility: Lua/busted has a nice DSL-style
syntax while also providing the customization power of a full programming
language. Another reason is to use a single framework for unit/functional tests.
Two other changes were performed in this commit:
- Instead of "gcc-unittest/gcc-ia32", the travis builds for gcc are now
identified by "gcc/gcc-32". They will run unit/functional tests for both 64
and 32 bits.
- Old integration tests(in src/nvim/testdir) are now ran by the 'oldtest' target
Diffstat (limited to 'scripts/run-functional-tests.py')
-rw-r--r-- | scripts/run-functional-tests.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/scripts/run-functional-tests.py b/scripts/run-functional-tests.py new file mode 100644 index 0000000000..1b8fb2ddef --- /dev/null +++ b/scripts/run-functional-tests.py @@ -0,0 +1,81 @@ +# Run functional tests using lua, busted and the python client + +import os +import sys +import textwrap + +from lupa import LuaRuntime +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 +''') + +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_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_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) |