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 |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 4 | source check.vim |
| 5 | |
| 6 | CheckUnix |
| 7 | CheckFeature terminal |
| 8 | CheckExecutable gdb |
| 9 | CheckExecutable gcc |
| 10 | |
| 11 | let g:GDB = exepath('gdb') |
| 12 | if g:GDB->empty() |
Christian Brabandt | f253443 | 2023-08-27 19:59:28 +0200 | [diff] [blame] | 13 | throw 'Skipped: gdb is not found in $PATH' |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 14 | endif |
| 15 | |
| 16 | let g:GCC = exepath('gcc') |
| 17 | if g:GCC->empty() |
Christian Brabandt | f253443 | 2023-08-27 19:59:28 +0200 | [diff] [blame] | 18 | throw 'Skipped: gcc is not found in $PATH' |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 19 | endif |
| 20 | |
iam28th | 323dda1 | 2023-12-14 20:30:26 +0100 | [diff] [blame] | 21 | function s:generate_files(bin_name) |
| 22 | let src_name = a:bin_name .. '.c' |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 23 | let lines =<< trim END |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | |
| 27 | int isprime(int n) |
| 28 | { |
| 29 | if (n <= 1) |
| 30 | return 0; |
| 31 | |
| 32 | for (int i = 2; i <= n / 2; i++) |
| 33 | if (n % i == 0) |
| 34 | return 0; |
| 35 | |
| 36 | return 1; |
| 37 | } |
| 38 | |
| 39 | int main(int argc, char *argv[]) |
| 40 | { |
| 41 | int n = 7; |
| 42 | |
| 43 | printf("%d is %s prime\n", n, isprime(n) ? "a" : "not a"); |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | END |
iam28th | 323dda1 | 2023-12-14 20:30:26 +0100 | [diff] [blame] | 48 | call writefile(lines, src_name) |
| 49 | call system($'{g:GCC} -g -o {a:bin_name} {src_name}') |
| 50 | endfunction |
| 51 | |
| 52 | function s:cleanup_files(bin_name) |
| 53 | call delete(a:bin_name) |
| 54 | call delete(a:bin_name .. '.c') |
| 55 | endfunction |
| 56 | |
| 57 | packadd termdebug |
| 58 | |
| 59 | func Test_termdebug_basic() |
| 60 | let bin_name = 'XTD_basic' |
| 61 | let src_name = bin_name .. '.c' |
| 62 | call s:generate_files(bin_name) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 63 | |
| 64 | edit XTD_basic.c |
| 65 | Termdebug ./XTD_basic |
Yegappan Lakshmanan | 85c3a5b | 2023-08-27 21:59:54 +0200 | [diff] [blame] | 66 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 67 | let gdb_buf = winbufnr(1) |
| 68 | wincmd b |
| 69 | Break 9 |
| 70 | call term_wait(gdb_buf) |
| 71 | redraw! |
| 72 | call assert_equal([ |
| 73 | \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0', |
| 74 | \ 'priority': 110, 'group': 'TermDebug'}], |
| 75 | \ sign_getplaced('', #{group: 'TermDebug'})[0].signs) |
| 76 | Run |
Christian Brabandt | 6c93c94 | 2023-08-27 21:48:29 +0200 | [diff] [blame] | 77 | call term_wait(gdb_buf, 400) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 78 | redraw! |
Yegappan Lakshmanan | 85c3a5b | 2023-08-27 21:59:54 +0200 | [diff] [blame] | 79 | call WaitForAssert({-> assert_equal([ |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 80 | \ {'lnum': 9, 'id': 12, 'name': 'debugPC', 'priority': 110, |
| 81 | \ 'group': 'TermDebug'}, |
| 82 | \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0', |
| 83 | \ 'priority': 110, 'group': 'TermDebug'}], |
Yegappan Lakshmanan | 85c3a5b | 2023-08-27 21:59:54 +0200 | [diff] [blame] | 84 | \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)}) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 85 | Finish |
| 86 | call term_wait(gdb_buf) |
| 87 | redraw! |
Yegappan Lakshmanan | 85c3a5b | 2023-08-27 21:59:54 +0200 | [diff] [blame] | 88 | call WaitForAssert({-> assert_equal([ |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 89 | \ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0', |
| 90 | \ 'priority': 110, 'group': 'TermDebug'}, |
| 91 | \ {'lnum': 20, 'id': 12, 'name': 'debugPC', |
| 92 | \ 'priority': 110, 'group': 'TermDebug'}], |
Yegappan Lakshmanan | 85c3a5b | 2023-08-27 21:59:54 +0200 | [diff] [blame] | 93 | \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)}) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 94 | Continue |
Shane-XB-Qian | 2dd613f | 2023-11-12 23:53:39 +0800 | [diff] [blame] | 95 | call term_wait(gdb_buf) |
| 96 | |
| 97 | let i = 2 |
| 98 | while i <= 258 |
| 99 | Break |
| 100 | call term_wait(gdb_buf) |
| 101 | if i == 2 |
| 102 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint2.0')[0].text, '02')}) |
| 103 | endif |
| 104 | if i == 10 |
| 105 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint10.0')[0].text, '0A')}) |
| 106 | endif |
| 107 | if i == 168 |
| 108 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint168.0')[0].text, 'A8')}) |
| 109 | endif |
| 110 | if i == 255 |
| 111 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint255.0')[0].text, 'FF')}) |
| 112 | endif |
| 113 | if i == 256 |
| 114 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint256.0')[0].text, 'F+')}) |
| 115 | endif |
| 116 | if i == 258 |
| 117 | call WaitForAssert({-> assert_equal(sign_getdefined('debugBreakpoint258.0')[0].text, 'F+')}) |
| 118 | endif |
| 119 | let i += 1 |
| 120 | endwhile |
shane.xb.qian | ca48202 | 2023-11-08 21:59:15 +0100 | [diff] [blame] | 121 | |
| 122 | let cn = 0 |
| 123 | " 60 is approx spaceBuffer * 3 |
| 124 | if winwidth(0) <= 78 + 60 |
| 125 | Var |
zeertzjq | aef6179 | 2024-07-18 20:35:42 +0200 | [diff] [blame^] | 126 | call assert_equal(winnr('$'), winnr()) |
| 127 | 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] | 128 | let cn += 1 |
| 129 | bw! |
| 130 | Asm |
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 | endif |
| 136 | set columns=160 |
shane.xb.qian | fdbadea | 2023-11-12 09:42:12 +0100 | [diff] [blame] | 137 | call term_wait(gdb_buf) |
Christian Brabandt | 305127f | 2023-11-11 18:59:33 +0100 | [diff] [blame] | 138 | let winw = winwidth(0) |
shane.xb.qian | ca48202 | 2023-11-08 21:59:15 +0100 | [diff] [blame] | 139 | Var |
Christian Brabandt | 305127f | 2023-11-11 18:59:33 +0100 | [diff] [blame] | 140 | if winwidth(0) < winw |
zeertzjq | aef6179 | 2024-07-18 20:35:42 +0200 | [diff] [blame^] | 141 | call assert_equal(winnr('$') - 1, winnr()) |
| 142 | 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] | 143 | let cn += 1 |
| 144 | bw! |
| 145 | endif |
| 146 | let winw = winwidth(0) |
shane.xb.qian | ca48202 | 2023-11-08 21:59:15 +0100 | [diff] [blame] | 147 | Asm |
Christian Brabandt | 305127f | 2023-11-11 18:59:33 +0100 | [diff] [blame] | 148 | if winwidth(0) < winw |
zeertzjq | aef6179 | 2024-07-18 20:35:42 +0200 | [diff] [blame^] | 149 | call assert_equal(winnr('$') - 1, winnr()) |
| 150 | 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] | 151 | let cn += 1 |
| 152 | bw! |
| 153 | endif |
shane.xb.qian | ca48202 | 2023-11-08 21:59:15 +0100 | [diff] [blame] | 154 | set columns& |
shane.xb.qian | fdbadea | 2023-11-12 09:42:12 +0100 | [diff] [blame] | 155 | call term_wait(gdb_buf) |
shane.xb.qian | ca48202 | 2023-11-08 21:59:15 +0100 | [diff] [blame] | 156 | |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 157 | wincmd t |
| 158 | quit! |
| 159 | redraw! |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 160 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 161 | call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs) |
| 162 | |
zeertzjq | aef6179 | 2024-07-18 20:35:42 +0200 | [diff] [blame^] | 163 | for use_prompt in [0, 1] |
| 164 | let g:termdebug_config = {} |
| 165 | let g:termdebug_config['use_prompt'] = use_prompt |
| 166 | TermdebugCommand ./XTD_basic arg args |
| 167 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 168 | wincmd t |
| 169 | quit! |
| 170 | redraw! |
| 171 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
| 172 | unlet g:termdebug_config |
| 173 | endfor |
| 174 | |
iam28th | 323dda1 | 2023-12-14 20:30:26 +0100 | [diff] [blame] | 175 | call s:cleanup_files(bin_name) |
| 176 | %bw! |
| 177 | endfunc |
| 178 | |
| 179 | func Test_termdebug_tbreak() |
| 180 | let g:test_is_flaky = 1 |
| 181 | let bin_name = 'XTD_tbreak' |
| 182 | let src_name = bin_name .. '.c' |
| 183 | |
| 184 | eval s:generate_files(bin_name) |
| 185 | |
| 186 | execute 'edit ' .. src_name |
| 187 | execute 'Termdebug ./' .. bin_name |
| 188 | |
| 189 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 190 | let gdb_buf = winbufnr(1) |
| 191 | wincmd b |
| 192 | |
| 193 | let bp_line = 22 " 'return' statement in main |
| 194 | let temp_bp_line = 10 " 'if' statement in 'for' loop body |
| 195 | execute "Tbreak " .. temp_bp_line |
| 196 | execute "Break " .. bp_line |
| 197 | |
| 198 | call term_wait(gdb_buf) |
| 199 | redraw! |
| 200 | " both temporary and normal breakpoint signs were displayed... |
| 201 | call assert_equal([ |
| 202 | \ {'lnum': temp_bp_line, 'id': 1014, 'name': 'debugBreakpoint1.0', |
| 203 | \ 'priority': 110, 'group': 'TermDebug'}, |
| 204 | \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0', |
| 205 | \ 'priority': 110, 'group': 'TermDebug'}], |
| 206 | \ sign_getplaced('', #{group: 'TermDebug'})[0].signs) |
| 207 | |
| 208 | Run |
| 209 | call term_wait(gdb_buf, 400) |
| 210 | redraw! |
| 211 | " debugPC sign is on the line where the temp. bp was set; |
| 212 | " temp. bp sign was removed after hit; |
| 213 | " normal bp sign is still present |
| 214 | call WaitForAssert({-> assert_equal([ |
| 215 | \ {'lnum': temp_bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110, |
| 216 | \ 'group': 'TermDebug'}, |
| 217 | \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0', |
| 218 | \ 'priority': 110, 'group': 'TermDebug'}], |
| 219 | \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)}) |
| 220 | |
| 221 | Continue |
| 222 | call term_wait(gdb_buf) |
| 223 | redraw! |
| 224 | " debugPC is on the normal breakpoint, |
| 225 | " temp. bp on line 10 was only hit once |
| 226 | call WaitForAssert({-> assert_equal([ |
| 227 | \ {'lnum': bp_line, 'id': 12, 'name': 'debugPC', 'priority': 110, |
| 228 | \ 'group': 'TermDebug'}, |
| 229 | \ {'lnum': bp_line, 'id': 2014, 'name': 'debugBreakpoint2.0', |
| 230 | \ 'priority': 110, 'group': 'TermDebug'}], |
| 231 | \ sign_getplaced('', #{group: 'TermDebug'})[0].signs)}) |
| 232 | |
| 233 | wincmd t |
| 234 | quit! |
| 235 | redraw! |
| 236 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
| 237 | call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs) |
| 238 | |
| 239 | eval s:cleanup_files(bin_name) |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 240 | %bw! |
| 241 | endfunc |
| 242 | |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 243 | func Test_termdebug_mapping() |
| 244 | %bw! |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 245 | call assert_true(maparg('K', 'n', 0, 1)->empty()) |
| 246 | call assert_true(maparg('-', 'n', 0, 1)->empty()) |
| 247 | call assert_true(maparg('+', 'n', 0, 1)->empty()) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 248 | Termdebug |
| 249 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 250 | wincmd b |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 251 | call assert_false(maparg('K', 'n', 0, 1)->empty()) |
| 252 | call assert_false(maparg('-', 'n', 0, 1)->empty()) |
| 253 | call assert_false(maparg('+', 'n', 0, 1)->empty()) |
| 254 | call assert_false(maparg('K', 'n', 0, 1).buffer) |
| 255 | call assert_false(maparg('-', 'n', 0, 1).buffer) |
| 256 | call assert_false(maparg('+', 'n', 0, 1).buffer) |
| 257 | call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 258 | wincmd t |
| 259 | quit! |
| 260 | redraw! |
| 261 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 262 | call assert_true(maparg('K', 'n', 0, 1)->empty()) |
| 263 | call assert_true(maparg('-', 'n', 0, 1)->empty()) |
| 264 | call assert_true(maparg('+', 'n', 0, 1)->empty()) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 265 | |
| 266 | %bw! |
| 267 | nnoremap K :echom "K"<cr> |
| 268 | nnoremap - :echom "-"<cr> |
| 269 | nnoremap + :echom "+"<cr> |
| 270 | Termdebug |
| 271 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 272 | wincmd b |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 273 | call assert_false(maparg('K', 'n', 0, 1)->empty()) |
| 274 | call assert_false(maparg('-', 'n', 0, 1)->empty()) |
| 275 | call assert_false(maparg('+', 'n', 0, 1)->empty()) |
| 276 | call assert_false(maparg('K', 'n', 0, 1).buffer) |
| 277 | call assert_false(maparg('-', 'n', 0, 1).buffer) |
| 278 | call assert_false(maparg('+', 'n', 0, 1).buffer) |
| 279 | call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 280 | wincmd t |
| 281 | quit! |
| 282 | redraw! |
| 283 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 284 | call assert_false(maparg('K', 'n', 0, 1)->empty()) |
| 285 | call assert_false(maparg('-', 'n', 0, 1)->empty()) |
| 286 | call assert_false(maparg('+', 'n', 0, 1)->empty()) |
| 287 | call assert_false(maparg('K', 'n', 0, 1).buffer) |
| 288 | call assert_false(maparg('-', 'n', 0, 1).buffer) |
| 289 | call assert_false(maparg('+', 'n', 0, 1).buffer) |
| 290 | 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] | 291 | |
| 292 | %bw! |
Ubaldo Tiberi | 46f2823 | 2024-06-19 19:50:32 +0200 | [diff] [blame] | 293 | |
| 294 | " -- Test that local-buffer mappings are restored in the correct buffers -- |
| 295 | " local mappings for foo |
| 296 | file foo |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 297 | nnoremap <buffer> K :echom "bK"<cr> |
| 298 | nnoremap <buffer> - :echom "b-"<cr> |
| 299 | nnoremap <buffer> + :echom "b+"<cr> |
Ubaldo Tiberi | 46f2823 | 2024-06-19 19:50:32 +0200 | [diff] [blame] | 300 | |
| 301 | " no mappings for 'bar' |
| 302 | enew |
| 303 | file bar |
| 304 | |
| 305 | " Start termdebug from foo |
| 306 | buffer foo |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 307 | Termdebug |
| 308 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 309 | wincmd b |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 310 | call assert_true(maparg('K', 'n', 0, 1).buffer) |
| 311 | call assert_true(maparg('-', 'n', 0, 1).buffer) |
| 312 | call assert_true(maparg('+', 'n', 0, 1).buffer) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 313 | call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>') |
Ubaldo Tiberi | 46f2823 | 2024-06-19 19:50:32 +0200 | [diff] [blame] | 314 | |
| 315 | Source |
| 316 | buffer bar |
| 317 | call assert_false(maparg('K', 'n', 0, 1)->empty()) |
| 318 | call assert_false(maparg('-', 'n', 0, 1)->empty()) |
| 319 | call assert_false(maparg('+', 'n', 0, 1)->empty()) |
| 320 | call assert_true(maparg('K', 'n', 0, 1).buffer->empty()) |
| 321 | call assert_true(maparg('-', 'n', 0, 1).buffer->empty()) |
| 322 | call assert_true(maparg('+', 'n', 0, 1).buffer->empty()) |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 323 | wincmd t |
| 324 | quit! |
| 325 | redraw! |
| 326 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
Ubaldo Tiberi | 46f2823 | 2024-06-19 19:50:32 +0200 | [diff] [blame] | 327 | |
| 328 | " Termdebug session ended. Buffer 'bar' shall have no mappings |
| 329 | call assert_true(bufname() ==# 'bar') |
| 330 | call assert_false(maparg('K', 'n', 0, 1)->empty()) |
| 331 | call assert_false(maparg('-', 'n', 0, 1)->empty()) |
| 332 | call assert_false(maparg('+', 'n', 0, 1)->empty()) |
| 333 | call assert_true(maparg('K', 'n', 0, 1).buffer->empty()) |
| 334 | call assert_true(maparg('-', 'n', 0, 1).buffer->empty()) |
| 335 | call assert_true(maparg('+', 'n', 0, 1).buffer->empty()) |
| 336 | |
| 337 | " Buffer 'foo' shall have the same mapping as before running the termdebug |
| 338 | " session |
| 339 | buffer foo |
| 340 | call assert_true(bufname() ==# 'foo') |
Ken Takata | ffed154 | 2024-05-21 17:14:56 +0200 | [diff] [blame] | 341 | call assert_true(maparg('K', 'n', 0, 1).buffer) |
| 342 | call assert_true(maparg('-', 'n', 0, 1).buffer) |
| 343 | call assert_true(maparg('+', 'n', 0, 1).buffer) |
| 344 | 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] | 345 | |
Ubaldo Tiberi | a48637c | 2024-06-18 20:18:20 +0200 | [diff] [blame] | 346 | nunmap K |
| 347 | nunmap + |
| 348 | nunmap - |
shane.xb.qian | 7fbbd7f | 2023-11-08 21:44:48 +0100 | [diff] [blame] | 349 | %bw! |
| 350 | endfunc |
| 351 | |
Ubaldo Tiberi | ef8eab8 | 2024-06-13 19:23:07 +0200 | [diff] [blame] | 352 | function Test_termdebug_save_restore_variables() |
Ubaldo Tiberi | a48637c | 2024-06-18 20:18:20 +0200 | [diff] [blame] | 353 | " saved mousemodel |
Ubaldo Tiberi | ef8eab8 | 2024-06-13 19:23:07 +0200 | [diff] [blame] | 354 | let &mousemodel='' |
Ubaldo Tiberi | a48637c | 2024-06-18 20:18:20 +0200 | [diff] [blame] | 355 | |
| 356 | " saved keys |
| 357 | nnoremap K :echo "hello world!"<cr> |
| 358 | let expected_map_K = maparg('K', 'n', 0 , 1) |
| 359 | nnoremap + :echo "hello plus!"<cr> |
| 360 | let expected_map_plus = maparg('+', 'n', 0 , 1) |
| 361 | let expected_map_minus = {} |
| 362 | |
| 363 | " saved &columns |
| 364 | let expected_columns = &columns |
| 365 | |
| 366 | " We want termdebug to overwrite 'K' map but not '+' map. |
| 367 | let g:termdebug_config = {} |
| 368 | let g:termdebug_config['map_K'] = 1 |
| 369 | |
Ubaldo Tiberi | ef8eab8 | 2024-06-13 19:23:07 +0200 | [diff] [blame] | 370 | Termdebug |
| 371 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 372 | call WaitForAssert({-> assert_match(&mousemodel, 'popup_setpos')}) |
| 373 | wincmd t |
| 374 | quit! |
| 375 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
Ubaldo Tiberi | a48637c | 2024-06-18 20:18:20 +0200 | [diff] [blame] | 376 | |
| 377 | call assert_true(empty(&mousemodel)) |
| 378 | |
| 379 | call assert_true(empty(expected_map_minus)) |
| 380 | call assert_equal(expected_map_K.rhs, maparg('K', 'n', 0, 1).rhs) |
| 381 | call assert_equal(expected_map_plus.rhs, maparg('+', 'n', 0, 1).rhs) |
| 382 | |
| 383 | call assert_equal(expected_columns, &columns) |
| 384 | |
| 385 | nunmap K |
| 386 | nunmap + |
| 387 | unlet g:termdebug_config |
Ubaldo Tiberi | ef8eab8 | 2024-06-13 19:23:07 +0200 | [diff] [blame] | 388 | endfunction |
| 389 | |
Ubaldo Tiberi | f7f8f0b | 2024-06-20 22:17:34 +0200 | [diff] [blame] | 390 | function Test_termdebug_sanity_check() |
| 391 | " Test if user has filename/folders with wrong names |
| 392 | let g:termdebug_config = {} |
| 393 | let s:dict = {'disasm_window': 'Termdebug-asm-listing', 'use_prompt': 'gdb', 'variables_window': 'Termdebug-variables-listing'} |
| 394 | |
| 395 | for key in keys(s:dict) |
| 396 | let s:filename = s:dict[key] |
| 397 | let g:termdebug_config[key] = 1 |
| 398 | let s:error_message = "You have a file/folder named '" .. s:filename .. "'" |
| 399 | |
| 400 | " Write dummy file with bad name |
| 401 | call writefile(['This', 'is', 'a', 'test'], s:filename) |
| 402 | Termdebug |
| 403 | call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)}) |
| 404 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
| 405 | |
| 406 | call delete(s:filename) |
| 407 | call remove(g:termdebug_config, key) |
| 408 | endfor |
| 409 | |
| 410 | unlet g:termdebug_config |
| 411 | endfunction |
| 412 | |
| 413 | function Test_termdebug_double_termdebug_instances() |
| 414 | let s:error_message = 'Terminal debugger already running, cannot run two' |
| 415 | Termdebug |
| 416 | call WaitForAssert({-> assert_equal(3, winnr('$'))}) |
| 417 | Termdebug |
| 418 | call WaitForAssert({-> assert_true(execute('messages') =~ s:error_message)}) |
| 419 | wincmd t |
| 420 | quit! |
| 421 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
| 422 | :%bw! |
| 423 | endfunction |
Ubaldo Tiberi | 62ccaa6 | 2024-05-21 23:33:03 +0200 | [diff] [blame] | 424 | |
Yegappan Lakshmanan | 58f39d8 | 2023-08-27 11:14:44 +0200 | [diff] [blame] | 425 | " vim: shiftwidth=2 sts=2 expandtab |