blob: b5c12aefe190793eacc3c5b36edaf10ac8f26558 [file] [log] [blame]
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +02001" Test for the termdebug plugin
2
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +02003source shared.vim
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +02004source check.vim
5
6CheckUnix
7CheckFeature terminal
8CheckExecutable gdb
9CheckExecutable gcc
10
11let g:GDB = exepath('gdb')
12if g:GDB->empty()
Christian Brabandtf2534432023-08-27 19:59:28 +020013 throw 'Skipped: gdb is not found in $PATH'
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020014endif
15
16let g:GCC = exepath('gcc')
17if g:GCC->empty()
Christian Brabandtf2534432023-08-27 19:59:28 +020018 throw 'Skipped: gcc is not found in $PATH'
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020019endif
20
iam28th323dda12023-12-14 20:30:26 +010021function s:generate_files(bin_name)
22 let src_name = a:bin_name .. '.c'
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020023 let lines =<< trim END
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 int isprime(int n)
28 {
29 if (n <= 1)
30 return 0;
31
32 for (int i = 2; i <= n / 2; i++)
33 if (n % i == 0)
34 return 0;
35
36 return 1;
37 }
38
39 int main(int argc, char *argv[])
40 {
41 int n = 7;
42
43 printf("%d is %s prime\n", n, isprime(n) ? "a" : "not a");
44
45 return 0;
46 }
47 END
iam28th323dda12023-12-14 20:30:26 +010048 call writefile(lines, src_name)
49 call system($'{g:GCC} -g -o {a:bin_name} {src_name}')
50endfunction
51
52function s:cleanup_files(bin_name)
53 call delete(a:bin_name)
54 call delete(a:bin_name .. '.c')
55endfunction
56
57packadd termdebug
58
59func Test_termdebug_basic()
60 let bin_name = 'XTD_basic'
61 let src_name = bin_name .. '.c'
62 call s:generate_files(bin_name)
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020063
64 edit XTD_basic.c
65 Termdebug ./XTD_basic
Christian Brabandt2979cfc2024-07-24 21:37:39 +020066 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020067 call WaitForAssert({-> assert_equal(3, winnr('$'))})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020068 let gdb_buf = winbufnr(1)
69 wincmd b
70 Break 9
71 call term_wait(gdb_buf)
72 redraw!
73 call assert_equal([
74 \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
75 \ 'priority': 110, 'group': 'TermDebug'}],
76 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)
77 Run
Christian Brabandt6c93c942023-08-27 21:48:29 +020078 call term_wait(gdb_buf, 400)
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020079 redraw!
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020080 call WaitForAssert({-> assert_equal([
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020081 \ {'lnum': 9, 'id': 12, 'name': 'debugPC', 'priority': 110,
82 \ 'group': 'TermDebug'},
83 \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
84 \ 'priority': 110, 'group': 'TermDebug'}],
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020085 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020086 Finish
87 call term_wait(gdb_buf)
88 redraw!
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020089 call WaitForAssert({-> assert_equal([
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020090 \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
91 \ 'priority': 110, 'group': 'TermDebug'},
92 \ {'lnum': 20, 'id': 12, 'name': 'debugPC',
93 \ 'priority': 110, 'group': 'TermDebug'}],
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020094 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020095 Continue
Shane-XB-Qian2dd613f2023-11-12 23:53:39 +080096 call term_wait(gdb_buf)
97
98 let i = 2
99 while i <= 258
100 Break
101 call term_wait(gdb_buf)
102 if i == 2
103 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint2.0')[0].text, '02')})
104 endif
105 if i == 10
106 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint10.0')[0].text, '0A')})
107 endif
108 if i == 168
109 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint168.0')[0].text, 'A8')})
110 endif
111 if i == 255
112 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint255.0')[0].text, 'FF')})
113 endif
114 if i == 256
115 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint256.0')[0].text, 'F+')})
116 endif
117 if i == 258
118 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint258.0')[0].text, 'F+')})
119 endif
120 let i += 1
121 endwhile
shane.xb.qianca482022023-11-08 21:59:15 +0100122
123 let cn = 0
124 " 60 is approx spaceBuffer * 3
125 if winwidth(0) <= 78 + 60
126 Var
zeertzjqaef61792024-07-18 20:35:42 +0200127 call assert_equal(winnr('$'), winnr())
128 call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['leaf', 1000], ['leaf', 1003 + cn]]], winlayout())
shane.xb.qianca482022023-11-08 21:59:15 +0100129 let cn += 1
130 bw!
131 Asm
zeertzjqaef61792024-07-18 20:35:42 +0200132 call assert_equal(winnr('$'), winnr())
133 call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['leaf', 1000], ['leaf', 1003 + cn]]], winlayout())
shane.xb.qianca482022023-11-08 21:59:15 +0100134 let cn += 1
135 bw!
136 endif
137 set columns=160
shane.xb.qianfdbadea2023-11-12 09:42:12 +0100138 call term_wait(gdb_buf)
Christian Brabandt305127f2023-11-11 18:59:33 +0100139 let winw = winwidth(0)
shane.xb.qianca482022023-11-08 21:59:15 +0100140 Var
Christian Brabandt305127f2023-11-11 18:59:33 +0100141 if winwidth(0) < winw
zeertzjqaef61792024-07-18 20:35:42 +0200142 call assert_equal(winnr('$') - 1, winnr())
143 call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]], winlayout())
Christian Brabandt305127f2023-11-11 18:59:33 +0100144 let cn += 1
145 bw!
146 endif
147 let winw = winwidth(0)
shane.xb.qianca482022023-11-08 21:59:15 +0100148 Asm
Christian Brabandt305127f2023-11-11 18:59:33 +0100149 if winwidth(0) < winw
zeertzjqaef61792024-07-18 20:35:42 +0200150 call assert_equal(winnr('$') - 1, winnr())
151 call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]], winlayout())
Christian Brabandt305127f2023-11-11 18:59:33 +0100152 let cn += 1
153 bw!
154 endif
shane.xb.qianca482022023-11-08 21:59:15 +0100155 set columns&
shane.xb.qianfdbadea2023-11-12 09:42:12 +0100156 call term_wait(gdb_buf)
shane.xb.qianca482022023-11-08 21:59:15 +0100157
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200158 wincmd t
159 quit!
160 redraw!
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100161 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200162 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
163
Ubaldo Tiberia90b0b42024-07-20 12:00:44 +0200164 for use_prompt in [v:true, v:false]
zeertzjqaef61792024-07-18 20:35:42 +0200165 let g:termdebug_config = {}
166 let g:termdebug_config['use_prompt'] = use_prompt
167 TermdebugCommand ./XTD_basic arg args
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200168 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
zeertzjqaef61792024-07-18 20:35:42 +0200169 call WaitForAssert({-> assert_equal(3, winnr('$'))})
170 wincmd t
171 quit!
172 redraw!
173 call WaitForAssert({-> assert_equal(1, winnr('$'))})
174 unlet g:termdebug_config
175 endfor
176
iam28th323dda12023-12-14 20:30:26 +0100177 call s:cleanup_files(bin_name)
178 %bw!
179endfunc
180
181func Test_termdebug_tbreak()
182 let g:test_is_flaky = 1
183 let bin_name = 'XTD_tbreak'
184 let src_name = bin_name .. '.c'
185
186 eval s:generate_files(bin_name)
187
188 execute 'edit ' .. src_name
189 execute 'Termdebug ./' .. bin_name
190
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200191 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
iam28th323dda12023-12-14 20:30:26 +0100192 call WaitForAssert({-> assert_equal(3, winnr('$'))})
193 let gdb_buf = winbufnr(1)
194 wincmd b
195
196 let bp_line = 22 " 'return' statement in main
197 let temp_bp_line = 10 " 'if' statement in 'for' loop body
198 execute "Tbreak " .. temp_bp_line
199 execute "Break " .. bp_line
200
201 call term_wait(gdb_buf)
202 redraw!
203 " both temporary and normal breakpoint signs were displayed...
204 call assert_equal([
205 \ {'lnum': temp_bp_line, 'id': 1014, 'name': 'debugBreakpoint1.0',
206 \ 'priority': 110, 'group': 'TermDebug'},
207 \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0',
208 \ 'priority': 110, 'group': 'TermDebug'}],
209 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)
210
211 Run
212 call term_wait(gdb_buf, 400)
213 redraw!
214 " debugPC sign is on the line where the temp. bp was set;
215 " temp. bp sign was removed after hit;
216 " normal bp sign is still present
217 call WaitForAssert({-> assert_equal([
218 \ {'lnum': temp_bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110,
219 \ 'group': 'TermDebug'},
220 \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0',
221 \ 'priority': 110, 'group': 'TermDebug'}],
222 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
223
224 Continue
225 call term_wait(gdb_buf)
226 redraw!
227 " debugPC is on the normal breakpoint,
228 " temp. bp on line 10 was only hit once
229 call WaitForAssert({-> assert_equal([
230 \ {'lnum': bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110,
231 \ 'group': 'TermDebug'},
232 \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0',
233 \ 'priority': 110, 'group': 'TermDebug'}],
234 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
235
236 wincmd t
237 quit!
238 redraw!
239 call WaitForAssert({-> assert_equal(1, winnr('$'))})
240 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
241
242 eval s:cleanup_files(bin_name)
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200243 %bw!
244endfunc
245
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100246func Test_termdebug_mapping()
247 %bw!
Ken Takataffed1542024-05-21 17:14:56 +0200248 call assert_true(maparg('K', 'n', 0, 1)->empty())
249 call assert_true(maparg('-', 'n', 0, 1)->empty())
250 call assert_true(maparg('+', 'n', 0, 1)->empty())
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100251 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200252 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100253 call WaitForAssert({-> assert_equal(3, winnr('$'))})
254 wincmd b
Ken Takataffed1542024-05-21 17:14:56 +0200255 call assert_false(maparg('K', 'n', 0, 1)->empty())
256 call assert_false(maparg('-', 'n', 0, 1)->empty())
257 call assert_false(maparg('+', 'n', 0, 1)->empty())
258 call assert_false(maparg('K', 'n', 0, 1).buffer)
259 call assert_false(maparg('-', 'n', 0, 1).buffer)
260 call assert_false(maparg('+', 'n', 0, 1).buffer)
261 call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100262 wincmd t
263 quit!
264 redraw!
265 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Ken Takataffed1542024-05-21 17:14:56 +0200266 call assert_true(maparg('K', 'n', 0, 1)->empty())
267 call assert_true(maparg('-', 'n', 0, 1)->empty())
268 call assert_true(maparg('+', 'n', 0, 1)->empty())
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100269
270 %bw!
271 nnoremap K :echom "K"<cr>
272 nnoremap - :echom "-"<cr>
273 nnoremap + :echom "+"<cr>
274 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200275 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100276 call WaitForAssert({-> assert_equal(3, winnr('$'))})
277 wincmd b
Ken Takataffed1542024-05-21 17:14:56 +0200278 call assert_false(maparg('K', 'n', 0, 1)->empty())
279 call assert_false(maparg('-', 'n', 0, 1)->empty())
280 call assert_false(maparg('+', 'n', 0, 1)->empty())
281 call assert_false(maparg('K', 'n', 0, 1).buffer)
282 call assert_false(maparg('-', 'n', 0, 1).buffer)
283 call assert_false(maparg('+', 'n', 0, 1).buffer)
284 call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100285 wincmd t
286 quit!
287 redraw!
288 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Ken Takataffed1542024-05-21 17:14:56 +0200289 call assert_false(maparg('K', 'n', 0, 1)->empty())
290 call assert_false(maparg('-', 'n', 0, 1)->empty())
291 call assert_false(maparg('+', 'n', 0, 1)->empty())
292 call assert_false(maparg('K', 'n', 0, 1).buffer)
293 call assert_false(maparg('-', 'n', 0, 1).buffer)
294 call assert_false(maparg('+', 'n', 0, 1).buffer)
295 call assert_equal(':echom "K"<cr>', maparg('K', 'n', 0, 1).rhs)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100296
297 %bw!
Ubaldo Tiberi46f28232024-06-19 19:50:32 +0200298
299 " -- Test that local-buffer mappings are restored in the correct buffers --
300 " local mappings for foo
301 file foo
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100302 nnoremap <buffer> K :echom "bK"<cr>
303 nnoremap <buffer> - :echom "b-"<cr>
304 nnoremap <buffer> + :echom "b+"<cr>
Ubaldo Tiberi46f28232024-06-19 19:50:32 +0200305
306 " no mappings for 'bar'
307 enew
308 file bar
309
310 " Start termdebug from foo
311 buffer foo
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100312 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200313 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100314 call WaitForAssert({-> assert_equal(3, winnr('$'))})
315 wincmd b
Ken Takataffed1542024-05-21 17:14:56 +0200316 call assert_true(maparg('K', 'n', 0, 1).buffer)
317 call assert_true(maparg('-', 'n', 0, 1).buffer)
318 call assert_true(maparg('+', 'n', 0, 1).buffer)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100319 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
Ubaldo Tiberi46f28232024-06-19 19:50:32 +0200320
321 Source
322 buffer bar
323 call assert_false(maparg('K', 'n', 0, 1)->empty())
324 call assert_false(maparg('-', 'n', 0, 1)->empty())
325 call assert_false(maparg('+', 'n', 0, 1)->empty())
326 call assert_true(maparg('K', 'n', 0, 1).buffer->empty())
327 call assert_true(maparg('-', 'n', 0, 1).buffer->empty())
328 call assert_true(maparg('+', 'n', 0, 1).buffer->empty())
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100329 wincmd t
330 quit!
331 redraw!
332 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Ubaldo Tiberi46f28232024-06-19 19:50:32 +0200333
334 " Termdebug session ended. Buffer 'bar' shall have no mappings
335 call assert_true(bufname() ==# 'bar')
336 call assert_false(maparg('K', 'n', 0, 1)->empty())
337 call assert_false(maparg('-', 'n', 0, 1)->empty())
338 call assert_false(maparg('+', 'n', 0, 1)->empty())
339 call assert_true(maparg('K', 'n', 0, 1).buffer->empty())
340 call assert_true(maparg('-', 'n', 0, 1).buffer->empty())
341 call assert_true(maparg('+', 'n', 0, 1).buffer->empty())
342
343 " Buffer 'foo' shall have the same mapping as before running the termdebug
344 " session
345 buffer foo
346 call assert_true(bufname() ==# 'foo')
Ken Takataffed1542024-05-21 17:14:56 +0200347 call assert_true(maparg('K', 'n', 0, 1).buffer)
348 call assert_true(maparg('-', 'n', 0, 1).buffer)
349 call assert_true(maparg('+', 'n', 0, 1).buffer)
350 call assert_equal(':echom "bK"<cr>', maparg('K', 'n', 0, 1).rhs)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100351
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200352 nunmap K
353 nunmap +
354 nunmap -
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100355 %bw!
356endfunc
357
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200358function Test_termdebug_save_restore_variables()
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200359 " saved mousemodel
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200360 let &mousemodel=''
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200361
362 " saved keys
363 nnoremap K :echo "hello world!"<cr>
364 let expected_map_K = maparg('K', 'n', 0 , 1)
365 nnoremap + :echo "hello plus!"<cr>
366 let expected_map_plus = maparg('+', 'n', 0 , 1)
367 let expected_map_minus = {}
368
369 " saved &columns
370 let expected_columns = &columns
371
372 " We want termdebug to overwrite 'K' map but not '+' map.
373 let g:termdebug_config = {}
Ubaldo Tiberia90b0b42024-07-20 12:00:44 +0200374 let g:termdebug_config['map_K'] = v:true
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200375
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200376 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200377 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200378 call WaitForAssert({-> assert_equal(3, winnr('$'))})
379 call WaitForAssert({-> assert_match(&mousemodel, 'popup_setpos')})
380 wincmd t
381 quit!
382 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200383
384 call assert_true(empty(&mousemodel))
385
386 call assert_true(empty(expected_map_minus))
387 call assert_equal(expected_map_K.rhs, maparg('K', 'n', 0, 1).rhs)
388 call assert_equal(expected_map_plus.rhs, maparg('+', 'n', 0, 1).rhs)
389
390 call assert_equal(expected_columns, &columns)
391
392 nunmap K
393 nunmap +
394 unlet g:termdebug_config
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200395endfunction
396
Ubaldo Tiberif7f8f0b2024-06-20 22:17:34 +0200397function Test_termdebug_sanity_check()
398 " Test if user has filename/folders with wrong names
399 let g:termdebug_config = {}
400 let s:dict = {'disasm_window': 'Termdebug-asm-listing', 'use_prompt': 'gdb', 'variables_window': 'Termdebug-variables-listing'}
401
402 for key in keys(s:dict)
403 let s:filename = s:dict[key]
Ubaldo Tiberia90b0b42024-07-20 12:00:44 +0200404 let g:termdebug_config[key] = v:true
Ubaldo Tiberif7f8f0b2024-06-20 22:17:34 +0200405 let s:error_message = "You have a file/folder named '" .. s:filename .. "'"
406
407 " Write dummy file with bad name
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200408 call writefile(['This', 'is', 'a', 'test'], s:filename, 'D')
Ubaldo Tiberif7f8f0b2024-06-20 22:17:34 +0200409 Termdebug
410 call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)})
411 call WaitForAssert({-> assert_equal(1, winnr('$'))})
412
413 call delete(s:filename)
414 call remove(g:termdebug_config, key)
415 endfor
416
417 unlet g:termdebug_config
418endfunction
419
420function Test_termdebug_double_termdebug_instances()
421 let s:error_message = 'Terminal debugger already running, cannot run two'
422 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200423 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
Ubaldo Tiberif7f8f0b2024-06-20 22:17:34 +0200424 call WaitForAssert({-> assert_equal(3, winnr('$'))})
425 Termdebug
426 call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)})
427 wincmd t
428 quit!
429 call WaitForAssert({-> assert_equal(1, winnr('$'))})
430 :%bw!
431endfunction
Ubaldo Tiberi62ccaa62024-05-21 23:33:03 +0200432
Ubaldo Tiberia90b0b42024-07-20 12:00:44 +0200433function Test_termdebug_config_types()
434 " TODO Remove the deprecated features after 1 Jan 2025.
435 let g:termdebug_config = {}
436 let s:error_message = 'Deprecation Warning:'
437 call assert_true(maparg('K', 'n', 0, 1)->empty())
438
439 for key in ['disasm_window', 'variables_window', 'map_K']
440 for val in [0, 1, v:true, v:false]
441 let g:termdebug_config[key] = val
442 Termdebug
443
444 " Type check: warning is displayed
445 if typename(val) == 'number'
446 call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)})
447 endif
448
449 " Test on g:termdebug_config keys
450 if val && key != 'map_K'
451 call WaitForAssert({-> assert_equal(4, winnr('$'))})
452 call remove(g:termdebug_config, key)
453 else
454 call WaitForAssert({-> assert_equal(3, winnr('$'))})
455 endif
456
457 " Test on mapping
458 if key == 'map_K'
459 if val
460 call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs)
461 else
462 call assert_true(maparg('K', 'n', 0, 1)->empty())
463 endif
464 endif
465
466 " Shutoff termdebug
467 wincmd t
468 quit!
469 call WaitForAssert({-> assert_equal(1, winnr('$'))})
470 :%bw!
471
472 endfor
473 endfor
474
475 unlet g:termdebug_config
476endfunction
477
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200478" vim: shiftwidth=2 sts=2 expandtab