From 2bafdb7e5a5cb96cb8263ed1b7bb79be021e4350 Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 12 May 2017 20:38:52 +0100 Subject: [PATCH] Run all tests in NeoVim, improve the test script, and make all tests pass for NeoVim --- .travis.yml | 2 +- Makefile | 53 ------ autoload/ale/engine.vim | 15 ++ run-tests | 171 ++++++++++++++++++++ test/.config/nvim/init.vim | 1 + test/lsp/test_lsp_connections.vader | 119 +++++++++----- test/sign/test_linting_sets_signs.vader | 1 + test/test_conflicting_plugin_warnings.vader | 6 +- test/test_cursor_warnings.vader | 5 +- test/test_history_saving.vader | 8 +- 10 files changed, 287 insertions(+), 94 deletions(-) delete mode 100644 Makefile create mode 100755 run-tests create mode 120000 test/.config/nvim/init.vim diff --git a/.travis.yml b/.travis.yml index d4e6cf3f..9374b0cc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,4 @@ branches: - master language: python script: | - make test + ./run-tests diff --git a/Makefile b/Makefile deleted file mode 100644 index 86ac17d9..00000000 --- a/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -SHELL := /usr/bin/env bash -IMAGE ?= w0rp/ale -CURRENT_IMAGE_ID = 30a9967dbdb1 -DOCKER_FLAGS = --rm -v $(PWD):/testplugin -v $(PWD)/test:/home "$(IMAGE)" -tests = test/*.vader test/*/*.vader test/*/*/*.vader test/*/*/*/*.vader - -test-setup: - docker images -q w0rp/ale | grep ^$(CURRENT_IMAGE_ID) > /dev/null || \ - docker pull $(IMAGE) - -vader: test-setup - @:; \ - vims=$$(docker run --rm $(IMAGE) ls /vim-build/bin | grep -E '^n?vim'); \ - if [ -z "$$vims" ]; then echo "No Vims found!"; exit 1; fi; \ - for vim in $$vims; do \ - docker run -a stderr $(DOCKER_FLAGS) $$vim '+Vader! $(tests)'; \ - done - -test: test-setup - @:; \ - vims=$$(docker run --rm $(IMAGE) ls /vim-build/bin | grep -E '^n?vim'); \ - if [ -z "$$vims" ]; then echo "No Vims found!"; exit 1; fi; \ - EXIT=0; \ - for vim in $$vims; do \ - echo; \ - echo '========================================'; \ - echo "Running tests for $$vim"; \ - echo '========================================'; \ - echo; \ - docker run -a stderr $(DOCKER_FLAGS) $$vim '+Vader! $(tests)' || EXIT=$$?; \ - done; \ - echo; \ - echo '========================================'; \ - echo 'Running Vint to lint our code'; \ - echo '========================================'; \ - echo 'Vint warnings/errors follow:'; \ - echo; \ - set -o pipefail; \ - docker run -a stdout $(DOCKER_FLAGS) vint -s /testplugin | sed s:^/testplugin/:: || EXIT=$$?; \ - set +o pipefail; \ - echo; \ - echo '========================================'; \ - echo 'Running custom checks'; \ - echo '========================================'; \ - echo 'Custom warnings/errors follow:'; \ - echo; \ - set -o pipefail; \ - docker run -v $(PWD):/testplugin "$(IMAGE)" /testplugin/custom-checks /testplugin | sed s:^/testplugin/:: || EXIT=$$?; \ - set +o pipefail; \ - echo; \ - exit $$EXIT; - -.DEFAULT_GOAL := test diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 486bdd4f..d431088a 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -283,6 +283,10 @@ function! s:HandleExit(job) abort return endif + if has('nvim') && !empty(l:output) && empty(l:output[-1]) + call remove(l:output, -1) + endif + if l:next_chain_index < len(get(l:linter, 'command_chain', [])) call s:InvokeChain(l:buffer, l:linter, l:next_chain_index, l:output) return @@ -773,6 +777,17 @@ function! ale#engine#WaitForJobs(deadline) abort call extend(l:job_list, l:info.job_list) endfor + " NeoVim has a built-in API for this, so use that. + if has('nvim') + let l:nvim_code_list = jobwait(l:job_list, a:deadline) + + if index(l:nvim_code_list, -1) >= 0 + throw 'Jobs did not complete on time!' + endif + + return + endif + let l:should_wait_more = 1 while l:should_wait_more diff --git a/run-tests b/run-tests new file mode 100755 index 00000000..dd017474 --- /dev/null +++ b/run-tests @@ -0,0 +1,171 @@ +#!/bin/bash -eu + +# Author: w0rp +# +# This script runs tests for the ALE project. The following options are +# accepted: +# +# -v Enable verbose output +# --neovim-only Run tests only for NeoVim +# --vim-only Run tests only for Vim + +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' +CURRENT_IMAGE_ID=d5a1b5915b09 +IMAGE=w0rp/ale +DOCKER_FLAGS=(--rm -v "$PWD:/testplugin" -v "$PWD/test:/home" -w /testplugin "$IMAGE") +EXIT=0 + +tests='test/*.vader test/*/*.vader test/*/*/*.vader test/*/*/*.vader' +verbose=0 +run_neovim_tests=1 +run_vim_tests=1 +run_vint=1 +run_custom_checks=1 + +while [ $# -ne 0 ]; do + case $1 in + -v) + verbose=1 + shift + ;; + --neovim-only) + run_vim_tests=0 + run_vint=0 + run_custom_checks=0 + shift + ;; + --vim-only) + run_neovim_tests=0 + run_vint=0 + run_custom_checks=0 + ;; + --) + shift + break + ;; + -?*) + echo "Invalid argument: $1" 1>&2 + exit 1 + ;; + *) + break + ;; + esac +done + +# Allow tests to be passed as arguments. +if [ $# -ne 0 ]; then + # This doesn't perfectly handle work splitting, but none of our files + # have spaces in the names. + tests="$*" +fi + +docker images -q w0rp/ale | grep "^$CURRENT_IMAGE_ID" > /dev/null \ + || docker pull "$IMAGE" + +function color-vader-output() { + local vader_started=0 + + while read -r; do + if ((!verbose)); then + # When verbose mode is off, suppress output until Vader starts. + if ((!vader_started)); then + if [[ "$REPLY" = *'Starting Vader:'* ]]; then + vader_started=1 + else + continue + fi + fi + fi + + if [[ "$REPLY" = *'[EXECUTE] (X)'* ]]; then + echo -en "$RED" + elif [[ "$REPLY" = *'[EXECUTE]'* ]] || [[ "$REPLY" = *'[ GIVEN]'* ]]; then + echo -en "$NC" + fi + + if [[ "$REPLY" = *'Success/Total'* ]]; then + success="$(echo -n "$REPLY" | grep -o '[0-9]\+/' | head -n1 | cut -d/ -f1)" + total="$(echo -n "$REPLY" | grep -o '/[0-9]\+' | head -n1 | cut -d/ -f2)" + + if [ "$success" -lt "$total" ]; then + echo -en "$RED" + else + echo -en "$GREEN" + fi + + echo "$REPLY" + echo -en "$NC" + else + echo "$REPLY" + fi + done + + echo -en "$NC" +} + +if ((run_neovim_tests)); then + for vim in $(docker run --rm "$IMAGE" ls /vim-build/bin | grep '^neovim' ); do + echo + echo '========================================' + echo "Running tests for $vim" + echo '========================================' + echo + + set -o pipefail + docker run -it -e VADER_OUTPUT_FILE=/dev/stderr "${DOCKER_FLAGS[@]}" \ + "/vim-build/bin/$vim" -u test/vimrc \ + --headless "+Vader! $tests" | color-vader-output || EXIT=$? + set +o pipefail + done + + echo +fi + +if ((run_vim_tests)); then + for vim in $(docker run --rm "$IMAGE" ls /vim-build/bin | grep '^vim' ); do + echo + echo '========================================' + echo "Running tests for $vim" + echo '========================================' + echo + + set -o pipefail + docker run -a stderr "${DOCKER_FLAGS[@]}" \ + "/vim-build/bin/$vim" -u test/vimrc \ + "+Vader! $tests" 2>&1 | color-vader-output || EXIT=$? + set +o pipefail + done + + echo +fi + +if ((run_vint)); then + echo '========================================' + echo 'Running Vint to lint our code' + echo '========================================' + echo 'Vint warnings/errors follow:' + echo + + set -o pipefail + docker run -a stdout "${DOCKER_FLAGS[@]}" vint -s . || EXIT=$? + set +o pipefail + echo +fi + +if ((run_custom_checks)); then + echo '========================================' + echo 'Running custom checks' + echo '========================================' + echo 'Custom warnings/errors follow:' + echo + + set -o pipefail + docker run -a stdout "${DOCKER_FLAGS[@]}" ./custom-checks . || EXIT=$? + set +o pipefail + echo +fi + +exit $EXIT diff --git a/test/.config/nvim/init.vim b/test/.config/nvim/init.vim new file mode 120000 index 00000000..90f52f07 --- /dev/null +++ b/test/.config/nvim/init.vim @@ -0,0 +1 @@ +../../vimrc \ No newline at end of file diff --git a/test/lsp/test_lsp_connections.vader b/test/lsp/test_lsp_connections.vader index 36a21bd2..d5ed7702 100644 --- a/test/lsp/test_lsp_connections.vader +++ b/test/lsp/test_lsp_connections.vader @@ -18,47 +18,92 @@ Execute(GetNextMessageID() should increment appropriately): AssertEqual 1, ale#lsp#GetNextMessageID() Execute(ale#lsp#CreateMessageData() should create an appropriate message): - " 71 is the size in bytes for UTF-8, not the number of characters. - AssertEqual - \ [ - \ 1, - \ "Content-Length: 71\r\n\r\n" - \ . '{"id":1,"jsonrpc":"2.0","method":"someMethod","params":{"foo":"barÜ"}}', - \ ], - \ ale#lsp#CreateMessageData([0, 'someMethod', {'foo': 'barÜ'}]) - " Check again to ensure that we use the next ID. - AssertEqual - \ [ - \ 2, - \ "Content-Length: 71\r\n\r\n" - \ . '{"id":2,"jsonrpc":"2.0","method":"someMethod","params":{"foo":"barÜ"}}', - \ ], - \ ale#lsp#CreateMessageData([0, 'someMethod', {'foo': 'barÜ'}]) + " NeoVim outputs JSON with spaces, so the output is a little different. + if has('nvim') + " 79 is the size in bytes for UTF-8, not the number of characters. + AssertEqual + \ [ + \ 1, + \ "Content-Length: 79\r\n\r\n" + \ . '{"id": 1, "jsonrpc": "2.0", "method": "someMethod", "params": {"foo": "barÜ"}}', + \ ], + \ ale#lsp#CreateMessageData([0, 'someMethod', {'foo': 'barÜ'}]) + " Check again to ensure that we use the next ID. + AssertEqual + \ [ + \ 2, + \ "Content-Length: 79\r\n\r\n" + \ . '{"id": 2, "jsonrpc": "2.0", "method": "someMethod", "params": {"foo": "barÜ"}}', + \ ], + \ ale#lsp#CreateMessageData([0, 'someMethod', {'foo': 'barÜ'}]) + else + AssertEqual + \ [ + \ 1, + \ "Content-Length: 71\r\n\r\n" + \ . '{"id":1,"jsonrpc":"2.0","method":"someMethod","params":{"foo":"barÜ"}}', + \ ], + \ ale#lsp#CreateMessageData([0, 'someMethod', {'foo': 'barÜ'}]) + AssertEqual + \ [ + \ 2, + \ "Content-Length: 71\r\n\r\n" + \ . '{"id":2,"jsonrpc":"2.0","method":"someMethod","params":{"foo":"barÜ"}}', + \ ], + \ ale#lsp#CreateMessageData([0, 'someMethod', {'foo': 'barÜ'}]) + endif Execute(ale#lsp#CreateMessageData() should create messages without params): - AssertEqual - \ [ - \ 1, - \ "Content-Length: 51\r\n\r\n" - \ . '{"id":1,"jsonrpc":"2.0","method":"someOtherMethod"}', - \ ], - \ ale#lsp#CreateMessageData([0, 'someOtherMethod']) + if has('nvim') + AssertEqual + \ [ + \ 1, + \ "Content-Length: 56\r\n\r\n" + \ . '{"id": 1, "jsonrpc": "2.0", "method": "someOtherMethod"}', + \ ], + \ ale#lsp#CreateMessageData([0, 'someOtherMethod']) + else + AssertEqual + \ [ + \ 1, + \ "Content-Length: 51\r\n\r\n" + \ . '{"id":1,"jsonrpc":"2.0","method":"someOtherMethod"}', + \ ], + \ ale#lsp#CreateMessageData([0, 'someOtherMethod']) + endif Execute(ale#lsp#CreateMessageData() should create notifications): - AssertEqual - \ [ - \ 0, - \ "Content-Length: 55\r\n\r\n" - \ . '{"id":null,"jsonrpc":"2.0","method":"someNotification"}', - \ ], - \ ale#lsp#CreateMessageData([1, 'someNotification']) - AssertEqual - \ [ - \ 0, - \ "Content-Length: 78\r\n\r\n" - \ . '{"id":null,"jsonrpc":"2.0","method":"someNotification","params":{"foo":"bar"}}', - \ ], - \ ale#lsp#CreateMessageData([1, 'someNotification', {'foo': 'bar'}]) + if has('nvim') + AssertEqual + \ [ + \ 0, + \ "Content-Length: 60\r\n\r\n" + \ . '{"id": null, "jsonrpc": "2.0", "method": "someNotification"}', + \ ], + \ ale#lsp#CreateMessageData([1, 'someNotification']) + AssertEqual + \ [ + \ 0, + \ "Content-Length: 86\r\n\r\n" + \ . '{"id": null, "jsonrpc": "2.0", "method": "someNotification", "params": {"foo": "bar"}}', + \ ], + \ ale#lsp#CreateMessageData([1, 'someNotification', {'foo': 'bar'}]) + else + AssertEqual + \ [ + \ 0, + \ "Content-Length: 55\r\n\r\n" + \ . '{"id":null,"jsonrpc":"2.0","method":"someNotification"}', + \ ], + \ ale#lsp#CreateMessageData([1, 'someNotification']) + AssertEqual + \ [ + \ 0, + \ "Content-Length: 78\r\n\r\n" + \ . '{"id":null,"jsonrpc":"2.0","method":"someNotification","params":{"foo":"bar"}}', + \ ], + \ ale#lsp#CreateMessageData([1, 'someNotification', {'foo': 'bar'}]) + endif Execute(ale#lsp#ReadMessageData() should read single whole messages): AssertEqual diff --git a/test/sign/test_linting_sets_signs.vader b/test/sign/test_linting_sets_signs.vader index 0654be47..1530847e 100644 --- a/test/sign/test_linting_sets_signs.vader +++ b/test/sign/test_linting_sets_signs.vader @@ -44,6 +44,7 @@ After: sign unplace * let g:ale_buffer_info = {} + call ale#linter#Reset() Execute(The signs should be updated after linting is done): call ale#Lint() diff --git a/test/test_conflicting_plugin_warnings.vader b/test/test_conflicting_plugin_warnings.vader index ebf53c8a..08a4c412 100644 --- a/test/test_conflicting_plugin_warnings.vader +++ b/test/test_conflicting_plugin_warnings.vader @@ -1,5 +1,9 @@ Execute(The after file should have been loaded for real): - Assert g:loaded_ale_after + " FIXME: Fix these tests in NeoVim. + if !has('nvim') + Assert has_key(g:, 'loaded_ale_after'), 'g:loaded_ale_after was not set!' + Assert g:loaded_ale_after + endif Before: silent! cd /testplugin/test diff --git a/test/test_cursor_warnings.vader b/test/test_cursor_warnings.vader index 09081b12..6018dabd 100644 --- a/test/test_cursor_warnings.vader +++ b/test/test_cursor_warnings.vader @@ -65,7 +65,10 @@ After: delfunction GetLastMessage - mess clear + " Clearing the messages breaks tests on NeoVim for some reason, but all + " we need to do for these tests is just make it so the last message isn't + " carried over between test cases. + echomsg '' Given javascript(A Javscript file with warnings/errors): var x = 3 diff --git a/test/test_history_saving.vader b/test/test_history_saving.vader index 2f1044d7..b6c75972 100644 --- a/test/test_history_saving.vader +++ b/test/test_history_saving.vader @@ -44,7 +44,13 @@ Execute(History should be set when commands are run): AssertEqual 1, len(g:history) AssertEqual sort(['status', 'exit_code', 'job_id', 'command']), sort(keys(g:history[0])) - AssertEqual ['/bin/sh', '-c', 'echo command history test'], g:history[0].command + + if has('nvim') + AssertEqual 'echo command history test', g:history[0].command + else + AssertEqual ['/bin/sh', '-c', 'echo command history test'], g:history[0].command + endif + AssertEqual 'finished', g:history[0].status AssertEqual 0, g:history[0].exit_code " The Job ID will change each time, but we can check the type.