]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add scripts to run the unit tests
authorYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 17 Jan 2022 01:05:53 +0000 (17:05 -0800)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 17 Jan 2022 01:05:53 +0000 (17:05 -0800)
test/run_tests.cmd [new file with mode: 0644]
test/run_tests.sh [new file with mode: 0755]
test/unit_tests.vim [moved from test/test_lsp.vim with 92% similarity]

diff --git a/test/run_tests.cmd b/test/run_tests.cmd
new file mode 100644 (file)
index 0000000..46ec369
--- /dev/null
@@ -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 (executable)
index 0000000..989b7f6
--- /dev/null
@@ -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
similarity index 92%
rename from test/test_lsp.vim
rename to test/unit_tests.vim
index 5856392338474f044e5774cba05fafe63077414d..6ff0b6d49a31218ab253318c8b23a297b3307c71 100644 (file)
@@ -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