blob: 16de0578039de3bfb87f9f343e6745cd1fa01e4e [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
Christian Brabandt305127f2023-11-11 18:59:33 +010099 let winw = winwidth(0)
shane.xb.qianca482022023-11-08 21:59:15 +0100100 Var
Christian Brabandt305127f2023-11-11 18:59:33 +0100101 if winwidth(0) < winw
102 call assert_equal(winnr(), winnr('$') - 1)
103 call assert_equal(winlayout(), ['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]])
104 let cn += 1
105 bw!
106 endif
107 let winw = winwidth(0)
shane.xb.qianca482022023-11-08 21:59:15 +0100108 Asm
Christian Brabandt305127f2023-11-11 18:59:33 +0100109 if winwidth(0) < winw
110 call assert_equal(winnr(), winnr('$') - 1)
111 call assert_equal(winlayout(), ['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]])
112 let cn += 1
113 bw!
114 endif
shane.xb.qianca482022023-11-08 21:59:15 +0100115 set columns&
116
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200117 wincmd t
118 quit!
119 redraw!
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100120 call WaitForAssert({-> assert_equal(1, winnr('$'))})
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200121 call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
122
123 call delete('XTD_basic')
124 %bw!
125endfunc
126
shane.xb.qian7fbbd7f2023-11-08 21:44:48 +0100127func Test_termdebug_mapping()
128 %bw!
129 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 1)
130 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 1)
131 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 1)
132 Termdebug
133 call WaitForAssert({-> assert_equal(3, winnr('$'))})
134 wincmd b
135 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
136 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
137 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
138 call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
139 call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
140 call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
141 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':Evaluate<CR>')
142 wincmd t
143 quit!
144 redraw!
145 call WaitForAssert({-> assert_equal(1, winnr('$'))})
146 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 1)
147 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 1)
148 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 1)
149
150 %bw!
151 nnoremap K :echom "K"<cr>
152 nnoremap - :echom "-"<cr>
153 nnoremap + :echom "+"<cr>
154 Termdebug
155 call WaitForAssert({-> assert_equal(3, winnr('$'))})
156 wincmd b
157 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
158 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
159 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
160 call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
161 call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
162 call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
163 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':Evaluate<CR>')
164 wincmd t
165 quit!
166 redraw!
167 call WaitForAssert({-> assert_equal(1, winnr('$'))})
168 call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
169 call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
170 call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
171 call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
172 call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
173 call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
174 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "K"<cr>')
175
176 %bw!
177 nnoremap <buffer> K :echom "bK"<cr>
178 nnoremap <buffer> - :echom "b-"<cr>
179 nnoremap <buffer> + :echom "b+"<cr>
180 Termdebug
181 call WaitForAssert({-> assert_equal(3, winnr('$'))})
182 wincmd b
183 call assert_equal(maparg('K', 'n', 0, 1).buffer, 1)
184 call assert_equal(maparg('-', 'n', 0, 1).buffer, 1)
185 call assert_equal(maparg('+', 'n', 0, 1).buffer, 1)
186 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
187 wincmd t
188 quit!
189 redraw!
190 call WaitForAssert({-> assert_equal(1, winnr('$'))})
191 call assert_equal(maparg('K', 'n', 0, 1).buffer, 1)
192 call assert_equal(maparg('-', 'n', 0, 1).buffer, 1)
193 call assert_equal(maparg('+', 'n', 0, 1).buffer, 1)
194 call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
195
196 %bw!
197endfunc
198
Yegappan Lakshmanan58f39d82023-08-27 11:14:44 +0200199" vim: shiftwidth=2 sts=2 expandtab