blob: eba2a617627cf565e0463e8f9977cb4e08cd8aff [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
21packadd termdebug
22
23func Test_termdebug_basic()
24 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
49 call writefile(lines, 'XTD_basic.c', 'D')
50 call system($'{g:GCC} -g -o XTD_basic XTD_basic.c')
51
52 edit XTD_basic.c
53 Termdebug ./XTD_basic
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020054 call WaitForAssert({-> assert_equal(3, winnr('$'))})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020055 let gdb_buf = winbufnr(1)
56 wincmd b
57 Break 9
58 call term_wait(gdb_buf)
59 redraw!
60 call assert_equal([
61 \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
62 \ 'priority': 110, 'group': 'TermDebug'}],
63 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)
64 Run
Christian Brabandt6c93c942023-08-27 21:48:29 +020065 call term_wait(gdb_buf, 400)
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020066 redraw!
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020067 call WaitForAssert({-> assert_equal([
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020068 \ {'lnum': 9, 'id': 12, 'name': 'debugPC', 'priority': 110,
69 \ 'group': 'TermDebug'},
70 \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
71 \ 'priority': 110, 'group': 'TermDebug'}],
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020072 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020073 Finish
74 call term_wait(gdb_buf)
75 redraw!
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020076 call WaitForAssert({-> assert_equal([
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020077 \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
78 \ 'priority': 110, 'group': 'TermDebug'},
79 \ {'lnum': 20, 'id': 12, 'name': 'debugPC',
80 \ 'priority': 110, 'group': 'TermDebug'}],
Yegappan Lakshmanan85c3a5b2023-08-27 21:59:54 +020081 \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +020082 Continue
83 wincmd t
84 quit!
85 redraw!
86 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
87
88 call delete('XTD_basic')
89 %bw!
90endfunc
91
92" vim: shiftwidth=2 sts=2 expandtab