2 # Common routines used for running the unit tests
4 # Load the LSP plugin. Also enable syntax, file type detection.
11 # Set the $LSP_PROFILE environment variable to profile the LSP plugin
12 var do_profile: bool = false
13 if exists('$LSP_PROFILE')
18 # profile the LSP plugin
19 profile start lsp_profile.txt
24 source ../plugin/lsp.vim
27 # The WaitFor*() functions are reused from the Vim test suite.
29 # Wait for up to five seconds for "assert" to return zero. "assert" must be a
30 # (lambda) function containing one assert function. Example:
31 # call WaitForAssert({-> assert_equal("dead", job_status(job)})
33 # A second argument can be used to specify a different timeout in msec.
35 # Return zero for success, one for failure (like the assert function).
36 func g:WaitForAssert(assert, ...)
37 let timeout = get(a:000, 0, 5000)
38 if g:WaitForCommon(v:null, a:assert, timeout) < 0
44 # Either "expr" or "assert" is not v:null
45 # Return the waiting time for success, -1 for failure.
46 func g:WaitForCommon(expr, assert, timeout)
47 " using reltime() is more accurate, but not always available
49 if exists('*reltimefloat')
54 if type(a:expr) == v:t_func
55 let success = a:expr()
56 elseif type(a:assert) == v:t_func
57 let success = a:assert() == 0
59 let success = eval(a:expr)
68 if type(a:assert) == v:t_func
69 " Remove the error added by the assert function.
70 call remove(v:errors, -1)
74 if exists('*reltimefloat')
75 let slept = float2nr(reltimefloat(reltime(start)) * 1000)
84 # Wait for up to five seconds for "expr" to become true. "expr" can be a
85 # stringified expression to evaluate, or a funcref without arguments.
86 # Using a lambda works best. Example:
87 # call WaitFor({-> status == "ok"})
89 # A second argument can be used to specify a different timeout in msec.
91 # When successful the time slept is returned.
92 # When running into the timeout an exception is thrown, thus the function does
94 func g:WaitFor(expr, ...)
95 let timeout = get(a:000, 0, 5000)
96 let slept = g:WaitForCommon(a:expr, v:null, timeout)
98 throw 'WaitFor() timed out after ' .. timeout .. ' msec'
103 # Wait for diagnostic messages from the LSP server.
104 # Waits for a maximum of (150 * 200) / 1000 = 30 seconds
105 def g:WaitForDiags(errCount: number)
108 var d = lsp#lsp#ErrorCount()
109 if d.Error == errCount
116 assert_equal(errCount, lsp#lsp#ErrorCount().Error)
117 if lsp#lsp#ErrorCount().Error != errCount
119 assert_report(getloclist(0)->string())
124 # Wait for the LSP server to load and process a file. This works by waiting
125 # for a certain number of diagnostic messages from the server.
126 def g:WaitForServerFileLoad(diagCount: number)
128 var waitCount = diagCount
130 # Introduce a temporary diagnostic
135 g:WaitForDiags(waitCount)
136 if waitCount != diagCount
137 # Remove the temporary line
138 deletebufline('%', '$')
144 # Start the language server. Returns true on success and false on failure.
145 # 'fname' is the name of a dummy file to start the server.
146 def g:StartLangServerWithFile(fname: string): bool
147 # Edit a dummy file to start the LSP server
148 exe ':silent! edit ' .. fname
149 # Wait for the LSP server to become ready (max 10 seconds)
151 while maxcount > 0 && !g:LspServerReady()
155 var serverStatus: bool = g:LspServerReady()
159 writefile(['FAIL: Not able to start the language server'], 'results.txt')
166 # vim: shiftwidth=2 softtabstop=2 noexpandtab