test/run_tests.cmd | 17 +++++++++++++++++ test/run_tests.sh | 23 +++++++++++++++++++++++ test/test_lsp.vim => test/unit_tests.vim | 34 +++++++++++++++++++++++++--------- diff --git a/test/run_tests.cmd b/test/run_tests.cmd new file mode 100644 index 0000000000000000000000000000000000000000..46ec369beb0c7a5e660fae58161a8c396bde70d8 --- /dev/null +++ b/test/run_tests.cmd @@ -0,0 +1,17 @@ +@echo off + +REM Script to run the unit-tests for the LSP Vim plugin on MS-Windows + +SETLOCAL +SET VIMPRG="vim.exe" +SET VIM_CMD=%VIMPRG% -u NONE -U NONE -i NONE --noplugin -N + +%VIM_CMD% -S unit_tests.vim + +echo LSP unit test results +type results.txt + +findstr /I FAIL results.txt > nul 2>&1 +if %ERRORLEVEL% EQU 0 echo ERROR: Some test failed. +if %ERRORLEVEL% NEQ 0 echo SUCCESS: All the tests passed. + diff --git a/test/run_tests.sh b/test/run_tests.sh new file mode 100755 index 0000000000000000000000000000000000000000..989b7f6af7f11f2be19670def0ce83118f079759 --- /dev/null +++ b/test/run_tests.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Script to run the unit-tests for the LSP Vim plugin + +VIMPRG=${VIMPRG:=/usr/bin/vim} +VIM_CMD="$VIMPRG -u NONE -U NONE -i NONE --noplugin -N" + +$VIM_CMD -S unit_tests.vim + +echo "LSP unit test results:" +echo +cat results.txt + +echo +grep FAIL results.txt > /dev/null 2>&1 +if [ $? -eq 0 ] +then + echo "ERROR: Some test(s) failed." + exit 1 +fi + +echo "SUCCESS: All the tests passed." +exit 0 diff --git a/test/test_lsp.vim b/test/unit_tests.vim rename from test/test_lsp.vim rename to test/unit_tests.vim index 5856392338474f044e5774cba05fafe63077414d..6ff0b6d49a31218ab253318c8b23a297b3307c71 100644 --- a/test/test_lsp.vim +++ b/test/unit_tests.vim @@ -1,6 +1,19 @@ vim9script -# Tests for Vim Language Server Protocol (LSP) client -# To run the tests, just source this file +# Unit tests for Vim Language Server Protocol (LSP) client + +syntax on +filetype on +filetype plugin on +filetype indent on + +set rtp+=../ +source ../plugin/lsp.vim +var lspServers = [{ + filetype: ['c', 'cpp'], + path: '/usr/bin/clangd', + args: ['--background-index', '--clang-tidy'] + }] +lsp#addServer(lspServers) g:LSPTest = true @@ -320,6 +333,10 @@ :%bw! enddef def LspRunTests() + :set nomore + :set debug=beep + delete('results.txt') + # Edit a dummy C file to start the LSP server :edit Xtest.c :sleep 500m @@ -340,17 +357,16 @@ endtry if v:errmsg != '' call add(v:errors, "Error: Test " .. f .. " generated error " .. v:errmsg) endif - if v:errors->len() != 0 - new Lsp-Test-Results - setline(1, ["Error: Test " .. f .. " failed"]->extend(v:errors)) - setbufvar('', '&modified', 0) - return + if !v:errors->empty() + writefile(v:errors, 'results.txt', 'a') + writefile([f .. ': FAIL'], 'results.txt', 'a') + else + writefile([f .. ': pass'], 'results.txt', 'a') endif endfor - - echomsg "Success: All the LSP tests have passed" enddef LspRunTests() +qall! # vim: shiftwidth=2 softtabstop=2 noexpandtab