blob: 561dd47a1a3e97138399d2fecf1f80c90e946110 [file] [log] [blame]
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +02001" Test for the termdebug plugin
2
3source check.vim
4
5CheckUnix
6CheckFeature terminal
7CheckExecutable gdb
8CheckExecutable gcc
9
10let g:GDB = exepath('gdb')
11if g:GDB->empty()
Christian Brabandtf2534432023-08-27 19:59:28 +020012 throw 'Skipped: gdb is not found in $PATH'
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020013endif
14
15let g:GCC = exepath('gcc')
16if g:GCC->empty()
Christian Brabandtf2534432023-08-27 19:59:28 +020017 throw 'Skipped: gcc is not found in $PATH'
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020018endif
19
20packadd termdebug
21
22func Test_termdebug_basic()
23 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
48 call writefile(lines, 'XTD_basic.c', 'D')
49 call system($'{g:GCC} -g -o XTD_basic XTD_basic.c')
50
51 edit XTD_basic.c
52 Termdebug ./XTD_basic
53 call assert_equal(3, winnr('$'))
54 let gdb_buf = winbufnr(1)
55 wincmd b
56 Break 9
57 call term_wait(gdb_buf)
58 redraw!
59 call assert_equal([
60 \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
61 \ 'priority': 110, 'group': 'TermDebug'}],
62 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)
63 Run
Christian Brabandt6c93c942023-08-27 21:48:29 +020064 call term_wait(gdb_buf, 400)
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020065 redraw!
66 call assert_equal([
67 \ {'lnum': 9, 'id': 12, 'name': 'debugPC', 'priority': 110,
68 \ 'group': 'TermDebug'},
69 \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
70 \ 'priority': 110, 'group': 'TermDebug'}],
71 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)
72 Finish
73 call term_wait(gdb_buf)
74 redraw!
75 call assert_equal([
76 \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
77 \ 'priority': 110, 'group': 'TermDebug'},
78 \ {'lnum': 20, 'id': 12, 'name': 'debugPC',
79 \ 'priority': 110, 'group': 'TermDebug'}],
80 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)
81 Continue
82 wincmd t
83 quit!
84 redraw!
85 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
86
87 call delete('XTD_basic')
88 %bw!
89endfunc
90
91" vim: shiftwidth=2 sts=2 expandtab