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