blob: 30176cb75b61852f7d87cec4f605313124f4a00d [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
182func Test_termdebug_tbreak()
183 let g:test_is_flaky = 1
184 let bin_name = 'XTD_tbreak'
185 let src_name = bin_name .. '.c'
186
187 eval s:generate_files(bin_name)
188
189 execute 'edit ' .. src_name
190 execute 'Termdebug ./' .. bin_name
191
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200192 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
iam28th323dda12023-12-14 20:30:26 +0100193 call WaitForAssert({-> assert_equal(3, winnr('$'))})
194 let gdb_buf = winbufnr(1)
195 wincmd b
196
197 let bp_line = 22 " 'return' statement in main
198 let temp_bp_line = 10 " 'if' statement in 'for' loop body
199 execute "Tbreak " .. temp_bp_line
200 execute "Break " .. bp_line
201
202 call term_wait(gdb_buf)
203 redraw!
204 " both temporary and normal breakpoint signs were displayed...
205 call assert_equal([
206 \ {'lnum': temp_bp_line, 'id': 1014, 'name': 'debugBreakpoint1.0',
207 \ 'priority': 110, 'group': 'TermDebug'},
208 \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0',
209 \ 'priority': 110, 'group': 'TermDebug'}],
210 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)
211
212 Run
213 call term_wait(gdb_buf, 400)
214 redraw!
215 " debugPC sign is on the line where the temp. bp was set;
216 " temp. bp sign was removed after hit;
217 " normal bp sign is still present
218 call WaitForAssert({-> assert_equal([
219 \ {'lnum': temp_bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110,
220 \ 'group': 'TermDebug'},
221 \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0',
222 \ 'priority': 110, 'group': 'TermDebug'}],
223 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
224
225 Continue
226 call term_wait(gdb_buf)
227 redraw!
228 " debugPC is on the normal breakpoint,
229 " temp. bp on line 10 was only hit once
230 call WaitForAssert({-> assert_equal([
231 \ {'lnum': bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110,
232 \ 'group': 'TermDebug'},
233 \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0',
234 \ 'priority': 110, 'group': 'TermDebug'}],
235 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
236
237 wincmd t
238 quit!
239 redraw!
240 call WaitForAssert({-> assert_equal(1, winnr('$'))})
241 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
242
243 eval s:cleanup_files(bin_name)
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200244 %bw!
245endfunc
246
Peter Wolf8f1d0982024-10-27 21:51:14 +0100247func Test_termdebug_evaluate()
248 let bin_name = 'XTD_evaluate'
249 let src_name = bin_name .. '.c'
250 call s:generate_files(bin_name)
251
252 edit XTD_evaluate.c
253 Termdebug ./XTD_evaluate
254 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
255 call WaitForAssert({-> assert_equal(3, winnr('$'))})
256 let gdb_buf = winbufnr(1)
257 wincmd b
258
259 " return stmt in main
260 Break 22
261 call term_wait(gdb_buf)
262 Run
263 call term_wait(gdb_buf, 400)
264 redraw!
265
266 " Evaluate an expression
267 Evaluate n
268 call term_wait(gdb_buf)
269 call assert_equal(execute('1messages')->trim(), '"n": 7')
270 Evaluate argc
271 call term_wait(gdb_buf)
272 call assert_equal(execute('1messages')->trim(), '"argc": 1')
273 Evaluate isprime(n)
274 call term_wait(gdb_buf)
275 call assert_equal(execute('1messages')->trim(), '"isprime(n)": 1')
276
277 wincmd t
278 quit!
279 redraw!
280 call s:cleanup_files(bin_name)
281 %bw!
282endfunc
283
284func Test_termdebug_evaluate_in_popup()
285 CheckScreendump
286 let bin_name = 'XTD_evaluate_in_popup'
287 let src_name = bin_name .. '.c'
288 let code =<< trim END
289 struct Point {
290 int x;
291 int y;
292 };
293
294 int main(int argc, char* argv[]) {
295 struct Point p = {argc, 2};
296 struct Point* p_ptr = &p;
297 return 0;
298 }
299 END
300 call writefile(code, src_name, 'D')
301 call system($'{g:GCC} -g -o {bin_name} {src_name}')
302
303 let lines =<< trim END
304 edit XTD_evaluate_in_popup.c
305 packadd termdebug
306 let g:termdebug_config = {}
307 let g:termdebug_config['evaluate_in_popup'] = v:true
308 Termdebug ./XTD_evaluate_in_popup
309 wincmd b
310 Break 9
311 Run
312 END
313
314 call writefile(lines, 'Xscript', 'D')
315 let buf = RunVimInTerminal('-S Xscript', {})
316 call TermWait(buf, 400)
317
318 call term_sendkeys(buf, ":Evaluate p\<CR>")
319 call TermWait(buf, 400)
320 call VerifyScreenDump(buf, 'Test_termdebug_evaluate_in_popup_01', {})
321
322 call term_sendkeys(buf, ":Evaluate p_ptr\<CR>")
323 call TermWait(buf, 400)
324 call VerifyScreenDump(buf, 'Test_termdebug_evaluate_in_popup_02', {})
325
326 " Cleanup
327 call term_sendkeys(buf, ":Gdb")
328 call term_sendkeys(buf, ":quit!\<CR>")
329 call term_sendkeys(buf, ":qa!\<CR>")
330 call StopVimInTerminal(buf)
331 call delete(bin_name)
332 %bw!
333endfunc
334
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100335func Test_termdebug_mapping()
336 %bw!
Ken Takataffed1542024-05-21 17:14:56 +0200337 call assert_true(maparg('K', 'n', 0, 1)->empty())
338 call assert_true(maparg('-', 'n', 0, 1)->empty())
339 call assert_true(maparg('+', 'n', 0, 1)->empty())
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100340 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200341 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100342 call WaitForAssert({-> assert_equal(3, winnr('$'))})
343 wincmd b
Ken Takataffed1542024-05-21 17:14:56 +0200344 call assert_false(maparg('K', 'n', 0, 1)->empty())
345 call assert_false(maparg('-', 'n', 0, 1)->empty())
346 call assert_false(maparg('+', 'n', 0, 1)->empty())
347 call assert_false(maparg('K', 'n', 0, 1).buffer)
348 call assert_false(maparg('-', 'n', 0, 1).buffer)
349 call assert_false(maparg('+', 'n', 0, 1).buffer)
350 call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100351 wincmd t
352 quit!
353 redraw!
354 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Ken Takataffed1542024-05-21 17:14:56 +0200355 call assert_true(maparg('K', 'n', 0, 1)->empty())
356 call assert_true(maparg('-', 'n', 0, 1)->empty())
357 call assert_true(maparg('+', 'n', 0, 1)->empty())
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100358
359 %bw!
360 nnoremap K :echom "K"<cr>
361 nnoremap - :echom "-"<cr>
362 nnoremap + :echom "+"<cr>
363 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200364 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100365 call WaitForAssert({-> assert_equal(3, winnr('$'))})
366 wincmd b
Ken Takataffed1542024-05-21 17:14:56 +0200367 call assert_false(maparg('K', 'n', 0, 1)->empty())
368 call assert_false(maparg('-', 'n', 0, 1)->empty())
369 call assert_false(maparg('+', 'n', 0, 1)->empty())
370 call assert_false(maparg('K', 'n', 0, 1).buffer)
371 call assert_false(maparg('-', 'n', 0, 1).buffer)
372 call assert_false(maparg('+', 'n', 0, 1).buffer)
373 call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100374 wincmd t
375 quit!
376 redraw!
377 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Ken Takataffed1542024-05-21 17:14:56 +0200378 call assert_false(maparg('K', 'n', 0, 1)->empty())
379 call assert_false(maparg('-', 'n', 0, 1)->empty())
380 call assert_false(maparg('+', 'n', 0, 1)->empty())
381 call assert_false(maparg('K', 'n', 0, 1).buffer)
382 call assert_false(maparg('-', 'n', 0, 1).buffer)
383 call assert_false(maparg('+', 'n', 0, 1).buffer)
384 call assert_equal(':echom "K"<cr>', maparg('K', 'n', 0, 1).rhs)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100385
386 %bw!
Ubaldo Tiberi46f28232024-06-19 19:50:32 +0200387
388 " -- Test that local-buffer mappings are restored in the correct buffers --
389 " local mappings for foo
390 file foo
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100391 nnoremap <buffer> K :echom "bK"<cr>
392 nnoremap <buffer> - :echom "b-"<cr>
393 nnoremap <buffer> + :echom "b+"<cr>
Ubaldo Tiberi46f28232024-06-19 19:50:32 +0200394
395 " no mappings for 'bar'
396 enew
397 file bar
398
399 " Start termdebug from foo
400 buffer foo
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100401 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200402 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100403 call WaitForAssert({-> assert_equal(3, winnr('$'))})
404 wincmd b
Ken Takataffed1542024-05-21 17:14:56 +0200405 call assert_true(maparg('K', 'n', 0, 1).buffer)
406 call assert_true(maparg('-', 'n', 0, 1).buffer)
407 call assert_true(maparg('+', 'n', 0, 1).buffer)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100408 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
Ubaldo Tiberi46f28232024-06-19 19:50:32 +0200409
410 Source
411 buffer bar
412 call assert_false(maparg('K', 'n', 0, 1)->empty())
413 call assert_false(maparg('-', 'n', 0, 1)->empty())
414 call assert_false(maparg('+', 'n', 0, 1)->empty())
415 call assert_true(maparg('K', 'n', 0, 1).buffer->empty())
416 call assert_true(maparg('-', 'n', 0, 1).buffer->empty())
417 call assert_true(maparg('+', 'n', 0, 1).buffer->empty())
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100418 wincmd t
419 quit!
420 redraw!
421 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Ubaldo Tiberi46f28232024-06-19 19:50:32 +0200422
423 " Termdebug session ended. Buffer 'bar' shall have no mappings
424 call assert_true(bufname() ==# 'bar')
425 call assert_false(maparg('K', 'n', 0, 1)->empty())
426 call assert_false(maparg('-', 'n', 0, 1)->empty())
427 call assert_false(maparg('+', 'n', 0, 1)->empty())
428 call assert_true(maparg('K', 'n', 0, 1).buffer->empty())
429 call assert_true(maparg('-', 'n', 0, 1).buffer->empty())
430 call assert_true(maparg('+', 'n', 0, 1).buffer->empty())
431
432 " Buffer 'foo' shall have the same mapping as before running the termdebug
433 " session
434 buffer foo
435 call assert_true(bufname() ==# 'foo')
Ken Takataffed1542024-05-21 17:14:56 +0200436 call assert_true(maparg('K', 'n', 0, 1).buffer)
437 call assert_true(maparg('-', 'n', 0, 1).buffer)
438 call assert_true(maparg('+', 'n', 0, 1).buffer)
439 call assert_equal(':echom "bK"<cr>', maparg('K', 'n', 0, 1).rhs)
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100440
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200441 nunmap K
442 nunmap +
443 nunmap -
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100444 %bw!
445endfunc
446
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200447function Test_termdebug_save_restore_variables()
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200448 " saved mousemodel
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200449 let &mousemodel=''
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200450
451 " saved keys
452 nnoremap K :echo "hello world!"<cr>
453 let expected_map_K = maparg('K', 'n', 0 , 1)
454 nnoremap + :echo "hello plus!"<cr>
455 let expected_map_plus = maparg('+', 'n', 0 , 1)
456 let expected_map_minus = {}
457
458 " saved &columns
459 let expected_columns = &columns
460
461 " We want termdebug to overwrite 'K' map but not '+' map.
462 let g:termdebug_config = {}
Ubaldo Tiberia90b0b42024-07-20 12:00:44 +0200463 let g:termdebug_config['map_K'] = v:true
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200464
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200465 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200466 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200467 call WaitForAssert({-> assert_equal(3, winnr('$'))})
468 call WaitForAssert({-> assert_match(&mousemodel, 'popup_setpos')})
469 wincmd t
470 quit!
471 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Ubaldo Tiberia48637c2024-06-18 20:18:20 +0200472
473 call assert_true(empty(&mousemodel))
474
475 call assert_true(empty(expected_map_minus))
476 call assert_equal(expected_map_K.rhs, maparg('K', 'n', 0, 1).rhs)
477 call assert_equal(expected_map_plus.rhs, maparg('+', 'n', 0, 1).rhs)
478
479 call assert_equal(expected_columns, &columns)
480
481 nunmap K
482 nunmap +
483 unlet g:termdebug_config
Ubaldo Tiberief8eab82024-06-13 19:23:07 +0200484endfunction
485
Ubaldo Tiberif7f8f0b2024-06-20 22:17:34 +0200486function Test_termdebug_sanity_check()
487 " Test if user has filename/folders with wrong names
488 let g:termdebug_config = {}
489 let s:dict = {'disasm_window': 'Termdebug-asm-listing', 'use_prompt': 'gdb', 'variables_window': 'Termdebug-variables-listing'}
490
491 for key in keys(s:dict)
492 let s:filename = s:dict[key]
Ubaldo Tiberia90b0b42024-07-20 12:00:44 +0200493 let g:termdebug_config[key] = v:true
Ubaldo Tiberif7f8f0b2024-06-20 22:17:34 +0200494 let s:error_message = "You have a file/folder named '" .. s:filename .. "'"
495
496 " Write dummy file with bad name
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200497 call writefile(['This', 'is', 'a', 'test'], s:filename, 'D')
Ubaldo Tiberif7f8f0b2024-06-20 22:17:34 +0200498 Termdebug
499 call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)})
500 call WaitForAssert({-> assert_equal(1, winnr('$'))})
501
502 call delete(s:filename)
503 call remove(g:termdebug_config, key)
504 endfor
505
506 unlet g:termdebug_config
507endfunction
508
509function Test_termdebug_double_termdebug_instances()
510 let s:error_message = 'Terminal debugger already running, cannot run two'
511 Termdebug
Christian Brabandt2979cfc2024-07-24 21:37:39 +0200512 call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
Ubaldo Tiberif7f8f0b2024-06-20 22:17:34 +0200513 call WaitForAssert({-> assert_equal(3, winnr('$'))})
514 Termdebug
515 call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)})
516 wincmd t
517 quit!
518 call WaitForAssert({-> assert_equal(1, winnr('$'))})
519 :%bw!
520endfunction
Ubaldo Tiberi62ccaa62024-05-21 23:33:03 +0200521
Ubaldo Tiberia90b0b42024-07-20 12:00:44 +0200522function Test_termdebug_config_types()
523 " TODO Remove the deprecated features after 1 Jan 2025.
524 let g:termdebug_config = {}
525 let s:error_message = 'Deprecation Warning:'
526 call assert_true(maparg('K', 'n', 0, 1)->empty())
527
528 for key in ['disasm_window', 'variables_window', 'map_K']
529 for val in [0, 1, v:true, v:false]
530 let g:termdebug_config[key] = val
531 Termdebug
532
533 " Type check: warning is displayed
534 if typename(val) == 'number'
535 call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)})
536 endif
537
538 " Test on g:termdebug_config keys
539 if val && key != 'map_K'
540 call WaitForAssert({-> assert_equal(4, winnr('$'))})
541 call remove(g:termdebug_config, key)
542 else
543 call WaitForAssert({-> assert_equal(3, winnr('$'))})
544 endif
545
546 " Test on mapping
547 if key == 'map_K'
548 if val
549 call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs)
550 else
551 call assert_true(maparg('K', 'n', 0, 1)->empty())
552 endif
553 endif
554
555 " Shutoff termdebug
556 wincmd t
557 quit!
558 call WaitForAssert({-> assert_equal(1, winnr('$'))})
559 :%bw!
560
561 endfor
562 endfor
563
564 unlet g:termdebug_config
565endfunction
566
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200567" vim: shiftwidth=2 sts=2 expandtab