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