]> Sergey Matveev's repositories - vim-lsp.git/blob - test/runner.vim
Optimize the diags handling code
[vim-lsp.git] / test / runner.vim
1 vim9script
2 # Script to run a language server unit tests
3 # The global variable TestName should be set to the name of the file
4 # containing the tests.
5
6 source common.vim
7
8 def LspRunTests()
9   :set nomore
10   :set debug=beep
11   delete('results.txt')
12
13   # Get the list of test functions in this file and call them
14   var fns: list<string> = execute('function /^Test_')
15                     ->split("\n")
16                     ->map("v:val->substitute('^def ', '', '')")
17                     ->sort()
18   if fns->empty()
19     # No tests are found
20     writefile(['No tests are found'], 'results.txt')
21     return
22   endif
23   for f in fns
24     v:errors = []
25     v:errmsg = ''
26     try
27       :%bw!
28       exe $'g:{f}'
29     catch
30       call add(v:errors, $'Error: Test {f} failed with exception {v:exception} at {v:throwpoint}')
31     endtry
32     if v:errmsg != ''
33       call add(v:errors, $'Error: Test {f} generated error {v:errmsg}')
34     endif
35     if !v:errors->empty()
36       writefile(v:errors, 'results.txt', 'a')
37       writefile([$'{f}: FAIL'], 'results.txt', 'a')
38     else
39       writefile([$'{f}: pass'], 'results.txt', 'a')
40     endif
41   endfor
42 enddef
43
44 try
45   g:LoadLspPlugin()
46   exe $'source {g:TestName}'
47   g:StartLangServer()
48   LspRunTests()
49 catch
50   writefile(['FAIL: Tests in ' .. g:TestName .. ' failed with exception ' .. v:exception .. ' at ' .. v:throwpoint], 'results.txt', 'a')
51 endtry
52
53 qall!
54
55 # vim: shiftwidth=2 softtabstop=2 noexpandtab