blob: 17e1d897a30f7119a7f99a59dd2bc8b89fc39714 [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
Peter Wolf8f1d0982024-10-27 21:51:14 +01004source screendump.vim
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +02005source check.vim
6
7CheckUnix
8CheckFeature terminal
9CheckExecutable gdb
10CheckExecutable gcc
11
12let g:GDB = exepath('gdb')
13if g:GDB->empty()
Christian Brabandtf2534432023-08-27 19:59:28 +020014 throw 'Skipped: gdb is not found in $PATH'
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020015endif
16
17let g:GCC = exepath('gcc')
18if g:GCC->empty()
Christian Brabandtf2534432023-08-27 19:59:28 +020019 throw 'Skipped: gcc is not found in $PATH'
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020020endif
21
iam28th323dda12023-12-14 20:30:26 +010022function s:generate_files(bin_name)
23 let src_name = a:bin_name .. '.c'
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020024 let lines =<< trim END
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 int isprime(int n)
29 {
30 if (n <= 1)
31 return 0;
32
33 for (int i = 2; i <= n / 2; i++)
34 if (n % i == 0)
35 return 0;
36
37 return 1;
38 }
39
40 int main(int argc, char *argv[])
41 {
42 int n = 7;
43
44 printf("%d is %s prime\n", n, isprime(n) ? "a" : "not a");
45
46 return 0;
47 }
48 END
iam28th323dda12023-12-14 20:30:26 +010049 call writefile(lines, src_name)
50 call system($'{g:GCC} -g -o {a:bin_name} {src_name}')
51endfunction
52
53function s:cleanup_files(bin_name)
54 call delete(a:bin_name)
55 call delete(a:bin_name .. '.c')
56endfunction
57
58packadd termdebug
59
60func Test_termdebug_basic()
61 let bin_name = 'XTD_basic'
62 let src_name = bin_name .. '.c'
63 call s:generate_files(bin_name)
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020064
65 edit XTD_basic.c
66 Termdebug ./XTD_basic
Christian Brabandt2979cfc2024-07-24 21:37:39 +020067 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020068 call WaitForAssert({-> assert_equal(3, winnr('$'))})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020069 let gdb_buf = winbufnr(1)
70 wincmd b
71 Break 9
72 call term_wait(gdb_buf)
73 redraw!
74 call assert_equal([
75 \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
76 \ 'priority': 110, 'group': 'TermDebug'}],
77 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)
78 Run
Christian Brabandt6c93c942023-08-27 21:48:29 +020079 call term_wait(gdb_buf, 400)
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020080 redraw!
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020081 call WaitForAssert({-> assert_equal([
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020082 \ {'lnum': 9, 'id': 12, 'name': 'debugPC', 'priority': 110,
83 \ 'group': 'TermDebug'},
84 \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
85 \ 'priority': 110, 'group': 'TermDebug'}],
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020086 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020087 Finish
88 call term_wait(gdb_buf)
89 redraw!
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020090 call WaitForAssert({-> assert_equal([
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020091 \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
92 \ 'priority': 110, 'group': 'TermDebug'},
93 \ {'lnum': 20, 'id': 12, 'name': 'debugPC',
94 \ 'priority': 110, 'group': 'TermDebug'}],
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020095 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020096 Continue
Shane-XB-Qian2dd613f2023-11-12 23:53:39 +080097 call term_wait(gdb_buf)
98
99 let i = 2
100 while i <= 258
101 Break
102 call term_wait(gdb_buf)
103 if i == 2
104 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint2.0')[0].text, '02')})
105 endif
106 if i == 10
107 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint10.0')[0].text, '0A')})
108 endif
109 if i == 168
110 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint168.0')[0].text, 'A8')})
111 endif
112 if i == 255
113 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint255.0')[0].text, 'FF')})
114 endif
115 if i == 256
116 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint256.0')[0].text, 'F+')})
117 endif
118 if i == 258
119 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint258.0')[0].text, 'F+')})
120 endif
121 let i += 1
122 endwhile
shane.xb.qianca482022023-11-08 21:59:15 +0100123
124 let cn = 0
125 " 60 is approx spaceBuffer * 3
126 if winwidth(0) <= 78 + 60
127 Var
zeertzjqaef61792024-07-18 20:35:42 +0200128 call assert_equal(winnr('$'), winnr())
129 call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['leaf', 1000], ['leaf', 1003 + cn]]], winlayout())
shane.xb.qianca482022023-11-08 21:59:15 +0100130 let cn += 1
131 bw!
132 Asm
zeertzjqaef61792024-07-18 20:35:42 +0200133 call assert_equal(winnr('$'), winnr())
134 call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['leaf', 1000], ['leaf', 1003 + cn]]], winlayout())
shane.xb.qianca482022023-11-08 21:59:15 +0100135 let cn += 1
136 bw!
137 endif
138 set columns=160
shane.xb.qianfdbadea2023-11-12 09:42:12 +0100139 call term_wait(gdb_buf)
Christian Brabandt305127f2023-11-11 18:59:33 +0100140 let winw = winwidth(0)
shane.xb.qianca482022023-11-08 21:59:15 +0100141 Var
Christian Brabandt305127f2023-11-11 18:59:33 +0100142 if winwidth(0) < winw
zeertzjqaef61792024-07-18 20:35:42 +0200143 call assert_equal(winnr('$') - 1, winnr())
144 call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]], winlayout())
Christian Brabandt305127f2023-11-11 18:59:33 +0100145 let cn += 1
146 bw!
147 endif
148 let winw = winwidth(0)
shane.xb.qianca482022023-11-08 21:59:15 +0100149 Asm
Christian Brabandt305127f2023-11-11 18:59:33 +0100150 if winwidth(0) < winw
zeertzjqaef61792024-07-18 20:35:42 +0200151 call assert_equal(winnr('$') - 1, winnr())
152 call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]], winlayout())
Christian Brabandt305127f2023-11-11 18:59:33 +0100153 let cn += 1
154 bw!
155 endif
shane.xb.qianca482022023-11-08 21:59:15 +0100156 set columns&
shane.xb.qianfdbadea2023-11-12 09:42:12 +0100157 call term_wait(gdb_buf)
shane.xb.qianca482022023-11-08 21:59:15 +0100158
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200159 wincmd t
160 quit!
161 redraw!
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100162 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200163 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
164
Ubaldo Tiberia90b0b42024-07-20 12:00:44 +0200165 for use_prompt in [v:true, v:false]
zeertzjqaef61792024-07-18 20:35:42 +0200166 let g:termdebug_config = {}
167 let g:termdebug_config['use_prompt'] = use_prompt
168 TermdebugCommand ./XTD_basic arg args
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200169 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
zeertzjqaef61792024-07-18 20:35:42 +0200170 call WaitForAssert({-> assert_equal(3, winnr('$'))})
171 wincmd t
172 quit!
173 redraw!
174 call WaitForAssert({-> assert_equal(1, winnr('$'))})
175 unlet g:termdebug_config
176 endfor
177
iam28th323dda12023-12-14 20:30:26 +0100178 call s:cleanup_files(bin_name)
179 %bw!
180endfunc
181
Ubaldo Tiberib5c15572024-11-19 21:10:24 +0100182func Test_termdebug_decimal_breakpoints()
183 let bin_name = 'XTD_decimal'
184 let src_name = bin_name .. '.c'
185 call s:generate_files(bin_name)
186
187 exe "edit " .. src_name
188
189 let g:termdebug_config = {}
190 let g:termdebug_config['sign_decimal'] = 1
191
192 exe "Termdebug " .. bin_name
193 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
194 call WaitForAssert({-> assert_equal(3, winnr('$'))})
195 let gdb_buf = winbufnr(1)
196 wincmd b
197 Break 9
198 call term_wait(gdb_buf)
199 redraw!
200
201 let i = 2
202 while i <= 258
203 Break
204 call term_wait(gdb_buf)
205 if i == 2
206 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint2.0')[0].text, '02')})
207 endif
208 if i == 10
209 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint10.0')[0].text, '10')})
210 endif
211 if i == 168
212 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint168.0')[0].text, '9+')})
213 endif
214 if i == 255
215 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint255.0')[0].text, '9+')})
216 endif
217 if i == 256
218 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint256.0')[0].text, '9+')})
219 endif
220 if i == 258
221 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint258.0')[0].text, '9+')})
222 endif
223 let i += 1
224 endwhile
225
226 wincmd t
227 quit!
228 redraw!
229 call WaitForAssert({-> assert_equal(1, winnr('$'))})
230 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
231
232 call s:cleanup_files(bin_name)
233 %bw!
234
235 unlet g:termdebug_config
236endfunc
237
iam28th323dda12023-12-14 20:30:26 +0100238func Test_termdebug_tbreak()
239 let g:test_is_flaky = 1
240 let bin_name = 'XTD_tbreak'
241 let src_name = bin_name .. '.c'
242
243 eval s:generate_files(bin_name)
244
245 execute 'edit ' .. src_name
246 execute 'Termdebug ./' .. bin_name
247
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200248 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
iam28th323dda12023-12-14 20:30:26 +0100249 call WaitForAssert({-> assert_equal(3, winnr('$'))})
250 let gdb_buf = winbufnr(1)
251 wincmd b
252
253 let bp_line = 22 " 'return' statement in main
254 let temp_bp_line = 10 " 'if' statement in 'for' loop body
255 execute "Tbreak " .. temp_bp_line
256 execute "Break " .. bp_line
257
258 call term_wait(gdb_buf)
259 redraw!
260 " both temporary and normal breakpoint signs were displayed...
261 call assert_equal([
262 \ {'lnum': temp_bp_line, 'id': 1014, 'name': 'debugBreakpoint1.0',
263 \ 'priority': 110, 'group': 'TermDebug'},
264 \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0',
265 \ 'priority': 110, 'group': 'TermDebug'}],
266 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)
267
268 Run
269 call term_wait(gdb_buf, 400)
270 redraw!
271 " debugPC sign is on the line where the temp. bp was set;
272 " temp. bp sign was removed after hit;
273 " normal bp sign is still present
274 call WaitForAssert({-> assert_equal([
275 \ {'lnum': temp_bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110,
276 \ 'group': 'TermDebug'},
277 \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0',
278 \ 'priority': 110, 'group': 'TermDebug'}],
279 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
280
281 Continue
282 call term_wait(gdb_buf)
283 redraw!
284 " debugPC is on the normal breakpoint,
285 " temp. bp on line 10 was only hit once
286 call WaitForAssert({-> assert_equal([
287 \ {'lnum': bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110,
288 \ 'group': 'TermDebug'},
289 \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0',
290 \ 'priority': 110, 'group': 'TermDebug'}],
291 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
292
293 wincmd t
294 quit!
295 redraw!
296 call WaitForAssert({-> assert_equal(1, winnr('$'))})
297 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
298
299 eval s:cleanup_files(bin_name)
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200300 %bw!
301endfunc
302
Peter Wolf8f1d0982024-10-27 21:51:14 +0100303func Test_termdebug_evaluate()
304 let bin_name = 'XTD_evaluate'
305 let src_name = bin_name .. '.c'
306 call s:generate_files(bin_name)
307
308 edit XTD_evaluate.c
309 Termdebug ./XTD_evaluate
310 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
311 call WaitForAssert({-> assert_equal(3, winnr('$'))})
312 let gdb_buf = winbufnr(1)
313 wincmd b
314
315 " return stmt in main
316 Break 22
317 call term_wait(gdb_buf)
318 Run
319 call term_wait(gdb_buf, 400)
320 redraw!
321
322 " Evaluate an expression
323 Evaluate n
324 call term_wait(gdb_buf)
325 call assert_equal(execute('1messages')->trim(), '"n": 7')
326 Evaluate argc
327 call term_wait(gdb_buf)
328 call assert_equal(execute('1messages')->trim(), '"argc": 1')
329 Evaluate isprime(n)
330 call term_wait(gdb_buf)
331 call assert_equal(execute('1messages')->trim(), '"isprime(n)": 1')
332
333 wincmd t
334 quit!
335 redraw!
336 call s:cleanup_files(bin_name)
337 %bw!
338endfunc
339
340func Test_termdebug_evaluate_in_popup()
341 CheckScreendump
342 let bin_name = 'XTD_evaluate_in_popup'
343 let src_name = bin_name .. '.c'
344 let code =<< trim END
345 struct Point {
346 int x;
347 int y;
348 };
349
350 int main(int argc, char* argv[]) {
351 struct Point p = {argc, 2};
352 struct Point* p_ptr = &p;
353 return 0;
354 }
355 END
356 call writefile(code, src_name, 'D')
357 call system($'{g:GCC} -g -o {bin_name} {src_name}')
358
359 let lines =<< trim END
360 edit XTD_evaluate_in_popup.c
361 packadd termdebug
362 let g:termdebug_config = {}
363 let g:termdebug_config['evaluate_in_popup'] = v:true
364 Termdebug ./XTD_evaluate_in_popup
365 wincmd b
366 Break 9
367 Run
368 END
369
370 call writefile(lines, 'Xscript', 'D')
371 let buf = RunVimInTerminal('-S Xscript', {})
372 call TermWait(buf, 400)
373
374 call term_sendkeys(buf, ":Evaluate p\<CR>")
375 call TermWait(buf, 400)
376 call VerifyScreenDump(buf, 'Test_termdebug_evaluate_in_popup_01', {})
377
378 call term_sendkeys(buf, ":Evaluate p_ptr\<CR>")
379 call TermWait(buf, 400)
380 call VerifyScreenDump(buf, 'Test_termdebug_evaluate_in_popup_02', {})
381
382 " Cleanup
383 call term_sendkeys(buf, ":Gdb")
384 call term_sendkeys(buf, ":quit!\<CR>")
385 call term_sendkeys(buf, ":qa!\<CR>")
386 call StopVimInTerminal(buf)
387 call delete(bin_name)
388 %bw!
389endfunc
390
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100391func Test_termdebug_mapping()
392 %bw!
Ken Takataffed1542024-05-21 17:14:56 +0200393 call assert_true(maparg('K', 'n', 0, 1)->empty())
394 call assert_true(maparg('-', 'n', 0, 1)->empty())
395 call assert_true(maparg('+', 'n', 0, 1)->empty())
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100396 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200397 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100398 call WaitForAssert({-> assert_equal(3, winnr('$'))})
399 wincmd b
Ken Takataffed1542024-05-21 17:14:56 +0200400 call assert_false(maparg('K', 'n', 0, 1)->empty())
401 call assert_false(maparg('-', 'n', 0, 1)->empty())
402 call assert_false(maparg('+', 'n', 0, 1)->empty())
403 call assert_false(maparg('K', 'n', 0, 1).buffer)
404 call assert_false(maparg('-', 'n', 0, 1).buffer)
405 call assert_false(maparg('+', 'n', 0, 1).buffer)
406 call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100407 wincmd t
408 quit!
409 redraw!
410 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Ken Takataffed1542024-05-21 17:14:56 +0200411 call assert_true(maparg('K', 'n', 0, 1)->empty())
412 call assert_true(maparg('-', 'n', 0, 1)->empty())
413 call assert_true(maparg('+', 'n', 0, 1)->empty())
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100414
415 %bw!
416 nnoremap K :echom "K"<cr>
417 nnoremap - :echom "-"<cr>
418 nnoremap + :echom "+"<cr>
419 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200420 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100421 call WaitForAssert({-> assert_equal(3, winnr('$'))})
422 wincmd b
Ken Takataffed1542024-05-21 17:14:56 +0200423 call assert_false(maparg('K', 'n', 0, 1)->empty())
424 call assert_false(maparg('-', 'n', 0, 1)->empty())
425 call assert_false(maparg('+', 'n', 0, 1)->empty())
426 call assert_false(maparg('K', 'n', 0, 1).buffer)
427 call assert_false(maparg('-', 'n', 0, 1).buffer)
428 call assert_false(maparg('+', 'n', 0, 1).buffer)
429 call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100430 wincmd t
431 quit!
432 redraw!
433 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Ken Takataffed1542024-05-21 17:14:56 +0200434 call assert_false(maparg('K', 'n', 0, 1)->empty())
435 call assert_false(maparg('-', 'n', 0, 1)->empty())
436 call assert_false(maparg('+', 'n', 0, 1)->empty())
437 call assert_false(maparg('K', 'n', 0, 1).buffer)
438 call assert_false(maparg('-', 'n', 0, 1).buffer)
439 call assert_false(maparg('+', 'n', 0, 1).buffer)
440 call assert_equal(':echom "K"<cr>', maparg('K', 'n', 0, 1).rhs)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100441
442 %bw!
Ubaldo Tiberi46f28232024-06-19 19:50:32 +0200443
444 " -- Test that local-buffer mappings are restored in the correct buffers --
445 " local mappings for foo
446 file foo
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100447 nnoremap <buffer> K :echom "bK"<cr>
448 nnoremap <buffer> - :echom "b-"<cr>
449 nnoremap <buffer> + :echom "b+"<cr>
Ubaldo Tiberi46f28232024-06-19 19:50:32 +0200450
451 " no mappings for 'bar'
452 enew
453 file bar
454
455 " Start termdebug from foo
456 buffer foo
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100457 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200458 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100459 call WaitForAssert({-> assert_equal(3, winnr('$'))})
460 wincmd b
Ken Takataffed1542024-05-21 17:14:56 +0200461 call assert_true(maparg('K', 'n', 0, 1).buffer)
462 call assert_true(maparg('-', 'n', 0, 1).buffer)
463 call assert_true(maparg('+', 'n', 0, 1).buffer)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100464 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
Ubaldo Tiberi46f28232024-06-19 19:50:32 +0200465
466 Source
467 buffer bar
468 call assert_false(maparg('K', 'n', 0, 1)->empty())
469 call assert_false(maparg('-', 'n', 0, 1)->empty())
470 call assert_false(maparg('+', 'n', 0, 1)->empty())
471 call assert_true(maparg('K', 'n', 0, 1).buffer->empty())
472 call assert_true(maparg('-', 'n', 0, 1).buffer->empty())
473 call assert_true(maparg('+', 'n', 0, 1).buffer->empty())
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100474 wincmd t
475 quit!
476 redraw!
477 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Ubaldo Tiberi46f28232024-06-19 19:50:32 +0200478
479 " Termdebug session ended. Buffer 'bar' shall have no mappings
480 call assert_true(bufname() ==# 'bar')
481 call assert_false(maparg('K', 'n', 0, 1)->empty())
482 call assert_false(maparg('-', 'n', 0, 1)->empty())
483 call assert_false(maparg('+', 'n', 0, 1)->empty())
484 call assert_true(maparg('K', 'n', 0, 1).buffer->empty())
485 call assert_true(maparg('-', 'n', 0, 1).buffer->empty())
486 call assert_true(maparg('+', 'n', 0, 1).buffer->empty())
487
488 " Buffer 'foo' shall have the same mapping as before running the termdebug
489 " session
490 buffer foo
491 call assert_true(bufname() ==# 'foo')
Ken Takataffed1542024-05-21 17:14:56 +0200492 call assert_true(maparg('K', 'n', 0, 1).buffer)
493 call assert_true(maparg('-', 'n', 0, 1).buffer)
494 call assert_true(maparg('+', 'n', 0, 1).buffer)
495 call assert_equal(':echom "bK"<cr>', maparg('K', 'n', 0, 1).rhs)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100496
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200497 nunmap K
498 nunmap +
499 nunmap -
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100500 %bw!
501endfunc
502
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200503function Test_termdebug_save_restore_variables()
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200504 " saved mousemodel
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200505 let &mousemodel=''
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200506
507 " saved keys
508 nnoremap K :echo "hello world!"<cr>
509 let expected_map_K = maparg('K', 'n', 0 , 1)
510 nnoremap + :echo "hello plus!"<cr>
511 let expected_map_plus = maparg('+', 'n', 0 , 1)
512 let expected_map_minus = {}
513
514 " saved &columns
515 let expected_columns = &columns
516
517 " We want termdebug to overwrite 'K' map but not '+' map.
518 let g:termdebug_config = {}
Ubaldo Tiberia90b0b42024-07-20 12:00:44 +0200519 let g:termdebug_config['map_K'] = v:true
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200520
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200521 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200522 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200523 call WaitForAssert({-> assert_equal(3, winnr('$'))})
524 call WaitForAssert({-> assert_match(&mousemodel, 'popup_setpos')})
525 wincmd t
526 quit!
527 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200528
529 call assert_true(empty(&mousemodel))
530
531 call assert_true(empty(expected_map_minus))
532 call assert_equal(expected_map_K.rhs, maparg('K', 'n', 0, 1).rhs)
533 call assert_equal(expected_map_plus.rhs, maparg('+', 'n', 0, 1).rhs)
534
535 call assert_equal(expected_columns, &columns)
536
537 nunmap K
538 nunmap +
539 unlet g:termdebug_config
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200540endfunction
541
Ubaldo Tiberif7f8f0b2024-06-20 22:17:34 +0200542function Test_termdebug_sanity_check()
543 " Test if user has filename/folders with wrong names
544 let g:termdebug_config = {}
545 let s:dict = {'disasm_window': 'Termdebug-asm-listing', 'use_prompt': 'gdb', 'variables_window': 'Termdebug-variables-listing'}
546
547 for key in keys(s:dict)
548 let s:filename = s:dict[key]
Ubaldo Tiberia90b0b42024-07-20 12:00:44 +0200549 let g:termdebug_config[key] = v:true
Ubaldo Tiberif7f8f0b2024-06-20 22:17:34 +0200550 let s:error_message = "You have a file/folder named '" .. s:filename .. "'"
551
552 " Write dummy file with bad name
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200553 call writefile(['This', 'is', 'a', 'test'], s:filename, 'D')
Ubaldo Tiberif7f8f0b2024-06-20 22:17:34 +0200554 Termdebug
555 call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)})
556 call WaitForAssert({-> assert_equal(1, winnr('$'))})
557
558 call delete(s:filename)
559 call remove(g:termdebug_config, key)
560 endfor
561
562 unlet g:termdebug_config
563endfunction
564
565function Test_termdebug_double_termdebug_instances()
566 let s:error_message = 'Terminal debugger already running, cannot run two'
567 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200568 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
Ubaldo Tiberif7f8f0b2024-06-20 22:17:34 +0200569 call WaitForAssert({-> assert_equal(3, winnr('$'))})
570 Termdebug
571 call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)})
572 wincmd t
573 quit!
574 call WaitForAssert({-> assert_equal(1, winnr('$'))})
575 :%bw!
576endfunction
Ubaldo Tiberi62ccaa62024-05-21 23:33:03 +0200577
Ubaldo Tiberia90b0b42024-07-20 12:00:44 +0200578function Test_termdebug_config_types()
579 " TODO Remove the deprecated features after 1 Jan 2025.
580 let g:termdebug_config = {}
581 let s:error_message = 'Deprecation Warning:'
582 call assert_true(maparg('K', 'n', 0, 1)->empty())
583
584 for key in ['disasm_window', 'variables_window', 'map_K']
585 for val in [0, 1, v:true, v:false]
586 let g:termdebug_config[key] = val
587 Termdebug
588
589 " Type check: warning is displayed
590 if typename(val) == 'number'
591 call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)})
592 endif
593
594 " Test on g:termdebug_config keys
595 if val && key != 'map_K'
596 call WaitForAssert({-> assert_equal(4, winnr('$'))})
597 call remove(g:termdebug_config, key)
598 else
599 call WaitForAssert({-> assert_equal(3, winnr('$'))})
600 endif
601
602 " Test on mapping
603 if key == 'map_K'
604 if val
605 call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs)
606 else
607 call assert_true(maparg('K', 'n', 0, 1)->empty())
608 endif
609 endif
610
611 " Shutoff termdebug
612 wincmd t
613 quit!
614 call WaitForAssert({-> assert_equal(1, winnr('$'))})
615 :%bw!
616
617 endfor
618 endfor
619
620 unlet g:termdebug_config
621endfunction
622
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200623" vim: shiftwidth=2 sts=2 expandtab