blob: 5f547c9a3957492848a1408971704e2d5d061035 [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
shane.xb.qianfdbadea2023-11-12 09:42:12 +010099 call term_wait(gdb_buf)
Christian Brabandt305127f2023-11-11 18:59:33 +0100100 let winw = winwidth(0)
shane.xb.qianca482022023-11-08 21:59:15 +0100101 Var
Christian Brabandt305127f2023-11-11 18:59:33 +0100102 if winwidth(0) < winw
103 call assert_equal(winnr(), winnr('$') - 1)
104 call assert_equal(winlayout(), ['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]])
105 let cn += 1
106 bw!
107 endif
108 let winw = winwidth(0)
shane.xb.qianca482022023-11-08 21:59:15 +0100109 Asm
Christian Brabandt305127f2023-11-11 18:59:33 +0100110 if winwidth(0) < winw
111 call assert_equal(winnr(), winnr('$') - 1)
112 call assert_equal(winlayout(), ['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]])
113 let cn += 1
114 bw!
115 endif
shane.xb.qianca482022023-11-08 21:59:15 +0100116 set columns&
shane.xb.qianfdbadea2023-11-12 09:42:12 +0100117 call term_wait(gdb_buf)
shane.xb.qianca482022023-11-08 21:59:15 +0100118
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200119 wincmd t
120 quit!
121 redraw!
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100122 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200123 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
124
125 call delete('XTD_basic')
126 %bw!
127endfunc
128
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100129func Test_termdebug_mapping()
130 %bw!
131 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 1)
132 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 1)
133 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 1)
134 Termdebug
135 call WaitForAssert({-> assert_equal(3, winnr('$'))})
136 wincmd b
137 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
138 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
139 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
140 call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
141 call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
142 call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
143 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':Evaluate<CR>')
144 wincmd t
145 quit!
146 redraw!
147 call WaitForAssert({-> assert_equal(1, winnr('$'))})
148 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 1)
149 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 1)
150 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 1)
151
152 %bw!
153 nnoremap K :echom "K"<cr>
154 nnoremap - :echom "-"<cr>
155 nnoremap + :echom "+"<cr>
156 Termdebug
157 call WaitForAssert({-> assert_equal(3, winnr('$'))})
158 wincmd b
159 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
160 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
161 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
162 call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
163 call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
164 call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
165 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':Evaluate<CR>')
166 wincmd t
167 quit!
168 redraw!
169 call WaitForAssert({-> assert_equal(1, winnr('$'))})
170 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
171 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
172 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
173 call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
174 call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
175 call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
176 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "K"<cr>')
177
178 %bw!
179 nnoremap <buffer> K :echom "bK"<cr>
180 nnoremap <buffer> - :echom "b-"<cr>
181 nnoremap <buffer> + :echom "b+"<cr>
182 Termdebug
183 call WaitForAssert({-> assert_equal(3, winnr('$'))})
184 wincmd b
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 wincmd t
190 quit!
191 redraw!
192 call WaitForAssert({-> assert_equal(1, winnr('$'))})
193 call assert_equal(maparg('K', 'n', 0, 1).buffer, 1)
194 call assert_equal(maparg('-', 'n', 0, 1).buffer, 1)
195 call assert_equal(maparg('+', 'n', 0, 1).buffer, 1)
196 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
197
198 %bw!
199endfunc
200
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200201" vim: shiftwidth=2 sts=2 expandtab