robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #39598 from zeertzjq/vim-9.1.1756e4876d8126

master
21.3 KiB664 linesraw
1" Test for the termdebug plugin
2
3source shared.vim
4source check.vim
5
6CheckUnix
7" CheckFeature terminal
8CheckExecutable gdb
9CheckExecutable gcc
10
11func s:TryAssert(assert)
12  let res = 1
13  try
14    let res = a:assert()
15  catch
16    let res = assert_report(v:exception)
17  endtry
18  return res
19endfunc
20
21" Override WaitForAssert() to turn exceptions into test failures, preventing
22" them from aborting a test.
23let s:SaveWaitForAssert = funcref('WaitForAssert')
24func! WaitForAssert(assert, ...)
25  let Assert = a:assert
26  if type(a:assert) == v:t_func
27    let Assert = function('s:TryAssert', [a:assert])
28  endif
29  call call(s:SaveWaitForAssert, [Assert] + a:000)
30endfunc
31
32let g:GDB = exepath('gdb')
33if g:GDB->empty()
34  throw 'Skipped: gdb is not found in $PATH'
35endif
36
37let g:GCC = exepath('gcc')
38if g:GCC->empty()
39  throw 'Skipped: gcc is not found in $PATH'
40endif
41
42function s:generate_files(bin_name)
43  let src_name = a:bin_name .. '.c'
44  let lines =<< trim END
45    #include <stdio.h>
46    #include <stdlib.h>
47
48    int isprime(int n)
49    {
50      if (n <= 1)
51        return 0;
52
53      for (int i = 2; i <= n / 2; i++)
54        if (n % i == 0)
55          return 0;
56
57      return 1;
58    }
59
60    int main(int argc, char *argv[])
61    {
62      int n = 7;
63
64      printf("%d is %s prime\n", n, isprime(n) ? "a" : "not a");
65
66      return 0;
67    }
68  END
69  call writefile(lines, src_name)
70  call system($'{g:GCC} -g -o {a:bin_name} {src_name}')
71endfunction
72
73function s:cleanup_files(bin_name)
74  call delete(a:bin_name)
75  call delete(a:bin_name .. '.c')
76endfunction
77
78packadd termdebug
79
80func s:GetTermdebugFunction(name)
81  for line in execute('scriptnames')->split("\n")
82    if line =~# 'termdebug/plugin/termdebug\.vim$'
83      let sid = matchstr(line, '^\s*\zs\d\+')
84      return function('<SNR>' .. sid .. '_' .. a:name)
85    endif
86  endfor
87  throw 'termdebug script not found'
88endfunc
89
90func Test_termdebug_break_command_builder()
91  let bin_name = 'XTD_break_cmd'
92  let src_name = bin_name .. '.c'
93  let BuildBreakpointCommand = s:GetTermdebugFunction('BuildBreakpointCommand')
94  call s:generate_files(bin_name)
95
96  execute 'edit ' .. src_name
97  call cursor(22, 1)
98  let here = '"' .. fnamemodify(src_name, ':p') .. ':22"'
99
100  call assert_equal('-break-insert ' .. here, BuildBreakpointCommand('', v:false))
101  call assert_equal('-break-insert -t ' .. here, BuildBreakpointCommand('', v:true))
102  call assert_equal('-break-insert -c "argc == 1" ' .. here,
103        \ BuildBreakpointCommand('if argc == 1', v:false))
104  call assert_equal('-break-insert -p 2 ' .. here,
105        \ BuildBreakpointCommand('thread 2', v:false))
106  call assert_equal('-break-insert -p 2 -c "argc == 1" ' .. here,
107        \ BuildBreakpointCommand('thread 2 if argc == 1', v:false))
108  call assert_equal('-break-insert -p 2 -c "argc == 1" 22',
109        \ BuildBreakpointCommand('22 thread 2 if argc == 1', v:false))
110  call assert_equal('-break-insert -c "argc == 1" 22',
111        \ BuildBreakpointCommand('22 if argc == 1', v:false))
112  call assert_equal('-break-insert -c "é == 1" 断点',
113        \ BuildBreakpointCommand('断点 if é == 1', v:false))
114  call assert_equal('-break-insert -p 2 断点',
115        \ BuildBreakpointCommand('断点 thread 2', v:false))
116  call assert_equal('-break-insert 断点 if',
117        \ BuildBreakpointCommand('断点 if', v:false))
118  call assert_equal('-break-insert 断点 thread 2 if',
119        \ BuildBreakpointCommand('断点 thread 2 if', v:false))
120  call assert_equal('-break-insert foo\ if\ bar',
121        \ BuildBreakpointCommand('foo\ if\ bar', v:false))
122
123  call s:cleanup_files(bin_name)
124  %bw!
125endfunc
126
127func Test_termdebug_break_with_default_location_and_condition()
128  let g:test_is_flaky = 1
129  let bin_name = 'XTD_break_if'
130  let src_name = bin_name .. '.c'
131  call s:generate_files(bin_name)
132
133  execute 'edit ' .. src_name
134  execute 'Termdebug ./' .. bin_name
135  call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
136  call WaitForAssert({-> assert_equal(3, winnr('$'))})
137  let gdb_buf = winbufnr(1)
138  wincmd b
139
140  call cursor(22, 1)
141  Break if argc == 1
142  call Nterm_wait(gdb_buf)
143  redraw!
144  call WaitForAssert({-> assert_equal([
145        \ {'lnum': 22, 'id': 1014, 'name': 'debugBreakpoint1.0',
146        \  'priority': 110, 'group': 'TermDebug'}],
147        \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
148
149  Run
150  call Nterm_wait(gdb_buf, 400)
151  redraw!
152  call WaitForAssert({-> assert_equal([
153        \ {'lnum': 22, 'id': 12, 'name': 'debugPC', 'priority': 110,
154        \  'group': 'TermDebug'},
155        \ {'lnum': 22, 'id': 1014, 'name': 'debugBreakpoint1.0',
156        \  'priority': 110, 'group': 'TermDebug'}],
157        \ sign_getplaced('', #{group: 'TermDebug'})[0].signs->reverse())})
158
159  Continue
160  call Nterm_wait(gdb_buf)
161  wincmd t
162  quit!
163  redraw!
164  call WaitForAssert({-> assert_equal(1, winnr('$'))})
165
166  call s:cleanup_files(bin_name)
167  %bw!
168endfunc
169
170func Test_termdebug_basic()
171  let g:test_is_flaky = 1
172  let bin_name = 'XTD_basic'
173  let src_name = bin_name .. '.c'
174  call s:generate_files(bin_name)
175
176  edit XTD_basic.c
177  Termdebug ./XTD_basic
178  call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
179  call WaitForAssert({-> assert_equal(3, winnr('$'))})
180  let gdb_buf = winbufnr(1)
181  wincmd b
182  Break 9
183  call Nterm_wait(gdb_buf)
184  redraw!
185  call WaitForAssert({-> assert_equal([
186        \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
187        \  'priority': 110, 'group': 'TermDebug'}],
188        \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
189  Run
190  call Nterm_wait(gdb_buf, 400)
191  redraw!
192  call WaitForAssert({-> assert_equal([
193        \ {'lnum': 9, 'id': 12, 'name': 'debugPC', 'priority': 110,
194        \  'group': 'TermDebug'},
195        \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
196        \  'priority': 110, 'group': 'TermDebug'}],
197        \ sign_getplaced('', #{group: 'TermDebug'})[0].signs->reverse())})
198  Finish
199  call Nterm_wait(gdb_buf)
200  redraw!
201  call WaitForAssert({-> assert_equal([
202        \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
203        \  'priority': 110, 'group': 'TermDebug'},
204        \ {'lnum': 20, 'id': 12, 'name': 'debugPC',
205        \  'priority': 110, 'group': 'TermDebug'}],
206        \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
207  Continue
208  call Nterm_wait(gdb_buf)
209
210  let g:termdebug_config = {}
211  let g:termdebug_config['signs'] = ['>1', '>2', '>3']
212  let g:termdebug_config['sign'] = '>>'
213  let g:termdebug_config['sign_decimal'] = 1
214
215  let i = 2
216  while i <= 258
217    Break
218    call Nterm_wait(gdb_buf)
219    if i == 2
220      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint2.0')[0].text, '>2')})
221    endif
222    if i == 3
223      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint3.0')[0].text, '>3')})
224    endif
225    if i == 4
226      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint4.0')[0].text, '>>')})
227    endif
228    if i == 5
229      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint5.0')[0].text, '>>')})
230      unlet g:termdebug_config['sign']
231    endif
232    if i == 6
233      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint6.0')[0].text, '06')})
234    endif
235    if i == 10
236      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint10.0')[0].text, '10')})
237    endif
238    if i == 99
239      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint99.0')[0].text, '99')})
240    endif
241    if i == 100
242      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint100.0')[0].text, '9+')})
243    endif
244    if i == 110
245      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint110.0')[0].text, '9+')})
246      unlet g:termdebug_config
247    endif
248    if i == 128
249      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint128.0')[0].text, '80')})
250    endif
251    if i == 168
252      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint168.0')[0].text, 'A8')})
253    endif
254    if i == 255
255      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint255.0')[0].text, 'FF')})
256    endif
257    if i == 256
258      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint256.0')[0].text, 'F+')})
259    endif
260    if i == 258
261      call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint258.0')[0].text, 'F+')})
262    endif
263    let i += 1
264  endwhile
265
266  let cn = 0
267  " 60 is approx spaceBuffer * 3
268  if winwidth(0) <= 78 + 60
269    Var
270    call assert_equal(winnr('$'), winnr())
271    call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['leaf', 1000], ['leaf', 1003 + cn]]], winlayout())
272    let cn += 1
273    bw!
274    Asm
275    call assert_equal(winnr('$'), winnr())
276    call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['leaf', 1000], ['leaf', 1003 + cn]]], winlayout())
277    let cn += 1
278    bw!
279  endif
280  set columns=160
281  call Nterm_wait(gdb_buf)
282  let winw = winwidth(0)
283  Var
284  if winwidth(0) < winw
285    call assert_equal(winnr('$') - 1, winnr())
286    call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]], winlayout())
287    let cn += 1
288    bw!
289  endif
290  let winw = winwidth(0)
291  Asm
292  if winwidth(0) < winw
293    call assert_equal(winnr('$') - 1, winnr())
294    call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]], winlayout())
295    let cn += 1
296    bw!
297  endif
298  set columns&
299  call Nterm_wait(gdb_buf)
300
301  wincmd t
302  quit!
303  redraw!
304  call WaitForAssert({-> assert_equal(1, winnr('$'))})
305  call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
306
307  for use_prompt in [0, 1]
308    let g:termdebug_config = {}
309    let g:termdebug_config['use_prompt'] = use_prompt
310    TermdebugCommand ./XTD_basic arg args
311    call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
312    call WaitForAssert({-> assert_equal(3, winnr('$'))})
313    wincmd t
314    quit!
315    redraw!
316    call WaitForAssert({-> assert_equal(1, winnr('$'))})
317    unlet g:termdebug_config
318  endfor
319
320  call s:cleanup_files(bin_name)
321  %bw!
322endfunc
323
324func Test_termdebug_tbreak()
325  let g:test_is_flaky = 1
326  let bin_name = 'XTD_tbreak'
327  let src_name = bin_name .. '.c'
328
329  eval s:generate_files(bin_name)
330
331  execute 'edit ' .. src_name
332  execute 'Termdebug ./' .. bin_name
333
334  call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
335  call WaitForAssert({-> assert_equal(3, winnr('$'))})
336  let gdb_buf = winbufnr(1)
337  wincmd b
338
339  let bp_line = 22        " 'return' statement in main
340  let temp_bp_line = 10   " 'if' statement in 'for' loop body
341  execute "Tbreak " .. temp_bp_line
342  execute "Break " .. bp_line
343
344  call Nterm_wait(gdb_buf)
345  redraw!
346  " both temporary and normal breakpoint signs were displayed...
347  call WaitForAssert({-> assert_equal([
348        \ {'lnum': temp_bp_line, 'id': 1014, 'name': 'debugBreakpoint1.0',
349        \  'priority': 110, 'group': 'TermDebug'},
350        \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0',
351        \  'priority': 110, 'group': 'TermDebug'}],
352        \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
353
354  Run
355  call Nterm_wait(gdb_buf, 400)
356  redraw!
357  " debugPC sign is on the line where the temp. bp was set;
358  " temp. bp sign was removed after hit;
359  " normal bp sign is still present
360  call WaitForAssert({-> assert_equal([
361        \ {'lnum': temp_bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110,
362        \  'group': 'TermDebug'},
363        \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0',
364        \  'priority': 110, 'group': 'TermDebug'}],
365        \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
366
367  Continue
368  call Nterm_wait(gdb_buf)
369  redraw!
370  " debugPC is on the normal breakpoint,
371  " temp. bp on line 10 was only hit once
372  call WaitForAssert({-> assert_equal([
373        \ {'lnum': bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110,
374        \  'group': 'TermDebug'},
375        \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0',
376        \  'priority': 110, 'group': 'TermDebug'}],
377        \ sign_getplaced('', #{group: 'TermDebug'})[0].signs->reverse())})
378
379  wincmd t
380  quit!
381  redraw!
382  call WaitForAssert({-> assert_equal(1, winnr('$'))})
383  call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
384
385  eval s:cleanup_files(bin_name)
386  %bw!
387endfunc
388
389func Test_termdebug_mapping()
390  %bw!
391  call assert_true(maparg('K', 'n', 0, 1)->empty())
392  call assert_true(maparg('-', 'n', 0, 1)->empty())
393  call assert_true(maparg('+', 'n', 0, 1)->empty())
394  Termdebug
395  call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
396  call WaitForAssert({-> assert_equal(3, winnr('$'))})
397  wincmd b
398  call assert_false(maparg('K', 'n', 0, 1)->empty())
399  call assert_false(maparg('-', 'n', 0, 1)->empty())
400  call assert_false(maparg('+', 'n', 0, 1)->empty())
401  call assert_false(maparg('K', 'n', 0, 1).buffer)
402  call assert_false(maparg('-', 'n', 0, 1).buffer)
403  call assert_false(maparg('+', 'n', 0, 1).buffer)
404  call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs)
405  wincmd t
406  quit!
407  redraw!
408  call WaitForAssert({-> assert_equal(1, winnr('$'))})
409  call assert_true(maparg('K', 'n', 0, 1)->empty())
410  call assert_true(maparg('-', 'n', 0, 1)->empty())
411  call assert_true(maparg('+', 'n', 0, 1)->empty())
412
413  %bw!
414  nnoremap K :echom "K"<cr>
415  nnoremap - :echom "-"<cr>
416  nnoremap + :echom "+"<cr>
417  Termdebug
418  call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
419  call WaitForAssert({-> assert_equal(3, winnr('$'))})
420  wincmd b
421  call assert_false(maparg('K', 'n', 0, 1)->empty())
422  call assert_false(maparg('-', 'n', 0, 1)->empty())
423  call assert_false(maparg('+', 'n', 0, 1)->empty())
424  call assert_false(maparg('K', 'n', 0, 1).buffer)
425  call assert_false(maparg('-', 'n', 0, 1).buffer)
426  call assert_false(maparg('+', 'n', 0, 1).buffer)
427  call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs)
428  wincmd t
429  quit!
430  redraw!
431  call WaitForAssert({-> assert_equal(1, winnr('$'))})
432  call assert_false(maparg('K', 'n', 0, 1)->empty())
433  call assert_false(maparg('-', 'n', 0, 1)->empty())
434  call assert_false(maparg('+', 'n', 0, 1)->empty())
435  call assert_false(maparg('K', 'n', 0, 1).buffer)
436  call assert_false(maparg('-', 'n', 0, 1).buffer)
437  call assert_false(maparg('+', 'n', 0, 1).buffer)
438  call assert_equal(':echom "K"<cr>', maparg('K', 'n', 0, 1).rhs)
439
440  %bw!
441
442  " -- Test that local-buffer mappings are restored in the correct buffers --
443  " local mappings for foo
444  file foo
445  nnoremap <buffer> K :echom "bK"<cr>
446  nnoremap <buffer> - :echom "b-"<cr>
447  nnoremap <buffer> + :echom "b+"<cr>
448
449  " no mappings for 'bar'
450  enew
451  file bar
452
453  " Start termdebug from foo
454  buffer foo
455  Termdebug
456  call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
457  call WaitForAssert({-> assert_equal(3, winnr('$'))})
458  wincmd b
459  call assert_true(maparg('K', 'n', 0, 1).buffer)
460  call assert_true(maparg('-', 'n', 0, 1).buffer)
461  call assert_true(maparg('+', 'n', 0, 1).buffer)
462  call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
463
464  Source
465  buffer bar
466  call assert_false(maparg('K', 'n', 0, 1)->empty())
467  call assert_false(maparg('-', 'n', 0, 1)->empty())
468  call assert_false(maparg('+', 'n', 0, 1)->empty())
469  call assert_true(maparg('K', 'n', 0, 1).buffer->empty())
470  call assert_true(maparg('-', 'n', 0, 1).buffer->empty())
471  call assert_true(maparg('+', 'n', 0, 1).buffer->empty())
472  wincmd t
473  quit!
474  redraw!
475  call WaitForAssert({-> assert_equal(1, winnr('$'))})
476
477  " Termdebug session ended. Buffer 'bar' shall have no mappings
478  call assert_true(bufname() ==# 'bar')
479  call assert_false(maparg('K', 'n', 0, 1)->empty())
480  call assert_false(maparg('-', 'n', 0, 1)->empty())
481  call assert_false(maparg('+', 'n', 0, 1)->empty())
482  call assert_true(maparg('K', 'n', 0, 1).buffer->empty())
483  call assert_true(maparg('-', 'n', 0, 1).buffer->empty())
484  call assert_true(maparg('+', 'n', 0, 1).buffer->empty())
485
486  " Buffer 'foo' shall have the same mapping as before running the termdebug
487  " session
488  buffer foo
489  call assert_true(bufname() ==# 'foo')
490  call assert_true(maparg('K', 'n', 0, 1).buffer)
491  call assert_true(maparg('-', 'n', 0, 1).buffer)
492  call assert_true(maparg('+', 'n', 0, 1).buffer)
493  call assert_equal(':echom "bK"<cr>', maparg('K', 'n', 0, 1).rhs)
494
495  nunmap K
496  nunmap +
497  nunmap -
498  %bw!
499endfunc
500
501func Test_termdebug_bufnames()
502  " Test if user has filename/folders named gdb, Termdebug-gdb-console,
503  " etc. in the current directory
504  let g:termdebug_config = {}
505  let g:termdebug_config['use_prompt'] = 1
506  let filename = 'gdb'
507  let replacement_filename = 'Termdebug-gdb-console'
508
509  call writefile(['This', 'is', 'a', 'test'], filename, 'D')
510  " Throw away the file once the test has done.
511  Termdebug
512  " Once termdebug has completed the startup you should have 3 windows on screen
513  call WaitForAssert({-> assert_equal(3, winnr('$'))})
514  " A file named filename already exists in the working directory,
515  " hence you must call the newly created buffer differently
516  call WaitForAssert({-> assert_false(bufexists(filename))})
517  call WaitForAssert({-> assert_true(bufexists(replacement_filename))})
518  quit!
519  call WaitForAssert({-> assert_equal(1, winnr('$'))})
520
521  " Check if error message is in :message
522  let g:termdebug_config['disasm_window'] = 1
523  let filename = 'Termdebug-asm-listing'
524  call writefile(['This', 'is', 'a', 'test'], filename, 'D')
525  " Check only the head of the error message
526  let error_message = "You have a file/folder named '" .. filename .. "'"
527  Termdebug
528  " Once termdebug has completed the startup you should have 4 windows on screen
529  call WaitForAssert({-> assert_equal(4, winnr('$'))})
530  call WaitForAssert({-> assert_notequal(-1, stridx(execute('messages'), error_message))})
531  quit!
532  wincmd b
533  wincmd q
534  call WaitForAssert({-> assert_equal(1, winnr('$'))})
535
536  unlet g:termdebug_config
537endfunc
538
539function Test_termdebug_save_restore_variables()
540  " saved mousemodel
541  "let &mousemodel=''
542  let &mousemodel='extend'
543
544  " saved keys
545  nnoremap K :echo "hello world!"<cr>
546  let expected_map_K = maparg('K', 'n', 0 , 1)
547  nnoremap + :echo "hello plus!"<cr>
548  let expected_map_plus = maparg('+', 'n', 0 , 1)
549  let expected_map_minus = {}
550
551  " saved &columns
552  let expected_columns = &columns
553
554  " We want termdebug to overwrite 'K' map but not '+' map.
555  let g:termdebug_config = {}
556  let g:termdebug_config['map_K'] = 1
557
558  Termdebug
559  call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
560  call WaitForAssert({-> assert_equal(3, winnr('$'))})
561  call WaitForAssert({-> assert_match(&mousemodel, 'popup_setpos')})
562  wincmd t
563  quit!
564  call WaitForAssert({-> assert_equal(1, winnr('$'))})
565
566  "call assert_true(empty(&mousemodel))
567  call assert_equal(&mousemodel, 'extend')
568
569  call assert_true(empty(expected_map_minus))
570  call assert_equal(expected_map_K.rhs, maparg('K', 'n', 0, 1).rhs)
571  call assert_equal(expected_map_plus.rhs, maparg('+', 'n', 0, 1).rhs)
572
573  call assert_equal(expected_columns, &columns)
574
575  nunmap K
576  nunmap +
577  unlet g:termdebug_config
578endfunction
579
580
581func Test_termdebug_toggle_break()
582  let g:test_is_flaky = 1
583  let bin_name = 'XTD_tbreak'
584  let src_name = bin_name .. '.c'
585
586  eval s:generate_files(bin_name)
587
588  execute 'edit ' .. src_name
589  execute 'Termdebug ./' .. bin_name
590
591  call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
592  call WaitForAssert({-> assert_equal(3, winnr('$'))})
593  let gdb_buf = winbufnr(1)
594  wincmd b
595
596  let bp_line = 22        " 'return' statement in main
597  execute "normal! " .. bp_line .. "G"
598  execute "ToggleBreak"
599
600  call Nterm_wait(gdb_buf)
601  redraw!
602  call WaitForAssert({-> assert_equal([
603        \ {'lnum': bp_line, 'id': 1014, 'name': 'debugBreakpoint1.0',
604        \  'priority': 110, 'group': 'TermDebug'}],
605        \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
606
607  RunOrContinue
608  call Nterm_wait(gdb_buf, 400)
609  redraw!
610  call WaitForAssert({-> assert_equal([
611        \ {'lnum': bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110,
612        \  'group': 'TermDebug'},
613        \ {'lnum': bp_line, 'id': 1014, 'name': 'debugBreakpoint1.0',
614        \  'priority': 110, 'group': 'TermDebug'}],
615        \ sign_getplaced('', #{group: 'TermDebug'})[0].signs->reverse())})
616
617  " Add one break point
618  execute "normal! " .. bp_line .. "G"
619  execute "ToggleBreak"
620  call Nterm_wait(gdb_buf)
621  redraw!
622  call WaitForAssert({-> assert_equal([
623        \ {'lnum': bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110,
624        \  'group': 'TermDebug'}],
625        \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
626
627  " Remove one break point
628  execute "normal! " .. bp_line .. "G"
629  execute "ToggleBreak"
630  call Nterm_wait(gdb_buf)
631  redraw!
632  call WaitForAssert({-> assert_equal([
633        \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0',
634        \  'priority': 110, 'group': 'TermDebug'},
635        \ {'lnum': bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110,
636        \  'group': 'TermDebug'}],
637        \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
638
639  " Remove multiple break points
640  execute "Break"
641  execute "Break"
642  execute "Break"
643  execute "Break"
644  call Nterm_wait(gdb_buf, 400)
645  execute "ToggleBreak"
646  call Nterm_wait(gdb_buf)
647  redraw!
648  call WaitForAssert({-> assert_equal([
649        \ {'lnum': bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110,
650        \  'group': 'TermDebug'}],
651        \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
652
653
654  wincmd t
655  quit!
656  redraw!
657  call WaitForAssert({-> assert_equal(1, winnr('$'))})
658  call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
659
660  eval s:cleanup_files(bin_name)
661  %bw!
662endfunc
663
664" vim: shiftwidth=2 sts=2 expandtab