blob: 3b2b8c1afd52e680639705d3546f2f882ce9ce41 [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
shane.xb.qianca482022023-11-08 21:59:15 +010083
84 let cn = 0
85 " 60 is approx spaceBuffer * 3
86 if winwidth(0) <= 78 + 60
87 Var
88 call assert_equal(winnr(), winnr('$'))
89 call assert_equal(winlayout(), ['col', [['leaf', 1002], ['leaf', 1001], ['leaf', 1000], ['leaf', 1003 + cn]]])
90 let cn += 1
91 bw!
92 Asm
93 call assert_equal(winnr(), winnr('$'))
94 call assert_equal(winlayout(), ['col', [['leaf', 1002], ['leaf', 1001], ['leaf', 1000], ['leaf', 1003 + cn]]])
95 let cn += 1
96 bw!
97 endif
98 set columns=160
99 Var
100 call assert_equal(winnr(), winnr('$') - 1)
101 call assert_equal(winlayout(), ['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]])
102 let cn += 1
103 bw!
104 Asm
105 call assert_equal(winnr(), winnr('$') - 1)
106 call assert_equal(winlayout(), ['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]])
107 let cn += 1
108 bw!
109 set columns&
110
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200111 wincmd t
112 quit!
113 redraw!
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100114 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200115 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
116
117 call delete('XTD_basic')
118 %bw!
119endfunc
120
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100121func Test_termdebug_mapping()
122 %bw!
123 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 1)
124 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 1)
125 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 1)
126 Termdebug
127 call WaitForAssert({-> assert_equal(3, winnr('$'))})
128 wincmd b
129 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
130 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
131 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
132 call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
133 call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
134 call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
135 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':Evaluate<CR>')
136 wincmd t
137 quit!
138 redraw!
139 call WaitForAssert({-> assert_equal(1, winnr('$'))})
140 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 1)
141 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 1)
142 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 1)
143
144 %bw!
145 nnoremap K :echom "K"<cr>
146 nnoremap - :echom "-"<cr>
147 nnoremap + :echom "+"<cr>
148 Termdebug
149 call WaitForAssert({-> assert_equal(3, winnr('$'))})
150 wincmd b
151 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
152 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
153 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
154 call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
155 call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
156 call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
157 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':Evaluate<CR>')
158 wincmd t
159 quit!
160 redraw!
161 call WaitForAssert({-> assert_equal(1, winnr('$'))})
162 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
163 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
164 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
165 call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
166 call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
167 call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
168 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "K"<cr>')
169
170 %bw!
171 nnoremap <buffer> K :echom "bK"<cr>
172 nnoremap <buffer> - :echom "b-"<cr>
173 nnoremap <buffer> + :echom "b+"<cr>
174 Termdebug
175 call WaitForAssert({-> assert_equal(3, winnr('$'))})
176 wincmd b
177 call assert_equal(maparg('K', 'n', 0, 1).buffer, 1)
178 call assert_equal(maparg('-', 'n', 0, 1).buffer, 1)
179 call assert_equal(maparg('+', 'n', 0, 1).buffer, 1)
180 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
181 wincmd t
182 quit!
183 redraw!
184 call WaitForAssert({-> assert_equal(1, winnr('$'))})
185 call assert_equal(maparg('K', 'n', 0, 1).buffer, 1)
186 call assert_equal(maparg('-', 'n', 0, 1).buffer, 1)
187 call assert_equal(maparg('+', 'n', 0, 1).buffer, 1)
188 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
189
190 %bw!
191endfunc
192
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200193" vim: shiftwidth=2 sts=2 expandtab