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