blob: 70e11873f9fc89587f6ccf6c194e52de1319f684 [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-Qian2dd613f2023-11-12 23:53:39 +080083 call term_wait(gdb_buf)
84
85 let i = 2
86 while i <= 258
87 Break
88 call term_wait(gdb_buf)
89 if i == 2
90 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint2.0')[0].text, '02')})
91 endif
92 if i == 10
93 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint10.0')[0].text, '0A')})
94 endif
95 if i == 168
96 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint168.0')[0].text, 'A8')})
97 endif
98 if i == 255
99 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint255.0')[0].text, 'FF')})
100 endif
101 if i == 256
102 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint256.0')[0].text, 'F+')})
103 endif
104 if i == 258
105 call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint258.0')[0].text, 'F+')})
106 endif
107 let i += 1
108 endwhile
shane.xb.qianca482022023-11-08 21:59:15 +0100109
110 let cn = 0
111 " 60 is approx spaceBuffer * 3
112 if winwidth(0) <= 78 + 60
113 Var
114 call assert_equal(winnr(), winnr('$'))
115 call assert_equal(winlayout(), ['col', [['leaf', 1002], ['leaf', 1001], ['leaf', 1000], ['leaf', 1003 + cn]]])
116 let cn += 1
117 bw!
118 Asm
119 call assert_equal(winnr(), winnr('$'))
120 call assert_equal(winlayout(), ['col', [['leaf', 1002], ['leaf', 1001], ['leaf', 1000], ['leaf', 1003 + cn]]])
121 let cn += 1
122 bw!
123 endif
124 set columns=160
shane.xb.qianfdbadea2023-11-12 09:42:12 +0100125 call term_wait(gdb_buf)
Christian Brabandt305127f2023-11-11 18:59:33 +0100126 let winw = winwidth(0)
shane.xb.qianca482022023-11-08 21:59:15 +0100127 Var
Christian Brabandt305127f2023-11-11 18:59:33 +0100128 if winwidth(0) < winw
129 call assert_equal(winnr(), winnr('$') - 1)
130 call assert_equal(winlayout(), ['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]])
131 let cn += 1
132 bw!
133 endif
134 let winw = winwidth(0)
shane.xb.qianca482022023-11-08 21:59:15 +0100135 Asm
Christian Brabandt305127f2023-11-11 18:59:33 +0100136 if winwidth(0) < winw
137 call assert_equal(winnr(), winnr('$') - 1)
138 call assert_equal(winlayout(), ['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]])
139 let cn += 1
140 bw!
141 endif
shane.xb.qianca482022023-11-08 21:59:15 +0100142 set columns&
shane.xb.qianfdbadea2023-11-12 09:42:12 +0100143 call term_wait(gdb_buf)
shane.xb.qianca482022023-11-08 21:59:15 +0100144
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200145 wincmd t
146 quit!
147 redraw!
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100148 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200149 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
150
151 call delete('XTD_basic')
152 %bw!
153endfunc
154
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100155func Test_termdebug_mapping()
156 %bw!
157 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 1)
158 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 1)
159 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 1)
160 Termdebug
161 call WaitForAssert({-> assert_equal(3, winnr('$'))})
162 wincmd b
163 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
164 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
165 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
166 call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
167 call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
168 call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
169 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':Evaluate<CR>')
170 wincmd t
171 quit!
172 redraw!
173 call WaitForAssert({-> assert_equal(1, winnr('$'))})
174 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 1)
175 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 1)
176 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 1)
177
178 %bw!
179 nnoremap K :echom "K"<cr>
180 nnoremap - :echom "-"<cr>
181 nnoremap + :echom "+"<cr>
182 Termdebug
183 call WaitForAssert({-> assert_equal(3, winnr('$'))})
184 wincmd b
185 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
186 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
187 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
188 call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
189 call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
190 call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
191 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':Evaluate<CR>')
192 wincmd t
193 quit!
194 redraw!
195 call WaitForAssert({-> assert_equal(1, winnr('$'))})
196 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
197 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
198 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
199 call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
200 call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
201 call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
202 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "K"<cr>')
203
204 %bw!
205 nnoremap <buffer> K :echom "bK"<cr>
206 nnoremap <buffer> - :echom "b-"<cr>
207 nnoremap <buffer> + :echom "b+"<cr>
208 Termdebug
209 call WaitForAssert({-> assert_equal(3, winnr('$'))})
210 wincmd b
211 call assert_equal(maparg('K', 'n', 0, 1).buffer, 1)
212 call assert_equal(maparg('-', 'n', 0, 1).buffer, 1)
213 call assert_equal(maparg('+', 'n', 0, 1).buffer, 1)
214 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
215 wincmd t
216 quit!
217 redraw!
218 call WaitForAssert({-> assert_equal(1, winnr('$'))})
219 call assert_equal(maparg('K', 'n', 0, 1).buffer, 1)
220 call assert_equal(maparg('-', 'n', 0, 1).buffer, 1)
221 call assert_equal(maparg('+', 'n', 0, 1).buffer, 1)
222 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
223
224 %bw!
225endfunc
226
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200227" vim: shiftwidth=2 sts=2 expandtab