diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-23 15:49:51 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-23 16:06:59 -0300 |
commit | 6c96e42e2c18bd6ae685b5a41c69b03954aa0375 (patch) | |
tree | d25a81cd37939466e5b9c8b33b3566f9aefbdf49 /scripts/run-api-tests.exp | |
parent | f03a7672e18fe57b1e4de17abf2a193f8b343562 (diff) | |
download | rneovim-6c96e42e2c18bd6ae685b5a41c69b03954aa0375.tar.gz rneovim-6c96e42e2c18bd6ae685b5a41c69b03954aa0375.tar.bz2 rneovim-6c96e42e2c18bd6ae685b5a41c69b03954aa0375.zip |
API: Test: Setup basic test infrastructure
- Add a 'expect' utility script that can run simple API tests using clients
developed for any platform.
- Extend travis build matrix to run API tests using the python client and
valgrind.
This script can be used to write API tests without having to manage nvim's
lifetime:
- It starts a single nvim instance listening on a known socket
- Invokes the test runner, which should connect to NEOVIM_LISTEN_ADDRESS
- The nvim instance started by the script provides a `BeforeEachTest` function,
which should be called before each test to reset nvim to a clean state.
- It takes care of shutting down nvim once the tests are finished.
As explained
[here](https://github.com/neovim/neovim/pull/737#issuecomment-43941520), it's
not possible to fully reset nvim to it's initial state, but the `BeforeEachTest`
function should be enough for most test cases. Tests requiring a fully clean
nvim instance should take care of starting/stopping nvim.
Diffstat (limited to 'scripts/run-api-tests.exp')
-rwxr-xr-x | scripts/run-api-tests.exp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/scripts/run-api-tests.exp b/scripts/run-api-tests.exp new file mode 100755 index 0000000000..6a568e17cb --- /dev/null +++ b/scripts/run-api-tests.exp @@ -0,0 +1,86 @@ +#!/usr/bin/env expect + +if {$argc < 2} { + puts "Need commands for running the tests and for starting nvim" + exit 1 +} + +set timeout 10 +set run_tests [split [lindex $argv 0] " "] +set run_nvim [split [lindex $argv 1] " "] + +# don't echo to stdout +log_user 0 +# set NEOVIM_LISTEN_ADDRESS, so nvim will listen on a known socket +set env(NEOVIM_LISTEN_ADDRESS) "/tmp/nvim-[exec date +%s%N].sock" +# start nvim +spawn {*}$run_nvim +# save the job descriptor +set nvim_id $spawn_id +# Reset function that can be invoked by test runners to put nvim in a cleaner +# state +send { +:function BeforeEachTest() + set all& + redir => groups + silent augroup + redir END + for group in split(groups) + exe 'augroup '.group + autocmd! + augroup NONE + exe 'augroup! '.group + endfor + tabnew + let curbufnum = eval(bufnr('%')) + redir => buflist + silent ls! + redir END + let bufnums = [] + for buf in split(buflist, '\n') + let bufnum = eval(split(buf, '[ u]')[0]) + if bufnum != curbufnum + call add(bufnums, bufnum) + endif + endfor + if len(bufnums) > 0 + exe 'silent bwipeout! '.join(bufnums, ' ') + endif + silent tabonly + for k in keys(g:) + exe 'unlet g:'.k + endfor + filetype plugin indent off + mapclear + mapclear! + abclear + comclear +endfunction +:echo "read"."y" +} +# wait until nvim is ready +expect "ready" +# run tests +spawn {*}$run_tests +set tests_id $spawn_id +set status 1 +# listen for test output in the background +expect_background { + * { + # show test output to the user + send_user -- $expect_out(buffer) + } + eof { + # collect the exit status code + set spawn_id $tests_id + catch wait result + set status [lindex $result 3] + set spawn_id $nvim_id + # quit nvim + send ":qa!\r" + } +} +# switch back nvim and wait until it exits +set spawn_id $nvim_id +expect eof +exit $status |