From ac0d2723d005a396cd0cb603a8200a52e978daa5 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Sun, 16 Jan 2022 17:05:53 -0800 Subject: [PATCH] Add scripts to run the unit tests --- test/run_tests.cmd | 17 ++++++++++++++ test/run_tests.sh | 23 ++++++++++++++++++ test/{test_lsp.vim => unit_tests.vim} | 34 ++++++++++++++++++++------- 3 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 test/run_tests.cmd create mode 100755 test/run_tests.sh rename test/{test_lsp.vim => unit_tests.vim} (92%) diff --git a/test/run_tests.cmd b/test/run_tests.cmd new file mode 100644 index 0000000..46ec369 --- /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 0000000..989b7f6 --- /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 similarity index 92% rename from test/test_lsp.vim rename to test/unit_tests.vim index 5856392..6ff0b6d 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 @@ def Test_lsp_selection() 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 @@ def LspRunTests() 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 -- 2.48.1