robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
e4876d8126
master
1" Test for the termdebug plugin 2 3source shared.vim 4source check.vim 5 6CheckUnix 7" CheckFeature terminal 8CheckExecutable gdb 9CheckExecutable gcc 10 11func s: TryAssert ( assert ) 12let res = 1 13try 14let res = a: assert () 15catch 16let res = assert_report ( v: exception ) 17endtry 18return res 19endfunc 20 21" Override WaitForAssert() to turn exceptions into test failures, preventing 22" them from aborting a test. 23let s: SaveWaitForAssert = funcref ( 'WaitForAssert' ) 24func ! WaitForAssert ( assert , ...) 25let Assert = a: assert 26if type ( a: assert ) == v: t_func 27let Assert = function ( 's:TryAssert' , [ a: assert ]) 28endif 29call call ( s: SaveWaitForAssert , [ Assert ] + a: 000 ) 30endfunc 31 32let g: GDB = exepath ( 'gdb' ) 33if g: GDB ->empty () 34throw 'Skipped: gdb is not found in $PATH' 35endif 36 37let g: GCC = exepath ( 'gcc' ) 38if g: GCC ->empty () 39throw 'Skipped: gcc is not found in $PATH' 40endif 41 42function s: generate_files ( bin_name ) 43let src_name = a: bin_name .. '.c' 44let lines =<< trim END 45#include <stdio.h> 46#include <stdlib.h> 47 48int isprime(int n) 49{ 50if (n <= 1) 51return 0; 52 53for (int i = 2; i <= n / 2; i++) 54if (n % i == 0) 55return 0; 56 57return 1; 58} 59 60int main(int argc, char *argv[]) 61{ 62int n = 7; 63 64printf("%d is %s prime\n", n, isprime(n) ? "a" : "not a"); 65 66return 0; 67} 68END 69call writefile ( lines , src_name ) 70call system ( $ '{g: GCC } -g -o {a:bin_name} {src_name}') 71endfunction 72 73function s: cleanup_files ( bin_name ) 74call delete ( a: bin_name ) 75call delete ( a: bin_name .. '.c' ) 76endfunction 77 78packadd termdebug 79 80func s: GetTermdebugFunction ( name ) 81for line in execute ( 'scriptnames' ) ->split ( "\n" ) 82if line =~# 'termdebug/plugin/termdebug\.vim$' 83let sid = matchstr ( line , '^\s*\zs\d\+' ) 84return function ( '<SNR>' .. sid .. '_' .. a: name ) 85endif 86endfor 87throw 'termdebug script not found' 88endfunc 89 90func Test_termdebug_break_command_builder () 91let bin_name = 'XTD_break_cmd' 92let src_name = bin_name .. '.c' 93let BuildBreakpointCommand = s: GetTermdebugFunction ( 'BuildBreakpointCommand' ) 94call s: generate_files ( bin_name ) 95 96execute 'edit ' .. src_name 97call cursor ( 22 , 1 ) 98let here = '"' .. fnamemodify ( src_name , ':p' ) .. ':22"' 99 100call assert_equal ( '-break-insert ' .. here , BuildBreakpointCommand ( '' , v: false )) 101call assert_equal ( '-break-insert -t ' .. here , BuildBreakpointCommand ( '' , v: true )) 102call assert_equal ( '-break-insert -c "argc == 1" ' .. here , 103 \BuildBreakpointCommand ( 'if argc == 1' , v: false )) 104call assert_equal ( '-break-insert -p 2 ' .. here , 105 \BuildBreakpointCommand ( 'thread 2' , v: false )) 106call assert_equal ( '-break-insert -p 2 -c "argc == 1" ' .. here , 107 \BuildBreakpointCommand ( 'thread 2 if argc == 1' , v: false )) 108call assert_equal ( '-break-insert -p 2 -c "argc == 1" 22' , 109 \BuildBreakpointCommand ( '22 thread 2 if argc == 1' , v: false )) 110call assert_equal ( '-break-insert -c "argc == 1" 22' , 111 \BuildBreakpointCommand ( '22 if argc == 1' , v: false )) 112call assert_equal ( '-break-insert -c "é == 1" 断点' , 113 \BuildBreakpointCommand ( '断点 if é == 1' , v: false )) 114call assert_equal ( '-break-insert -p 2 断点' , 115 \BuildBreakpointCommand ( '断点 thread 2' , v: false )) 116call assert_equal ( '-break-insert 断点 if' , 117 \BuildBreakpointCommand ( '断点 if' , v: false )) 118call assert_equal ( '-break-insert 断点 thread 2 if' , 119 \BuildBreakpointCommand ( '断点 thread 2 if' , v: false )) 120call assert_equal ( '-break-insert foo\ if\ bar' , 121 \BuildBreakpointCommand ( 'foo\ if\ bar' , v: false )) 122 123call s: cleanup_files ( bin_name ) 124 %bw ! 125endfunc 126 127func Test_termdebug_break_with_default_location_and_condition () 128let g: test_is_flaky = 1 129let bin_name = 'XTD_break_if' 130let src_name = bin_name .. '.c' 131call s: generate_files ( bin_name ) 132 133execute 'edit ' .. src_name 134execute 'Termdebug ./' .. bin_name 135call WaitForAssert ({ ->assert_true ( get ( g:, "termdebug_is_running" , v: false ))}) 136call WaitForAssert ({ ->assert_equal ( 3 , winnr ( '$' ))}) 137let gdb_buf = winbufnr ( 1 ) 138wincmd b 139 140call cursor ( 22 , 1 ) 141Break if argc == 1 142call Nterm_wait ( gdb_buf ) 143redraw ! 144call WaitForAssert ({ ->assert_equal ([ 145 \{ 'lnum' : 22 , 'id' : 1014 , 'name' : 'debugBreakpoint1.0' , 146 \'priority' : 110 , 'group' : 'TermDebug' }], 147 \sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs )}) 148 149Run 150call Nterm_wait ( gdb_buf , 400 ) 151redraw ! 152call WaitForAssert ({ ->assert_equal ([ 153 \{ 'lnum' : 22 , 'id' : 12 , 'name' : 'debugPC' , 'priority' : 110 , 154 \'group' : 'TermDebug' }, 155 \{ 'lnum' : 22 , 'id' : 1014 , 'name' : 'debugBreakpoint1.0' , 156 \'priority' : 110 , 'group' : 'TermDebug' }], 157 \sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs ->reverse ())}) 158 159Continue 160call Nterm_wait ( gdb_buf ) 161wincmd t 162quit ! 163redraw ! 164call WaitForAssert ({ ->assert_equal ( 1 , winnr ( '$' ))}) 165 166call s: cleanup_files ( bin_name ) 167 %bw ! 168endfunc 169 170func Test_termdebug_basic () 171let g: test_is_flaky = 1 172let bin_name = 'XTD_basic' 173let src_name = bin_name .. '.c' 174call s: generate_files ( bin_name ) 175 176edit XTD_basic.c 177Termdebug ./XTD_basic 178call WaitForAssert ({ ->assert_true ( get ( g:, "termdebug_is_running" , v: false ))}) 179call WaitForAssert ({ ->assert_equal ( 3 , winnr ( '$' ))}) 180let gdb_buf = winbufnr ( 1 ) 181wincmd b 182Break 9 183call Nterm_wait ( gdb_buf ) 184redraw ! 185call WaitForAssert ({ ->assert_equal ([ 186 \{ 'lnum' : 9 , 'id' : 1014 , 'name' : 'debugBreakpoint1.0' , 187 \'priority' : 110 , 'group' : 'TermDebug' }], 188 \sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs )}) 189Run 190call Nterm_wait ( gdb_buf , 400 ) 191redraw ! 192call WaitForAssert ({ ->assert_equal ([ 193 \{ 'lnum' : 9 , 'id' : 12 , 'name' : 'debugPC' , 'priority' : 110 , 194 \'group' : 'TermDebug' }, 195 \{ 'lnum' : 9 , 'id' : 1014 , 'name' : 'debugBreakpoint1.0' , 196 \'priority' : 110 , 'group' : 'TermDebug' }], 197 \sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs ->reverse ())}) 198Finish 199call Nterm_wait ( gdb_buf ) 200redraw ! 201call WaitForAssert ({ ->assert_equal ([ 202 \{ 'lnum' : 9 , 'id' : 1014 , 'name' : 'debugBreakpoint1.0' , 203 \'priority' : 110 , 'group' : 'TermDebug' }, 204 \{ 'lnum' : 20 , 'id' : 12 , 'name' : 'debugPC' , 205 \'priority' : 110 , 'group' : 'TermDebug' }], 206 \sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs )}) 207Continue 208call Nterm_wait ( gdb_buf ) 209 210let g: termdebug_config = {} 211let g: termdebug_config [ 'signs' ] = [ '>1' , '>2' , '>3' ] 212let g: termdebug_config [ 'sign' ] = '>>' 213let g: termdebug_config [ 'sign_decimal' ] = 1 214 215let i = 2 216while i <= 258 217Break 218call Nterm_wait ( gdb_buf ) 219if i == 2 220call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint2.0' )[ 0 ]. text , '>2' )}) 221endif 222if i == 3 223call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint3.0' )[ 0 ]. text , '>3' )}) 224endif 225if i == 4 226call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint4.0' )[ 0 ]. text , '>>' )}) 227endif 228if i == 5 229call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint5.0' )[ 0 ]. text , '>>' )}) 230unlet g: termdebug_config [ 'sign' ] 231endif 232if i == 6 233call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint6.0' )[ 0 ]. text , '06' )}) 234endif 235if i == 10 236call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint10.0' )[ 0 ]. text , '10' )}) 237endif 238if i == 99 239call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint99.0' )[ 0 ]. text , '99' )}) 240endif 241if i == 100 242call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint100.0' )[ 0 ]. text , '9+' )}) 243endif 244if i == 110 245call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint110.0' )[ 0 ]. text , '9+' )}) 246unlet g: termdebug_config 247endif 248if i == 128 249call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint128.0' )[ 0 ]. text , '80' )}) 250endif 251if i == 168 252call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint168.0' )[ 0 ]. text , 'A8' )}) 253endif 254if i == 255 255call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint255.0' )[ 0 ]. text , 'FF' )}) 256endif 257if i == 256 258call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint256.0' )[ 0 ]. text , 'F+' )}) 259endif 260if i == 258 261call WaitForAssert ({ ->assert_equal ( sign_getdefined ( 'debugBreakpoint258.0' )[ 0 ]. text , 'F+' )}) 262endif 263let i += 1 264endwhile 265 266let cn = 0 267" 60 is approx spaceBuffer * 3 268if winwidth ( 0 ) <= 78 + 60 269Var 270call assert_equal ( winnr ( '$' ), winnr ()) 271call assert_equal ([ 'col' , [[ 'leaf' , 1002 ], [ 'leaf' , 1001 ], [ 'leaf' , 1000 ], [ 'leaf' , 1003 + cn ]]], winlayout ()) 272let cn += 1 273bw ! 274Asm 275call assert_equal ( winnr ( '$' ), winnr ()) 276call assert_equal ([ 'col' , [[ 'leaf' , 1002 ], [ 'leaf' , 1001 ], [ 'leaf' , 1000 ], [ 'leaf' , 1003 + cn ]]], winlayout ()) 277let cn += 1 278bw ! 279endif 280set columns = 160 281call Nterm_wait ( gdb_buf ) 282let winw = winwidth ( 0 ) 283Var 284if winwidth ( 0 ) < winw 285call assert_equal ( winnr ( '$' ) - 1 , winnr ()) 286call assert_equal ([ 'col' , [[ 'leaf' , 1002 ], [ 'leaf' , 1001 ], [ 'row' , [[ 'leaf' , 1003 + cn ], [ 'leaf' , 1000 ]]]]], winlayout ()) 287let cn += 1 288bw ! 289endif 290let winw = winwidth ( 0 ) 291Asm 292if winwidth ( 0 ) < winw 293call assert_equal ( winnr ( '$' ) - 1 , winnr ()) 294call assert_equal ([ 'col' , [[ 'leaf' , 1002 ], [ 'leaf' , 1001 ], [ 'row' , [[ 'leaf' , 1003 + cn ], [ 'leaf' , 1000 ]]]]], winlayout ()) 295let cn += 1 296bw ! 297endif 298set columns & 299call Nterm_wait ( gdb_buf ) 300 301wincmd t 302quit ! 303redraw ! 304call WaitForAssert ({ ->assert_equal ( 1 , winnr ( '$' ))}) 305call assert_equal ([], sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs ) 306 307for use_prompt in [ 0 , 1 ] 308let g: termdebug_config = {} 309let g: termdebug_config [ 'use_prompt' ] = use_prompt 310TermdebugCommand ./XTD_basic arg args 311call WaitForAssert ({ ->assert_true ( get ( g:, "termdebug_is_running" , v: false ))}) 312call WaitForAssert ({ ->assert_equal ( 3 , winnr ( '$' ))}) 313wincmd t 314quit ! 315redraw ! 316call WaitForAssert ({ ->assert_equal ( 1 , winnr ( '$' ))}) 317unlet g: termdebug_config 318endfor 319 320call s: cleanup_files ( bin_name ) 321 %bw ! 322endfunc 323 324func Test_termdebug_tbreak () 325let g: test_is_flaky = 1 326let bin_name = 'XTD_tbreak' 327let src_name = bin_name .. '.c' 328 329eval s: generate_files ( bin_name ) 330 331execute 'edit ' .. src_name 332execute 'Termdebug ./' .. bin_name 333 334call WaitForAssert ({ ->assert_true ( get ( g:, "termdebug_is_running" , v: false ))}) 335call WaitForAssert ({ ->assert_equal ( 3 , winnr ( '$' ))}) 336let gdb_buf = winbufnr ( 1 ) 337wincmd b 338 339let bp_line = 22 " 'return' statement in main 340let temp_bp_line = 10 " 'if' statement in 'for' loop body 341execute "Tbreak " .. temp_bp_line 342execute "Break " .. bp_line 343 344call Nterm_wait ( gdb_buf ) 345redraw ! 346" both temporary and normal breakpoint signs were displayed... 347call WaitForAssert ({ ->assert_equal ([ 348 \{ 'lnum' : temp_bp_line , 'id' : 1014 , 'name' : 'debugBreakpoint1.0' , 349 \'priority' : 110 , 'group' : 'TermDebug' }, 350 \{ 'lnum' : bp_line , 'id' : 2014 , 'name' : 'debugBreakpoint2.0' , 351 \'priority' : 110 , 'group' : 'TermDebug' }], 352 \sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs )}) 353 354Run 355call Nterm_wait ( gdb_buf , 400 ) 356redraw ! 357" debugPC sign is on the line where the temp. bp was set; 358" temp. bp sign was removed after hit; 359" normal bp sign is still present 360call WaitForAssert ({ ->assert_equal ([ 361 \{ 'lnum' : temp_bp_line , 'id' : 12 , 'name' : 'debugPC' , 'priority' : 110 , 362 \'group' : 'TermDebug' }, 363 \{ 'lnum' : bp_line , 'id' : 2014 , 'name' : 'debugBreakpoint2.0' , 364 \'priority' : 110 , 'group' : 'TermDebug' }], 365 \sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs )}) 366 367Continue 368call Nterm_wait ( gdb_buf ) 369redraw ! 370" debugPC is on the normal breakpoint, 371" temp. bp on line 10 was only hit once 372call WaitForAssert ({ ->assert_equal ([ 373 \{ 'lnum' : bp_line , 'id' : 12 , 'name' : 'debugPC' , 'priority' : 110 , 374 \'group' : 'TermDebug' }, 375 \{ 'lnum' : bp_line , 'id' : 2014 , 'name' : 'debugBreakpoint2.0' , 376 \'priority' : 110 , 'group' : 'TermDebug' }], 377 \sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs ->reverse ())}) 378 379wincmd t 380quit ! 381redraw ! 382call WaitForAssert ({ ->assert_equal ( 1 , winnr ( '$' ))}) 383call assert_equal ([], sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs ) 384 385eval s: cleanup_files ( bin_name ) 386 %bw ! 387endfunc 388 389func Test_termdebug_mapping () 390 %bw ! 391call assert_true ( maparg ( 'K' , 'n' , 0 , 1 ) ->empty ()) 392call assert_true ( maparg ( '-' , 'n' , 0 , 1 ) ->empty ()) 393call assert_true ( maparg ( '+' , 'n' , 0 , 1 ) ->empty ()) 394Termdebug 395call WaitForAssert ({ ->assert_true ( get ( g:, "termdebug_is_running" , v: false ))}) 396call WaitForAssert ({ ->assert_equal ( 3 , winnr ( '$' ))}) 397wincmd b 398call assert_false ( maparg ( 'K' , 'n' , 0 , 1 ) ->empty ()) 399call assert_false ( maparg ( '-' , 'n' , 0 , 1 ) ->empty ()) 400call assert_false ( maparg ( '+' , 'n' , 0 , 1 ) ->empty ()) 401call assert_false ( maparg ( 'K' , 'n' , 0 , 1 ). buffer ) 402call assert_false ( maparg ( '-' , 'n' , 0 , 1 ). buffer ) 403call assert_false ( maparg ( '+' , 'n' , 0 , 1 ). buffer ) 404call assert_equal ( ':Evaluate<CR>' , maparg ( 'K' , 'n' , 0 , 1 ). rhs ) 405wincmd t 406quit ! 407redraw ! 408call WaitForAssert ({ ->assert_equal ( 1 , winnr ( '$' ))}) 409call assert_true ( maparg ( 'K' , 'n' , 0 , 1 ) ->empty ()) 410call assert_true ( maparg ( '-' , 'n' , 0 , 1 ) ->empty ()) 411call assert_true ( maparg ( '+' , 'n' , 0 , 1 ) ->empty ()) 412 413 %bw ! 414nnoremap K :echom "K"< cr > 415nnoremap - :echom "-"< cr > 416nnoremap + :echom "+"< cr > 417Termdebug 418call WaitForAssert ({ ->assert_true ( get ( g:, "termdebug_is_running" , v: false ))}) 419call WaitForAssert ({ ->assert_equal ( 3 , winnr ( '$' ))}) 420wincmd b 421call assert_false ( maparg ( 'K' , 'n' , 0 , 1 ) ->empty ()) 422call assert_false ( maparg ( '-' , 'n' , 0 , 1 ) ->empty ()) 423call assert_false ( maparg ( '+' , 'n' , 0 , 1 ) ->empty ()) 424call assert_false ( maparg ( 'K' , 'n' , 0 , 1 ). buffer ) 425call assert_false ( maparg ( '-' , 'n' , 0 , 1 ). buffer ) 426call assert_false ( maparg ( '+' , 'n' , 0 , 1 ). buffer ) 427call assert_equal ( ':Evaluate<CR>' , maparg ( 'K' , 'n' , 0 , 1 ). rhs ) 428wincmd t 429quit ! 430redraw ! 431call WaitForAssert ({ ->assert_equal ( 1 , winnr ( '$' ))}) 432call assert_false ( maparg ( 'K' , 'n' , 0 , 1 ) ->empty ()) 433call assert_false ( maparg ( '-' , 'n' , 0 , 1 ) ->empty ()) 434call assert_false ( maparg ( '+' , 'n' , 0 , 1 ) ->empty ()) 435call assert_false ( maparg ( 'K' , 'n' , 0 , 1 ). buffer ) 436call assert_false ( maparg ( '-' , 'n' , 0 , 1 ). buffer ) 437call assert_false ( maparg ( '+' , 'n' , 0 , 1 ). buffer ) 438call assert_equal ( ':echom "K"<cr>' , maparg ( 'K' , 'n' , 0 , 1 ). rhs ) 439 440 %bw ! 441 442" -- Test that local-buffer mappings are restored in the correct buffers -- 443" local mappings for foo 444file foo 445nnoremap <buffer> K :echom "bK"< cr > 446nnoremap <buffer> - :echom "b-"< cr > 447nnoremap <buffer> + :echom "b+"< cr > 448 449" no mappings for 'bar' 450enew 451file bar 452 453" Start termdebug from foo 454buffer foo 455Termdebug 456call WaitForAssert ({ ->assert_true ( get ( g:, "termdebug_is_running" , v: false ))}) 457call WaitForAssert ({ ->assert_equal ( 3 , winnr ( '$' ))}) 458wincmd b 459call assert_true ( maparg ( 'K' , 'n' , 0 , 1 ). buffer ) 460call assert_true ( maparg ( '-' , 'n' , 0 , 1 ). buffer ) 461call assert_true ( maparg ( '+' , 'n' , 0 , 1 ). buffer ) 462call assert_equal ( maparg ( 'K' , 'n' , 0 , 1 ). rhs , ':echom "bK"<cr>' ) 463 464Source 465buffer bar 466call assert_false ( maparg ( 'K' , 'n' , 0 , 1 ) ->empty ()) 467call assert_false ( maparg ( '-' , 'n' , 0 , 1 ) ->empty ()) 468call assert_false ( maparg ( '+' , 'n' , 0 , 1 ) ->empty ()) 469call assert_true ( maparg ( 'K' , 'n' , 0 , 1 ). buffer ->empty ()) 470call assert_true ( maparg ( '-' , 'n' , 0 , 1 ). buffer ->empty ()) 471call assert_true ( maparg ( '+' , 'n' , 0 , 1 ). buffer ->empty ()) 472wincmd t 473quit ! 474redraw ! 475call WaitForAssert ({ ->assert_equal ( 1 , winnr ( '$' ))}) 476 477" Termdebug session ended. Buffer 'bar' shall have no mappings 478call assert_true ( bufname () ==# 'bar' ) 479call assert_false ( maparg ( 'K' , 'n' , 0 , 1 ) ->empty ()) 480call assert_false ( maparg ( '-' , 'n' , 0 , 1 ) ->empty ()) 481call assert_false ( maparg ( '+' , 'n' , 0 , 1 ) ->empty ()) 482call assert_true ( maparg ( 'K' , 'n' , 0 , 1 ). buffer ->empty ()) 483call assert_true ( maparg ( '-' , 'n' , 0 , 1 ). buffer ->empty ()) 484call assert_true ( maparg ( '+' , 'n' , 0 , 1 ). buffer ->empty ()) 485 486" Buffer 'foo' shall have the same mapping as before running the termdebug 487" session 488buffer foo 489call assert_true ( bufname () ==# 'foo' ) 490call assert_true ( maparg ( 'K' , 'n' , 0 , 1 ). buffer ) 491call assert_true ( maparg ( '-' , 'n' , 0 , 1 ). buffer ) 492call assert_true ( maparg ( '+' , 'n' , 0 , 1 ). buffer ) 493call assert_equal ( ':echom "bK"<cr>' , maparg ( 'K' , 'n' , 0 , 1 ). rhs ) 494 495nunmap K 496nunmap + 497nunmap - 498 %bw ! 499endfunc 500 501func Test_termdebug_bufnames () 502" Test if user has filename/folders named gdb, Termdebug-gdb-console, 503" etc. in the current directory 504let g: termdebug_config = {} 505let g: termdebug_config [ 'use_prompt' ] = 1 506let filename = 'gdb' 507let replacement_filename = 'Termdebug-gdb-console' 508 509call writefile ([ 'This' , 'is' , 'a' , 'test' ], filename , 'D' ) 510" Throw away the file once the test has done. 511Termdebug 512" Once termdebug has completed the startup you should have 3 windows on screen 513call WaitForAssert ({ ->assert_equal ( 3 , winnr ( '$' ))}) 514" A file named filename already exists in the working directory, 515" hence you must call the newly created buffer differently 516call WaitForAssert ({ ->assert_false ( bufexists ( filename ))}) 517call WaitForAssert ({ ->assert_true ( bufexists ( replacement_filename ))}) 518quit ! 519call WaitForAssert ({ ->assert_equal ( 1 , winnr ( '$' ))}) 520 521" Check if error message is in :message 522let g: termdebug_config [ 'disasm_window' ] = 1 523let filename = 'Termdebug-asm-listing' 524call writefile ([ 'This' , 'is' , 'a' , 'test' ], filename , 'D' ) 525" Check only the head of the error message 526let error_message = "You have a file/folder named '" .. filename .. "'" 527Termdebug 528" Once termdebug has completed the startup you should have 4 windows on screen 529call WaitForAssert ({ ->assert_equal ( 4 , winnr ( '$' ))}) 530call WaitForAssert ({ ->assert_notequal ( -1 , stridx ( execute ( 'messages' ), error_message ))}) 531quit ! 532wincmd b 533wincmd q 534call WaitForAssert ({ ->assert_equal ( 1 , winnr ( '$' ))}) 535 536unlet g: termdebug_config 537endfunc 538 539function Test_termdebug_save_restore_variables () 540" saved mousemodel 541"let &mousemodel='' 542let & mousemodel = 'extend' 543 544" saved keys 545nnoremap K :echo "hello world!"< cr > 546let expected_map_K = maparg ( 'K' , 'n' , 0 , 1 ) 547nnoremap + :echo "hello plus!"< cr > 548let expected_map_plus = maparg ( '+' , 'n' , 0 , 1 ) 549let expected_map_minus = {} 550 551" saved &columns 552let expected_columns = & columns 553 554" We want termdebug to overwrite 'K' map but not '+' map. 555let g: termdebug_config = {} 556let g: termdebug_config [ 'map_K' ] = 1 557 558Termdebug 559call WaitForAssert ({ ->assert_true ( get ( g:, "termdebug_is_running" , v: false ))}) 560call WaitForAssert ({ ->assert_equal ( 3 , winnr ( '$' ))}) 561call WaitForAssert ({ ->assert_match ( & mousemodel , 'popup_setpos' )}) 562wincmd t 563quit ! 564call WaitForAssert ({ ->assert_equal ( 1 , winnr ( '$' ))}) 565 566"call assert_true(empty(&mousemodel)) 567call assert_equal ( & mousemodel , 'extend' ) 568 569call assert_true ( empty ( expected_map_minus )) 570call assert_equal ( expected_map_K . rhs , maparg ( 'K' , 'n' , 0 , 1 ). rhs ) 571call assert_equal ( expected_map_plus . rhs , maparg ( '+' , 'n' , 0 , 1 ). rhs ) 572 573call assert_equal ( expected_columns , & columns ) 574 575nunmap K 576nunmap + 577unlet g: termdebug_config 578endfunction 579 580 581func Test_termdebug_toggle_break () 582let g: test_is_flaky = 1 583let bin_name = 'XTD_tbreak' 584let src_name = bin_name .. '.c' 585 586eval s: generate_files ( bin_name ) 587 588execute 'edit ' .. src_name 589execute 'Termdebug ./' .. bin_name 590 591call WaitForAssert ({ ->assert_true ( get ( g:, "termdebug_is_running" , v: false ))}) 592call WaitForAssert ({ ->assert_equal ( 3 , winnr ( '$' ))}) 593let gdb_buf = winbufnr ( 1 ) 594wincmd b 595 596let bp_line = 22 " 'return' statement in main 597execute "normal! " .. bp_line .. "G" 598execute "ToggleBreak" 599 600call Nterm_wait ( gdb_buf ) 601redraw ! 602call WaitForAssert ({ ->assert_equal ([ 603 \{ 'lnum' : bp_line , 'id' : 1014 , 'name' : 'debugBreakpoint1.0' , 604 \'priority' : 110 , 'group' : 'TermDebug' }], 605 \sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs )}) 606 607RunOrContinue 608call Nterm_wait ( gdb_buf , 400 ) 609redraw ! 610call WaitForAssert ({ ->assert_equal ([ 611 \{ 'lnum' : bp_line , 'id' : 12 , 'name' : 'debugPC' , 'priority' : 110 , 612 \'group' : 'TermDebug' }, 613 \{ 'lnum' : bp_line , 'id' : 1014 , 'name' : 'debugBreakpoint1.0' , 614 \'priority' : 110 , 'group' : 'TermDebug' }], 615 \sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs ->reverse ())}) 616 617" Add one break point 618execute "normal! " .. bp_line .. "G" 619execute "ToggleBreak" 620call Nterm_wait ( gdb_buf ) 621redraw ! 622call WaitForAssert ({ ->assert_equal ([ 623 \{ 'lnum' : bp_line , 'id' : 12 , 'name' : 'debugPC' , 'priority' : 110 , 624 \'group' : 'TermDebug' }], 625 \sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs )}) 626 627" Remove one break point 628execute "normal! " .. bp_line .. "G" 629execute "ToggleBreak" 630call Nterm_wait ( gdb_buf ) 631redraw ! 632call WaitForAssert ({ ->assert_equal ([ 633 \{ 'lnum' : bp_line , 'id' : 2014 , 'name' : 'debugBreakpoint2.0' , 634 \'priority' : 110 , 'group' : 'TermDebug' }, 635 \{ 'lnum' : bp_line , 'id' : 12 , 'name' : 'debugPC' , 'priority' : 110 , 636 \'group' : 'TermDebug' }], 637 \sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs )}) 638 639" Remove multiple break points 640execute "Break" 641execute "Break" 642execute "Break" 643execute "Break" 644call Nterm_wait ( gdb_buf , 400 ) 645execute "ToggleBreak" 646call Nterm_wait ( gdb_buf ) 647redraw ! 648call WaitForAssert ({ ->assert_equal ([ 649 \{ 'lnum' : bp_line , 'id' : 12 , 'name' : 'debugPC' , 'priority' : 110 , 650 \'group' : 'TermDebug' }], 651 \sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs )}) 652 653 654wincmd t 655quit ! 656redraw ! 657call WaitForAssert ({ ->assert_equal ( 1 , winnr ( '$' ))}) 658call assert_equal ([], sign_getplaced ( '' , #{ group : 'TermDebug' })[ 0 ]. signs ) 659 660eval s: cleanup_files ( bin_name ) 661 %bw ! 662endfunc 663 664" vim: shiftwidth=2 sts=2 expandtab