Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 1 | " Test for the termdebug plugin |
| 2 | |
Yegappan Lakshmanan | 85c3a5b | 2023-08-27 21:59:54 +0200 | [diff] [blame] | 3 | source shared.vim |
Peter Wolf | 8f1d098 | 2024-10-27 21:51:14 +0100 | [diff] [blame] | 4 | source screendump.vim |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 5 | source check.vim |
| 6 | |
| 7 | CheckUnix |
| 8 | CheckFeature terminal |
| 9 | CheckExecutable gdb |
| 10 | CheckExecutable gcc |
| 11 | |
| 12 | let g:GDB = exepath('gdb') |
| 13 | if g:GDB->empty() |
Christian Brabandt | f253443 | 2023-08-27 19:59:28 +0200 | [diff] [blame] | 14 | throw 'Skipped: gdb is not found in $PATH' |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 15 | endif |
| 16 | |
| 17 | let g:GCC = exepath('gcc') |
| 18 | if g:GCC->empty() |
Christian Brabandt | f253443 | 2023-08-27 19:59:28 +0200 | [diff] [blame] | 19 | throw 'Skipped: gcc is not found in $PATH' |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 20 | endif |
| 21 | |
iam28th | 323dda1 | 2023-12-14 20:30:26 +0100 | [diff] [blame] | 22 | function s:generate_files(bin_name) |
| 23 | let src_name = a:bin_name .. '.c' |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 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 |
iam28th | 323dda1 | 2023-12-14 20:30:26 +0100 | [diff] [blame] | 49 | call writefile(lines, src_name) |
| 50 | call system($'{g:GCC} -g -o {a:bin_name} {src_name}') |
| 51 | endfunction |
| 52 | |
| 53 | function s:cleanup_files(bin_name) |
| 54 | call delete(a:bin_name) |
| 55 | call delete(a:bin_name .. '.c') |
| 56 | endfunction |
| 57 | |
| 58 | packadd termdebug |
| 59 | |
Ubaldo Tiberi | ae1c8b7 | 2024-11-19 22:32:30 +0100 | [diff] [blame] | 60 | " should be the first test to run, since it validates the window layout with |
| 61 | " win ids |
iam28th | 323dda1 | 2023-12-14 20:30:26 +0100 | [diff] [blame] | 62 | func Test_termdebug_basic() |
Christian Brabandt | ebb08d5 | 2025-01-11 15:43:12 +0100 | [diff] [blame] | 63 | let g:test_is_flaky = 1 |
iam28th | 323dda1 | 2023-12-14 20:30:26 +0100 | [diff] [blame] | 64 | let bin_name = 'XTD_basic' |
| 65 | let src_name = bin_name .. '.c' |
| 66 | call s:generate_files(bin_name) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 67 | |
| 68 | edit XTD_basic.c |
| 69 | Termdebug ./XTD_basic |
Christian Brabandt | 2979cfc | 2024-07-24 21:37:39 +0200 | [diff] [blame] | 70 | call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))}) |
Yegappan Lakshmanan | 85c3a5b | 2023-08-27 21:59:54 +0200 | [diff] [blame] | 71 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 72 | let gdb_buf = winbufnr(1) |
| 73 | wincmd b |
| 74 | Break 9 |
| 75 | call term_wait(gdb_buf) |
| 76 | redraw! |
| 77 | call assert_equal([ |
| 78 | \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0', |
| 79 | \ 'priority': 110, 'group': 'TermDebug'}], |
| 80 | \ sign_getplaced('', #{group: 'TermDebug'})[0].signs) |
| 81 | Run |
Christian Brabandt | 6c93c94 | 2023-08-27 21:48:29 +0200 | [diff] [blame] | 82 | call term_wait(gdb_buf, 400) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 83 | redraw! |
Yegappan Lakshmanan | 85c3a5b | 2023-08-27 21:59:54 +0200 | [diff] [blame] | 84 | call WaitForAssert({-> assert_equal([ |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 85 | \ {'lnum': 9, 'id': 12, 'name': 'debugPC', 'priority': 110, |
| 86 | \ 'group': 'TermDebug'}, |
| 87 | \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0', |
| 88 | \ 'priority': 110, 'group': 'TermDebug'}], |
Yegappan Lakshmanan | 85c3a5b | 2023-08-27 21:59:54 +0200 | [diff] [blame] | 89 | \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)}) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 90 | Finish |
| 91 | call term_wait(gdb_buf) |
| 92 | redraw! |
Yegappan Lakshmanan | 85c3a5b | 2023-08-27 21:59:54 +0200 | [diff] [blame] | 93 | call WaitForAssert({-> assert_equal([ |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 94 | \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0', |
| 95 | \ 'priority': 110, 'group': 'TermDebug'}, |
| 96 | \ {'lnum': 20, 'id': 12, 'name': 'debugPC', |
| 97 | \ 'priority': 110, 'group': 'TermDebug'}], |
Yegappan Lakshmanan | 85c3a5b | 2023-08-27 21:59:54 +0200 | [diff] [blame] | 98 | \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)}) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 99 | Continue |
Shane-XB-Qian | 2dd613f | 2023-11-12 23:53:39 +0800 | [diff] [blame] | 100 | call term_wait(gdb_buf) |
| 101 | |
| 102 | let i = 2 |
| 103 | while i <= 258 |
| 104 | Break |
| 105 | call term_wait(gdb_buf) |
| 106 | if i == 2 |
| 107 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint2.0')[0].text, '02')}) |
| 108 | endif |
| 109 | if i == 10 |
| 110 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint10.0')[0].text, '0A')}) |
| 111 | endif |
| 112 | if i == 168 |
| 113 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint168.0')[0].text, 'A8')}) |
| 114 | endif |
| 115 | if i == 255 |
| 116 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint255.0')[0].text, 'FF')}) |
| 117 | endif |
| 118 | if i == 256 |
| 119 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint256.0')[0].text, 'F+')}) |
| 120 | endif |
| 121 | if i == 258 |
| 122 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint258.0')[0].text, 'F+')}) |
| 123 | endif |
| 124 | let i += 1 |
| 125 | endwhile |
shane.xb.qian | ca48202 | 2023-11-08 21:59:15 +0100 | [diff] [blame] | 126 | |
| 127 | let cn = 0 |
| 128 | " 60 is approx spaceBuffer * 3 |
| 129 | if winwidth(0) <= 78 + 60 |
| 130 | Var |
zeertzjq | aef6179 | 2024-07-18 20:35:42 +0200 | [diff] [blame] | 131 | call assert_equal(winnr('$'), winnr()) |
| 132 | call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['leaf', 1000], ['leaf', 1003 + cn]]], winlayout()) |
shane.xb.qian | ca48202 | 2023-11-08 21:59:15 +0100 | [diff] [blame] | 133 | let cn += 1 |
| 134 | bw! |
| 135 | Asm |
zeertzjq | aef6179 | 2024-07-18 20:35:42 +0200 | [diff] [blame] | 136 | call assert_equal(winnr('$'), winnr()) |
| 137 | call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['leaf', 1000], ['leaf', 1003 + cn]]], winlayout()) |
shane.xb.qian | ca48202 | 2023-11-08 21:59:15 +0100 | [diff] [blame] | 138 | let cn += 1 |
| 139 | bw! |
| 140 | endif |
| 141 | set columns=160 |
shane.xb.qian | fdbadea | 2023-11-12 09:42:12 +0100 | [diff] [blame] | 142 | call term_wait(gdb_buf) |
Christian Brabandt | 305127f | 2023-11-11 18:59:33 +0100 | [diff] [blame] | 143 | let winw = winwidth(0) |
shane.xb.qian | ca48202 | 2023-11-08 21:59:15 +0100 | [diff] [blame] | 144 | Var |
Christian Brabandt | 305127f | 2023-11-11 18:59:33 +0100 | [diff] [blame] | 145 | if winwidth(0) < winw |
zeertzjq | aef6179 | 2024-07-18 20:35:42 +0200 | [diff] [blame] | 146 | call assert_equal(winnr('$') - 1, winnr()) |
| 147 | call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]], winlayout()) |
Christian Brabandt | 305127f | 2023-11-11 18:59:33 +0100 | [diff] [blame] | 148 | let cn += 1 |
| 149 | bw! |
| 150 | endif |
| 151 | let winw = winwidth(0) |
shane.xb.qian | ca48202 | 2023-11-08 21:59:15 +0100 | [diff] [blame] | 152 | Asm |
Christian Brabandt | 305127f | 2023-11-11 18:59:33 +0100 | [diff] [blame] | 153 | if winwidth(0) < winw |
zeertzjq | aef6179 | 2024-07-18 20:35:42 +0200 | [diff] [blame] | 154 | call assert_equal(winnr('$') - 1, winnr()) |
| 155 | call assert_equal(['col', [['leaf', 1002], ['leaf', 1001], ['row', [['leaf', 1003 + cn], ['leaf', 1000]]]]], winlayout()) |
Christian Brabandt | 305127f | 2023-11-11 18:59:33 +0100 | [diff] [blame] | 156 | let cn += 1 |
| 157 | bw! |
| 158 | endif |
shane.xb.qian | ca48202 | 2023-11-08 21:59:15 +0100 | [diff] [blame] | 159 | set columns& |
shane.xb.qian | fdbadea | 2023-11-12 09:42:12 +0100 | [diff] [blame] | 160 | call term_wait(gdb_buf) |
shane.xb.qian | ca48202 | 2023-11-08 21:59:15 +0100 | [diff] [blame] | 161 | |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 162 | wincmd t |
| 163 | quit! |
| 164 | redraw! |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 165 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 166 | call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs) |
| 167 | |
Ubaldo Tiberi | a90b0b4 | 2024-07-20 12:00:44 +0200 | [diff] [blame] | 168 | for use_prompt in [v:true, v:false] |
zeertzjq | aef6179 | 2024-07-18 20:35:42 +0200 | [diff] [blame] | 169 | let g:termdebug_config = {} |
| 170 | let g:termdebug_config['use_prompt'] = use_prompt |
| 171 | TermdebugCommand ./XTD_basic arg args |
Christian Brabandt | 2979cfc | 2024-07-24 21:37:39 +0200 | [diff] [blame] | 172 | call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))}) |
zeertzjq | aef6179 | 2024-07-18 20:35:42 +0200 | [diff] [blame] | 173 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 174 | wincmd t |
| 175 | quit! |
| 176 | redraw! |
| 177 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
| 178 | unlet g:termdebug_config |
| 179 | endfor |
| 180 | |
iam28th | 323dda1 | 2023-12-14 20:30:26 +0100 | [diff] [blame] | 181 | call s:cleanup_files(bin_name) |
| 182 | %bw! |
| 183 | endfunc |
| 184 | |
Ubaldo Tiberi | b5c1557 | 2024-11-19 21:10:24 +0100 | [diff] [blame] | 185 | func Test_termdebug_decimal_breakpoints() |
| 186 | let bin_name = 'XTD_decimal' |
| 187 | let src_name = bin_name .. '.c' |
| 188 | call s:generate_files(bin_name) |
| 189 | |
| 190 | exe "edit " .. src_name |
| 191 | |
| 192 | let g:termdebug_config = {} |
| 193 | let g:termdebug_config['sign_decimal'] = 1 |
| 194 | |
| 195 | exe "Termdebug " .. bin_name |
| 196 | call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))}) |
| 197 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 198 | let gdb_buf = winbufnr(1) |
| 199 | wincmd b |
| 200 | Break 9 |
| 201 | call term_wait(gdb_buf) |
| 202 | redraw! |
| 203 | |
| 204 | let i = 2 |
| 205 | while i <= 258 |
| 206 | Break |
| 207 | call term_wait(gdb_buf) |
| 208 | if i == 2 |
| 209 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint2.0')[0].text, '02')}) |
| 210 | endif |
| 211 | if i == 10 |
| 212 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint10.0')[0].text, '10')}) |
| 213 | endif |
| 214 | if i == 168 |
| 215 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint168.0')[0].text, '9+')}) |
| 216 | endif |
| 217 | if i == 255 |
| 218 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint255.0')[0].text, '9+')}) |
| 219 | endif |
| 220 | if i == 256 |
| 221 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint256.0')[0].text, '9+')}) |
| 222 | endif |
| 223 | if i == 258 |
| 224 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint258.0')[0].text, '9+')}) |
| 225 | endif |
| 226 | let i += 1 |
| 227 | endwhile |
| 228 | |
| 229 | wincmd t |
| 230 | quit! |
| 231 | redraw! |
| 232 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
| 233 | call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs) |
| 234 | |
| 235 | call s:cleanup_files(bin_name) |
| 236 | %bw! |
| 237 | |
| 238 | unlet g:termdebug_config |
| 239 | endfunc |
| 240 | |
iam28th | 323dda1 | 2023-12-14 20:30:26 +0100 | [diff] [blame] | 241 | func Test_termdebug_tbreak() |
| 242 | let g:test_is_flaky = 1 |
| 243 | let bin_name = 'XTD_tbreak' |
| 244 | let src_name = bin_name .. '.c' |
| 245 | |
| 246 | eval s:generate_files(bin_name) |
| 247 | |
| 248 | execute 'edit ' .. src_name |
| 249 | execute 'Termdebug ./' .. bin_name |
| 250 | |
Christian Brabandt | 2979cfc | 2024-07-24 21:37:39 +0200 | [diff] [blame] | 251 | call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))}) |
iam28th | 323dda1 | 2023-12-14 20:30:26 +0100 | [diff] [blame] | 252 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 253 | let gdb_buf = winbufnr(1) |
| 254 | wincmd b |
| 255 | |
| 256 | let bp_line = 22 " 'return' statement in main |
| 257 | let temp_bp_line = 10 " 'if' statement in 'for' loop body |
| 258 | execute "Tbreak " .. temp_bp_line |
| 259 | execute "Break " .. bp_line |
| 260 | |
| 261 | call term_wait(gdb_buf) |
| 262 | redraw! |
| 263 | " both temporary and normal breakpoint signs were displayed... |
| 264 | call assert_equal([ |
| 265 | \ {'lnum': temp_bp_line, 'id': 1014, 'name': 'debugBreakpoint1.0', |
| 266 | \ 'priority': 110, 'group': 'TermDebug'}, |
| 267 | \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0', |
| 268 | \ 'priority': 110, 'group': 'TermDebug'}], |
| 269 | \ sign_getplaced('', #{group: 'TermDebug'})[0].signs) |
| 270 | |
| 271 | Run |
| 272 | call term_wait(gdb_buf, 400) |
| 273 | redraw! |
| 274 | " debugPC sign is on the line where the temp. bp was set; |
| 275 | " temp. bp sign was removed after hit; |
| 276 | " normal bp sign is still present |
| 277 | call WaitForAssert({-> assert_equal([ |
| 278 | \ {'lnum': temp_bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110, |
| 279 | \ 'group': 'TermDebug'}, |
| 280 | \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0', |
| 281 | \ 'priority': 110, 'group': 'TermDebug'}], |
| 282 | \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)}) |
| 283 | |
| 284 | Continue |
| 285 | call term_wait(gdb_buf) |
| 286 | redraw! |
| 287 | " debugPC is on the normal breakpoint, |
| 288 | " temp. bp on line 10 was only hit once |
| 289 | call WaitForAssert({-> assert_equal([ |
| 290 | \ {'lnum': bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110, |
| 291 | \ 'group': 'TermDebug'}, |
| 292 | \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0', |
| 293 | \ 'priority': 110, 'group': 'TermDebug'}], |
| 294 | \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)}) |
| 295 | |
| 296 | wincmd t |
| 297 | quit! |
| 298 | redraw! |
| 299 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
| 300 | call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs) |
| 301 | |
| 302 | eval s:cleanup_files(bin_name) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 303 | %bw! |
| 304 | endfunc |
| 305 | |
Peter Wolf | 8f1d098 | 2024-10-27 21:51:14 +0100 | [diff] [blame] | 306 | func Test_termdebug_evaluate() |
| 307 | let bin_name = 'XTD_evaluate' |
| 308 | let src_name = bin_name .. '.c' |
| 309 | call s:generate_files(bin_name) |
| 310 | |
| 311 | edit XTD_evaluate.c |
| 312 | Termdebug ./XTD_evaluate |
| 313 | call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))}) |
| 314 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 315 | let gdb_buf = winbufnr(1) |
| 316 | wincmd b |
| 317 | |
| 318 | " return stmt in main |
| 319 | Break 22 |
| 320 | call term_wait(gdb_buf) |
| 321 | Run |
| 322 | call term_wait(gdb_buf, 400) |
| 323 | redraw! |
| 324 | |
| 325 | " Evaluate an expression |
| 326 | Evaluate n |
| 327 | call term_wait(gdb_buf) |
| 328 | call assert_equal(execute('1messages')->trim(), '"n": 7') |
| 329 | Evaluate argc |
| 330 | call term_wait(gdb_buf) |
| 331 | call assert_equal(execute('1messages')->trim(), '"argc": 1') |
| 332 | Evaluate isprime(n) |
| 333 | call term_wait(gdb_buf) |
| 334 | call assert_equal(execute('1messages')->trim(), '"isprime(n)": 1') |
| 335 | |
| 336 | wincmd t |
| 337 | quit! |
| 338 | redraw! |
| 339 | call s:cleanup_files(bin_name) |
| 340 | %bw! |
| 341 | endfunc |
| 342 | |
| 343 | func Test_termdebug_evaluate_in_popup() |
| 344 | CheckScreendump |
| 345 | let bin_name = 'XTD_evaluate_in_popup' |
| 346 | let src_name = bin_name .. '.c' |
| 347 | let code =<< trim END |
| 348 | struct Point { |
| 349 | int x; |
| 350 | int y; |
| 351 | }; |
| 352 | |
| 353 | int main(int argc, char* argv[]) { |
| 354 | struct Point p = {argc, 2}; |
| 355 | struct Point* p_ptr = &p; |
| 356 | return 0; |
| 357 | } |
| 358 | END |
| 359 | call writefile(code, src_name, 'D') |
| 360 | call system($'{g:GCC} -g -o {bin_name} {src_name}') |
| 361 | |
| 362 | let lines =<< trim END |
| 363 | edit XTD_evaluate_in_popup.c |
| 364 | packadd termdebug |
| 365 | let g:termdebug_config = {} |
| 366 | let g:termdebug_config['evaluate_in_popup'] = v:true |
| 367 | Termdebug ./XTD_evaluate_in_popup |
| 368 | wincmd b |
| 369 | Break 9 |
| 370 | Run |
| 371 | END |
| 372 | |
| 373 | call writefile(lines, 'Xscript', 'D') |
| 374 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 375 | call TermWait(buf, 400) |
| 376 | |
| 377 | call term_sendkeys(buf, ":Evaluate p\<CR>") |
| 378 | call TermWait(buf, 400) |
| 379 | call VerifyScreenDump(buf, 'Test_termdebug_evaluate_in_popup_01', {}) |
| 380 | |
| 381 | call term_sendkeys(buf, ":Evaluate p_ptr\<CR>") |
| 382 | call TermWait(buf, 400) |
| 383 | call VerifyScreenDump(buf, 'Test_termdebug_evaluate_in_popup_02', {}) |
| 384 | |
| 385 | " Cleanup |
| 386 | call term_sendkeys(buf, ":Gdb") |
| 387 | call term_sendkeys(buf, ":quit!\<CR>") |
| 388 | call term_sendkeys(buf, ":qa!\<CR>") |
| 389 | call StopVimInTerminal(buf) |
| 390 | call delete(bin_name) |
| 391 | %bw! |
| 392 | endfunc |
| 393 | |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 394 | func Test_termdebug_mapping() |
| 395 | %bw! |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 396 | call assert_true(maparg('K', 'n', 0, 1)->empty()) |
| 397 | call assert_true(maparg('-', 'n', 0, 1)->empty()) |
| 398 | call assert_true(maparg('+', 'n', 0, 1)->empty()) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 399 | Termdebug |
Christian Brabandt | 2979cfc | 2024-07-24 21:37:39 +0200 | [diff] [blame] | 400 | call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))}) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 401 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 402 | wincmd b |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 403 | call assert_false(maparg('K', 'n', 0, 1)->empty()) |
| 404 | call assert_false(maparg('-', 'n', 0, 1)->empty()) |
| 405 | call assert_false(maparg('+', 'n', 0, 1)->empty()) |
| 406 | call assert_false(maparg('K', 'n', 0, 1).buffer) |
| 407 | call assert_false(maparg('-', 'n', 0, 1).buffer) |
| 408 | call assert_false(maparg('+', 'n', 0, 1).buffer) |
| 409 | call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 410 | wincmd t |
| 411 | quit! |
| 412 | redraw! |
| 413 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 414 | call assert_true(maparg('K', 'n', 0, 1)->empty()) |
| 415 | call assert_true(maparg('-', 'n', 0, 1)->empty()) |
| 416 | call assert_true(maparg('+', 'n', 0, 1)->empty()) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 417 | |
| 418 | %bw! |
| 419 | nnoremap K :echom "K"<cr> |
| 420 | nnoremap - :echom "-"<cr> |
| 421 | nnoremap + :echom "+"<cr> |
| 422 | Termdebug |
Christian Brabandt | 2979cfc | 2024-07-24 21:37:39 +0200 | [diff] [blame] | 423 | call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))}) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 424 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 425 | wincmd b |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 426 | call assert_false(maparg('K', 'n', 0, 1)->empty()) |
| 427 | call assert_false(maparg('-', 'n', 0, 1)->empty()) |
| 428 | call assert_false(maparg('+', 'n', 0, 1)->empty()) |
| 429 | call assert_false(maparg('K', 'n', 0, 1).buffer) |
| 430 | call assert_false(maparg('-', 'n', 0, 1).buffer) |
| 431 | call assert_false(maparg('+', 'n', 0, 1).buffer) |
| 432 | call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 433 | wincmd t |
| 434 | quit! |
| 435 | redraw! |
| 436 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 437 | call assert_false(maparg('K', 'n', 0, 1)->empty()) |
| 438 | call assert_false(maparg('-', 'n', 0, 1)->empty()) |
| 439 | call assert_false(maparg('+', 'n', 0, 1)->empty()) |
| 440 | call assert_false(maparg('K', 'n', 0, 1).buffer) |
| 441 | call assert_false(maparg('-', 'n', 0, 1).buffer) |
| 442 | call assert_false(maparg('+', 'n', 0, 1).buffer) |
| 443 | call assert_equal(':echom "K"<cr>', maparg('K', 'n', 0, 1).rhs) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 444 | |
| 445 | %bw! |
Ubaldo Tiberi | 46f2823 | 2024-06-19 19:50:32 +0200 | [diff] [blame] | 446 | |
| 447 | " -- Test that local-buffer mappings are restored in the correct buffers -- |
| 448 | " local mappings for foo |
| 449 | file foo |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 450 | nnoremap <buffer> K :echom "bK"<cr> |
| 451 | nnoremap <buffer> - :echom "b-"<cr> |
| 452 | nnoremap <buffer> + :echom "b+"<cr> |
Ubaldo Tiberi | 46f2823 | 2024-06-19 19:50:32 +0200 | [diff] [blame] | 453 | |
| 454 | " no mappings for 'bar' |
| 455 | enew |
| 456 | file bar |
| 457 | |
| 458 | " Start termdebug from foo |
| 459 | buffer foo |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 460 | Termdebug |
Christian Brabandt | 2979cfc | 2024-07-24 21:37:39 +0200 | [diff] [blame] | 461 | call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))}) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 462 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 463 | wincmd b |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 464 | call assert_true(maparg('K', 'n', 0, 1).buffer) |
| 465 | call assert_true(maparg('-', 'n', 0, 1).buffer) |
| 466 | call assert_true(maparg('+', 'n', 0, 1).buffer) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 467 | call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>') |
Ubaldo Tiberi | 46f2823 | 2024-06-19 19:50:32 +0200 | [diff] [blame] | 468 | |
| 469 | Source |
| 470 | buffer bar |
| 471 | call assert_false(maparg('K', 'n', 0, 1)->empty()) |
| 472 | call assert_false(maparg('-', 'n', 0, 1)->empty()) |
| 473 | call assert_false(maparg('+', 'n', 0, 1)->empty()) |
| 474 | call assert_true(maparg('K', 'n', 0, 1).buffer->empty()) |
| 475 | call assert_true(maparg('-', 'n', 0, 1).buffer->empty()) |
| 476 | call assert_true(maparg('+', 'n', 0, 1).buffer->empty()) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 477 | wincmd t |
| 478 | quit! |
| 479 | redraw! |
| 480 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
Ubaldo Tiberi | 46f2823 | 2024-06-19 19:50:32 +0200 | [diff] [blame] | 481 | |
| 482 | " Termdebug session ended. Buffer 'bar' shall have no mappings |
| 483 | call assert_true(bufname() ==# 'bar') |
| 484 | call assert_false(maparg('K', 'n', 0, 1)->empty()) |
| 485 | call assert_false(maparg('-', 'n', 0, 1)->empty()) |
| 486 | call assert_false(maparg('+', 'n', 0, 1)->empty()) |
| 487 | call assert_true(maparg('K', 'n', 0, 1).buffer->empty()) |
| 488 | call assert_true(maparg('-', 'n', 0, 1).buffer->empty()) |
| 489 | call assert_true(maparg('+', 'n', 0, 1).buffer->empty()) |
| 490 | |
| 491 | " Buffer 'foo' shall have the same mapping as before running the termdebug |
| 492 | " session |
| 493 | buffer foo |
| 494 | call assert_true(bufname() ==# 'foo') |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 495 | call assert_true(maparg('K', 'n', 0, 1).buffer) |
| 496 | call assert_true(maparg('-', 'n', 0, 1).buffer) |
| 497 | call assert_true(maparg('+', 'n', 0, 1).buffer) |
| 498 | call assert_equal(':echom "bK"<cr>', maparg('K', 'n', 0, 1).rhs) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 499 | |
Ubaldo Tiberi | a48637c | 2024-06-18 20:18:20 +0200 | [diff] [blame] | 500 | nunmap K |
| 501 | nunmap + |
| 502 | nunmap - |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 503 | %bw! |
| 504 | endfunc |
| 505 | |
Ubaldo Tiberi | ef8eab8 | 2024-06-13 19:23:07 +0200 | [diff] [blame] | 506 | function Test_termdebug_save_restore_variables() |
Ubaldo Tiberi | a48637c | 2024-06-18 20:18:20 +0200 | [diff] [blame] | 507 | " saved mousemodel |
Ubaldo Tiberi | ef8eab8 | 2024-06-13 19:23:07 +0200 | [diff] [blame] | 508 | let &mousemodel='' |
Ubaldo Tiberi | a48637c | 2024-06-18 20:18:20 +0200 | [diff] [blame] | 509 | |
| 510 | " saved keys |
| 511 | nnoremap K :echo "hello world!"<cr> |
| 512 | let expected_map_K = maparg('K', 'n', 0 , 1) |
| 513 | nnoremap + :echo "hello plus!"<cr> |
| 514 | let expected_map_plus = maparg('+', 'n', 0 , 1) |
| 515 | let expected_map_minus = {} |
| 516 | |
| 517 | " saved &columns |
| 518 | let expected_columns = &columns |
| 519 | |
| 520 | " We want termdebug to overwrite 'K' map but not '+' map. |
| 521 | let g:termdebug_config = {} |
Ubaldo Tiberi | a90b0b4 | 2024-07-20 12:00:44 +0200 | [diff] [blame] | 522 | let g:termdebug_config['map_K'] = v:true |
Ubaldo Tiberi | a48637c | 2024-06-18 20:18:20 +0200 | [diff] [blame] | 523 | |
Ubaldo Tiberi | ef8eab8 | 2024-06-13 19:23:07 +0200 | [diff] [blame] | 524 | Termdebug |
Christian Brabandt | 2979cfc | 2024-07-24 21:37:39 +0200 | [diff] [blame] | 525 | call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))}) |
Ubaldo Tiberi | ef8eab8 | 2024-06-13 19:23:07 +0200 | [diff] [blame] | 526 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 527 | call WaitForAssert({-> assert_match(&mousemodel, 'popup_setpos')}) |
| 528 | wincmd t |
| 529 | quit! |
| 530 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
Ubaldo Tiberi | a48637c | 2024-06-18 20:18:20 +0200 | [diff] [blame] | 531 | |
| 532 | call assert_true(empty(&mousemodel)) |
| 533 | |
| 534 | call assert_true(empty(expected_map_minus)) |
| 535 | call assert_equal(expected_map_K.rhs, maparg('K', 'n', 0, 1).rhs) |
| 536 | call assert_equal(expected_map_plus.rhs, maparg('+', 'n', 0, 1).rhs) |
| 537 | |
| 538 | call assert_equal(expected_columns, &columns) |
| 539 | |
| 540 | nunmap K |
| 541 | nunmap + |
| 542 | unlet g:termdebug_config |
Ubaldo Tiberi | ef8eab8 | 2024-06-13 19:23:07 +0200 | [diff] [blame] | 543 | endfunction |
| 544 | |
Ubaldo Tiberi | f7f8f0b | 2024-06-20 22:17:34 +0200 | [diff] [blame] | 545 | function Test_termdebug_sanity_check() |
| 546 | " Test if user has filename/folders with wrong names |
| 547 | let g:termdebug_config = {} |
| 548 | let s:dict = {'disasm_window': 'Termdebug-asm-listing', 'use_prompt': 'gdb', 'variables_window': 'Termdebug-variables-listing'} |
| 549 | |
| 550 | for key in keys(s:dict) |
| 551 | let s:filename = s:dict[key] |
Ubaldo Tiberi | a90b0b4 | 2024-07-20 12:00:44 +0200 | [diff] [blame] | 552 | let g:termdebug_config[key] = v:true |
Ubaldo Tiberi | f7f8f0b | 2024-06-20 22:17:34 +0200 | [diff] [blame] | 553 | let s:error_message = "You have a file/folder named '" .. s:filename .. "'" |
| 554 | |
| 555 | " Write dummy file with bad name |
Christian Brabandt | 2979cfc | 2024-07-24 21:37:39 +0200 | [diff] [blame] | 556 | call writefile(['This', 'is', 'a', 'test'], s:filename, 'D') |
Ubaldo Tiberi | f7f8f0b | 2024-06-20 22:17:34 +0200 | [diff] [blame] | 557 | Termdebug |
| 558 | call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)}) |
| 559 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
| 560 | |
| 561 | call delete(s:filename) |
| 562 | call remove(g:termdebug_config, key) |
| 563 | endfor |
| 564 | |
| 565 | unlet g:termdebug_config |
| 566 | endfunction |
| 567 | |
| 568 | function Test_termdebug_double_termdebug_instances() |
| 569 | let s:error_message = 'Terminal debugger already running, cannot run two' |
| 570 | Termdebug |
Christian Brabandt | 2979cfc | 2024-07-24 21:37:39 +0200 | [diff] [blame] | 571 | call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))}) |
Ubaldo Tiberi | f7f8f0b | 2024-06-20 22:17:34 +0200 | [diff] [blame] | 572 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 573 | Termdebug |
| 574 | call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)}) |
| 575 | wincmd t |
| 576 | quit! |
| 577 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
| 578 | :%bw! |
| 579 | endfunction |
Ubaldo Tiberi | 62ccaa6 | 2024-05-21 23:33:03 +0200 | [diff] [blame] | 580 | |
Ubaldo Tiberi | a90b0b4 | 2024-07-20 12:00:44 +0200 | [diff] [blame] | 581 | function Test_termdebug_config_types() |
| 582 | " TODO Remove the deprecated features after 1 Jan 2025. |
Christian Brabandt | ebb08d5 | 2025-01-11 15:43:12 +0100 | [diff] [blame] | 583 | let g:test_is_flaky = 1 |
Ubaldo Tiberi | a90b0b4 | 2024-07-20 12:00:44 +0200 | [diff] [blame] | 584 | let g:termdebug_config = {} |
| 585 | let s:error_message = 'Deprecation Warning:' |
| 586 | call assert_true(maparg('K', 'n', 0, 1)->empty()) |
| 587 | |
| 588 | for key in ['disasm_window', 'variables_window', 'map_K'] |
| 589 | for val in [0, 1, v:true, v:false] |
| 590 | let g:termdebug_config[key] = val |
| 591 | Termdebug |
| 592 | |
| 593 | " Type check: warning is displayed |
| 594 | if typename(val) == 'number' |
| 595 | call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)}) |
| 596 | endif |
| 597 | |
| 598 | " Test on g:termdebug_config keys |
| 599 | if val && key != 'map_K' |
| 600 | call WaitForAssert({-> assert_equal(4, winnr('$'))}) |
| 601 | call remove(g:termdebug_config, key) |
| 602 | else |
| 603 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 604 | endif |
| 605 | |
| 606 | " Test on mapping |
| 607 | if key == 'map_K' |
| 608 | if val |
| 609 | call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs) |
| 610 | else |
| 611 | call assert_true(maparg('K', 'n', 0, 1)->empty()) |
| 612 | endif |
| 613 | endif |
| 614 | |
| 615 | " Shutoff termdebug |
| 616 | wincmd t |
| 617 | quit! |
| 618 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
| 619 | :%bw! |
| 620 | |
| 621 | endfor |
| 622 | endfor |
| 623 | |
| 624 | unlet g:termdebug_config |
| 625 | endfunction |
| 626 | |
Ubaldo Tiberi | ae1c8b7 | 2024-11-19 22:32:30 +0100 | [diff] [blame] | 627 | function Test_termdebug_config_debug() |
| 628 | let s:error_message = '\[termdebug\] Termdebug already loaded' |
| 629 | |
| 630 | " USER mode: No error message shall be displayed |
| 631 | packadd termdebug |
| 632 | call assert_true(execute('messages') !~ s:error_message) |
| 633 | |
| 634 | " DEBUG mode: Error message shall now be displayed |
| 635 | let g:termdebug_config = {} |
| 636 | let g:termdebug_config['debug'] = 1 |
| 637 | packadd termdebug |
| 638 | call assert_true(execute('messages') =~ s:error_message) |
| 639 | |
| 640 | unlet g:termdebug_config |
| 641 | unlet g:termdebug_loaded |
| 642 | " Revert DEBUG mode, by reloading the plugin |
| 643 | source $VIMRUNTIME/pack/dist/opt/termdebug/plugin/termdebug.vim |
| 644 | endfunction |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 645 | " vim: shiftwidth=2 sts=2 expandtab |