1" Test Vim profiler 2 3source check.vim 4CheckFeature profile 5 6source shared.vim 7source screendump.vim 8 9func Test_profile_func() 10 call RunProfileFunc('func', 'let', 'let') 11 call RunProfileFunc('def', 'var', '') 12endfunc 13 14func RunProfileFunc(command, declare, assign) 15 let lines =<< trim [CODE] 16 profile start Xprofile_func.log 17 profile func Foo* 18 XXX Foo1() 19 endXXX 20 XXX Foo2() 21 DDD counter = 100 22 while counter > 0 23 AAA counter = counter - 1 24 endwhile 25 sleep 1m 26 endXXX 27 XXX Foo3() 28 endXXX 29 XXX Bar() 30 endXXX 31 call Foo1() 32 call Foo1() 33 profile pause 34 call Foo1() 35 profile continue 36 call Foo2() 37 call Foo3() 38 call Bar() 39 if !v:profiling 40 delfunc Foo2 41 endif 42 delfunc Foo3 43 [CODE] 44 45 call map(lines, {k, v -> substitute(v, 'XXX', a:command, '') }) 46 call map(lines, {k, v -> substitute(v, 'DDD', a:declare, '') }) 47 call map(lines, {k, v -> substitute(v, 'AAA', a:assign, '') }) 48 49 call writefile(lines, 'Xprofile_func.vim') 50 call system(GetVimCommand() 51 \ . ' -es --clean' 52 \ . ' -c "so Xprofile_func.vim"' 53 \ . ' -c "qall!"') 54 call assert_equal(0, v:shell_error) 55 56 let lines = readfile('Xprofile_func.log') 57 58 " - Foo1() is called 3 times but should be reported as called twice 59 " since one call is in between "profile pause" .. "profile continue". 60 " - Foo2() should come before Foo1() since Foo1() does much more work. 61 " - Foo3() is not reported because function is deleted. 62 " - Unlike Foo3(), Foo2() should not be deleted since there is a check 63 " for v:profiling. 64 " - Bar() is not reported since it does not match "profile func Foo*". 65 call assert_equal(31, len(lines)) 66 67 call assert_equal('FUNCTION Foo1()', lines[0]) 68 call assert_match('Defined:.*Xprofile_func.vim:3', lines[1]) 69 call assert_equal('Called 2 times', lines[2]) 70 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3]) 71 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4]) 72 call assert_equal('', lines[5]) 73 call assert_equal('count total (s) self (s)', lines[6]) 74 call assert_equal('', lines[7]) 75 call assert_equal('FUNCTION Foo2()', lines[8]) 76 call assert_equal('Called 1 time', lines[10]) 77 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[11]) 78 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[12]) 79 call assert_equal('', lines[13]) 80 call assert_equal('count total (s) self (s)', lines[14]) 81 call assert_match('^\s*1\s\+.*\s\(let\|var\) counter = 100$', lines[15]) 82 call assert_match('^\s*101\s\+.*\swhile counter > 0$', lines[16]) 83 call assert_match('^\s*100\s\+.*\s \(let\)\= counter = counter - 1$', lines[17]) 84 call assert_match('^\s*10[01]\s\+.*\sendwhile$', lines[18]) 85 call assert_match('^\s*1\s\+.\+sleep 1m$', lines[19]) 86 call assert_equal('', lines[20]) 87 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[21]) 88 call assert_equal('count total (s) self (s) function', lines[22]) 89 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo2()$', lines[23]) 90 call assert_match('^\s*2\s\+\d\+\.\d\+\s\+Foo1()$', lines[24]) 91 call assert_equal('', lines[25]) 92 call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[26]) 93 call assert_equal('count total (s) self (s) function', lines[27]) 94 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo2()$', lines[28]) 95 call assert_match('^\s*2\s\+\d\+\.\d\+\s\+Foo1()$', lines[29]) 96 call assert_equal('', lines[30]) 97 98 call delete('Xprofile_func.vim') 99 call delete('Xprofile_func.log') 100endfunc 101 102func Test_profile_func_with_ifelse() 103 call Run_profile_func_with_ifelse('func', 'let') 104 call Run_profile_func_with_ifelse('def', 'var') 105endfunc 106 107func Run_profile_func_with_ifelse(command, declare) 108 let lines =<< trim [CODE] 109 XXX Foo1() 110 if 1 111 DDD x = 0 112 elseif 1 113 DDD x = 1 114 else 115 DDD x = 2 116 endif 117 endXXX 118 XXX Foo2() 119 if 0 120 DDD x = 0 121 elseif 1 122 DDD x = 1 123 else 124 DDD x = 2 125 endif 126 endXXX 127 XXX Foo3() 128 if 0 129 DDD x = 0 130 elseif 0 131 DDD x = 1 132 else 133 DDD x = 2 134 endif 135 endXXX 136 call Foo1() 137 call Foo2() 138 call Foo3() 139 [CODE] 140 141 call map(lines, {k, v -> substitute(v, 'XXX', a:command, '') }) 142 call map(lines, {k, v -> substitute(v, 'DDD', a:declare, '') }) 143 144 call writefile(lines, 'Xprofile_func.vim') 145 call system(GetVimCommand() 146 \ . ' -es -i NONE --noplugin' 147 \ . ' -c "profile start Xprofile_func.log"' 148 \ . ' -c "profile func Foo*"' 149 \ . ' -c "so Xprofile_func.vim"' 150 \ . ' -c "qall!"') 151 call assert_equal(0, v:shell_error) 152 153 let lines = readfile('Xprofile_func.log') 154 155 " - Foo1() should pass 'if' block. 156 " - Foo2() should pass 'elseif' block. 157 " - Foo3() should pass 'else' block. 158 call assert_equal(57, len(lines)) 159 160 call assert_equal('FUNCTION Foo1()', lines[0]) 161 call assert_match('Defined:.*Xprofile_func.vim', lines[1]) 162 call assert_equal('Called 1 time', lines[2]) 163 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3]) 164 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4]) 165 call assert_equal('', lines[5]) 166 call assert_equal('count total (s) self (s)', lines[6]) 167 call assert_match('^\s*1\s\+.*\sif 1$', lines[7]) 168 call assert_match('^\s*1\s\+.*\s \(let\|var\) x = 0$', lines[8]) 169 call assert_match( '^\s\+elseif 1$', lines[9]) 170 call assert_match( '^\s\+\(let\|var\) x = 1$', lines[10]) 171 call assert_match( '^\s\+else$', lines[11]) 172 call assert_match( '^\s\+\(let\|var\) x = 2$', lines[12]) 173 call assert_match('^\s*1\s\+.*\sendif$', lines[13]) 174 call assert_equal('', lines[14]) 175 call assert_equal('FUNCTION Foo2()', lines[15]) 176 call assert_equal('Called 1 time', lines[17]) 177 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[18]) 178 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[19]) 179 call assert_equal('', lines[20]) 180 call assert_equal('count total (s) self (s)', lines[21]) 181 call assert_match('^\s*1\s\+.*\sif 0$', lines[22]) 182 call assert_match( '^\s\+\(let\|var\) x = 0$', lines[23]) 183 call assert_match('^\s*1\s\+.*\selseif 1$', lines[24]) 184 call assert_match('^\s*1\s\+.*\s \(let\|var\) x = 1$', lines[25]) 185 call assert_match( '^\s\+else$', lines[26]) 186 call assert_match( '^\s\+\(let\|var\) x = 2$', lines[27]) 187 call assert_match('^\s*1\s\+.*\sendif$', lines[28]) 188 call assert_equal('', lines[29]) 189 call assert_equal('FUNCTION Foo3()', lines[30]) 190 call assert_equal('Called 1 time', lines[32]) 191 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[33]) 192 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[34]) 193 call assert_equal('', lines[35]) 194 call assert_equal('count total (s) self (s)', lines[36]) 195 call assert_match('^\s*1\s\+.*\sif 0$', lines[37]) 196 call assert_match( '^\s\+\(let\|var\) x = 0$', lines[38]) 197 call assert_match('^\s*1\s\+.*\selseif 0$', lines[39]) 198 call assert_match( '^\s\+\(let\|var\) x = 1$', lines[40]) 199 call assert_match('^\s*1\s\+.*\selse$', lines[41]) 200 call assert_match('^\s*1\s\+.*\s \(let\|var\) x = 2$', lines[42]) 201 call assert_match('^\s*1\s\+.*\sendif$', lines[43]) 202 call assert_equal('', lines[44]) 203 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[45]) 204 call assert_equal('count total (s) self (s) function', lines[46]) 205 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[47]) 206 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[48]) 207 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[49]) 208 call assert_equal('', lines[50]) 209 call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[51]) 210 call assert_equal('count total (s) self (s) function', lines[52]) 211 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[53]) 212 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[54]) 213 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[55]) 214 call assert_equal('', lines[56]) 215 216 call delete('Xprofile_func.vim') 217 call delete('Xprofile_func.log') 218endfunc 219 220func Test_profile_func_with_trycatch() 221 call Run_profile_func_with_trycatch('func', 'let') 222 call Run_profile_func_with_trycatch('def', 'var') 223endfunc 224 225func Run_profile_func_with_trycatch(command, declare) 226 let lines =<< trim [CODE] 227 XXX Foo1() 228 try 229 DDD x = 0 230 catch 231 DDD x = 1 232 finally 233 DDD x = 2 234 endtry 235 endXXX 236 XXX Foo2() 237 try 238 throw 0 239 catch 240 DDD x = 1 241 finally 242 DDD x = 2 243 endtry 244 endXXX 245 XXX Foo3() 246 try 247 throw 0 248 catch 249 throw 1 250 finally 251 DDD x = 2 252 endtry 253 endXXX 254 call Foo1() 255 call Foo2() 256 let rethrown = 0 257 try 258 call Foo3() 259 catch 260 let rethrown = 1 261 endtry 262 if rethrown != 1 263 " call Foo1 again so that the test fails 264 call Foo1() 265 endif 266 [CODE] 267 268 call map(lines, {k, v -> substitute(v, 'XXX', a:command, '') }) 269 call map(lines, {k, v -> substitute(v, 'DDD', a:declare, '') }) 270 271 call writefile(lines, 'Xprofile_func.vim') 272 call system(GetVimCommand() 273 \ . ' -es -i NONE --noplugin' 274 \ . ' -c "profile start Xprofile_func.log"' 275 \ . ' -c "profile func Foo*"' 276 \ . ' -c "so Xprofile_func.vim"' 277 \ . ' -c "qall!"') 278 call assert_equal(0, v:shell_error) 279 280 let lines = readfile('Xprofile_func.log') 281 282 " - Foo1() should pass 'try' 'finally' blocks. 283 " - Foo2() should pass 'catch' 'finally' blocks. 284 " - Foo3() should not pass 'endtry'. 285 call assert_equal(57, len(lines)) 286 287 call assert_equal('FUNCTION Foo1()', lines[0]) 288 call assert_match('Defined:.*Xprofile_func.vim', lines[1]) 289 call assert_equal('Called 1 time', lines[2]) 290 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3]) 291 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4]) 292 call assert_equal('', lines[5]) 293 call assert_equal('count total (s) self (s)', lines[6]) 294 call assert_match('^\s*1\s\+.*\stry$', lines[7]) 295 call assert_match('^\s*1\s\+.*\s \(let\|var\) x = 0$', lines[8]) 296 call assert_match( '^\s\+catch$', lines[9]) 297 call assert_match( '^\s\+\(let\|var\) x = 1$', lines[10]) 298 call assert_match('^\s*1\s\+.*\sfinally$', lines[11]) 299 call assert_match('^\s*1\s\+.*\s \(let\|var\) x = 2$', lines[12]) 300 call assert_match('^\s*1\s\+.*\sendtry$', lines[13]) 301 call assert_equal('', lines[14]) 302 call assert_equal('FUNCTION Foo2()', lines[15]) 303 call assert_equal('Called 1 time', lines[17]) 304 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[18]) 305 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[19]) 306 call assert_equal('', lines[20]) 307 call assert_equal('count total (s) self (s)', lines[21]) 308 call assert_match('^\s*1\s\+.*\stry$', lines[22]) 309 call assert_match('^\s*1\s\+.*\s throw 0$', lines[23]) 310 call assert_match('^\s*1\s\+.*\scatch$', lines[24]) 311 call assert_match('^\s*1\s\+.*\s \(let\|var\) x = 1$', lines[25]) 312 call assert_match('^\s*1\s\+.*\sfinally$', lines[26]) 313 call assert_match('^\s*1\s\+.*\s \(let\|var\) x = 2$', lines[27]) 314 call assert_match('^\s*1\s\+.*\sendtry$', lines[28]) 315 call assert_equal('', lines[29]) 316 call assert_equal('FUNCTION Foo3()', lines[30]) 317 call assert_equal('Called 1 time', lines[32]) 318 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[33]) 319 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[34]) 320 call assert_equal('', lines[35]) 321 call assert_equal('count total (s) self (s)', lines[36]) 322 call assert_match('^\s*1\s\+.*\stry$', lines[37]) 323 call assert_match('^\s*1\s\+.*\s throw 0$', lines[38]) 324 call assert_match('^\s*1\s\+.*\scatch$', lines[39]) 325 call assert_match('^\s*1\s\+.*\s throw 1$', lines[40]) 326 call assert_match('^\s*1\s\+.*\sfinally$', lines[41]) 327 call assert_match('^\s*1\s\+.*\s \(let\|var\) x = 2$', lines[42]) 328 call assert_match( '^\s\+endtry$', lines[43]) 329 call assert_equal('', lines[44]) 330 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[45]) 331 call assert_equal('count total (s) self (s) function', lines[46]) 332 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[47]) 333 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[48]) 334 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[49]) 335 call assert_equal('', lines[50]) 336 call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[51]) 337 call assert_equal('count total (s) self (s) function', lines[52]) 338 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[53]) 339 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[54]) 340 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[55]) 341 call assert_equal('', lines[56]) 342 343 call delete('Xprofile_func.vim') 344 call delete('Xprofile_func.log') 345endfunc 346 347func Test_profile_file() 348 let lines =<< trim [CODE] 349 func! Foo() 350 endfunc 351 for i in range(10) 352 " a comment 353 call Foo() 354 endfor 355 call Foo() 356 [CODE] 357 358 call writefile(lines, 'Xprofile_file.vim') 359 call system(GetVimCommandClean() 360 \ . ' -es' 361 \ . ' -c "profile start Xprofile_file.log"' 362 \ . ' -c "profile file Xprofile_file.vim"' 363 \ . ' -c "so Xprofile_file.vim"' 364 \ . ' -c "so Xprofile_file.vim"' 365 \ . ' -c "qall!"') 366 call assert_equal(0, v:shell_error) 367 368 let lines = readfile('Xprofile_file.log') 369 370 call assert_equal(14, len(lines)) 371 372 call assert_match('^SCRIPT .*Xprofile_file.vim$', lines[0]) 373 call assert_equal('Sourced 2 times', lines[1]) 374 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[2]) 375 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[3]) 376 call assert_equal('', lines[4]) 377 call assert_equal('count total (s) self (s)', lines[5]) 378 call assert_match(' 2 0.\d\+ func! Foo()', lines[6]) 379 call assert_equal(' endfunc', lines[7]) 380 " Loop iterates 10 times. Since script runs twice, body executes 20 times. 381 " First line of loop executes one more time than body to detect end of loop. 382 call assert_match('^\s*22\s\+\d\+\.\d\+\s\+for i in range(10)$', lines[8]) 383 call assert_equal(' " a comment', lines[9]) 384 " if self and total are equal we only get one number 385 call assert_match('^\s*20\s\+\(\d\+\.\d\+\s\+\)\=\d\+\.\d\+\s\+call Foo()$', lines[10]) 386 call assert_match('^\s*22\s\+\d\+\.\d\+\s\+endfor$', lines[11]) 387 " if self and total are equal we only get one number 388 call assert_match('^\s*2\s\+\(\d\+\.\d\+\s\+\)\=\d\+\.\d\+\s\+call Foo()$', lines[12]) 389 call assert_equal('', lines[13]) 390 391 call delete('Xprofile_file.vim') 392 call delete('Xprofile_file.log') 393endfunc 394 395func Test_profile_file_with_cont() 396 let lines = [ 397 \ 'echo "hello', 398 \ ' \ world"', 399 \ 'echo "foo ', 400 \ ' \bar"', 401 \ ] 402 403 call writefile(lines, 'Xprofile_file.vim') 404 call system(GetVimCommandClean() 405 \ . ' -es' 406 \ . ' -c "profile start Xprofile_file.log"' 407 \ . ' -c "profile file Xprofile_file.vim"' 408 \ . ' -c "so Xprofile_file.vim"' 409 \ . ' -c "qall!"') 410 call assert_equal(0, v:shell_error) 411 412 let lines = readfile('Xprofile_file.log') 413 call assert_equal(11, len(lines)) 414 415 call assert_match('^SCRIPT .*Xprofile_file.vim$', lines[0]) 416 call assert_equal('Sourced 1 time', lines[1]) 417 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[2]) 418 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[3]) 419 call assert_equal('', lines[4]) 420 call assert_equal('count total (s) self (s)', lines[5]) 421 call assert_match(' 1 0.\d\+ echo "hello', lines[6]) 422 call assert_equal(' \ world"', lines[7]) 423 call assert_match(' 1 0.\d\+ echo "foo ', lines[8]) 424 call assert_equal(' \bar"', lines[9]) 425 call assert_equal('', lines[10]) 426 427 call delete('Xprofile_file.vim') 428 call delete('Xprofile_file.log') 429endfunc 430 431func Test_profile_completion() 432 call feedkeys(":profile \<C-A>\<C-B>\"\<CR>", 'tx') 433 call assert_equal('"profile continue file func pause start', @:) 434 435 call feedkeys(":profile start test_prof\<C-A>\<C-B>\"\<CR>", 'tx') 436 call assert_match('^"profile start.* test_profile\.vim', @:) 437endfunc 438 439func Test_profile_errors() 440 call assert_fails("profile func Foo", 'E750:') 441 call assert_fails("profile pause", 'E750:') 442 call assert_fails("profile continue", 'E750:') 443endfunc 444 445func Test_profile_truncate_mbyte() 446 if &enc !=# 'utf-8' 447 return 448 endif 449 450 let lines = [ 451 \ 'scriptencoding utf-8', 452 \ 'func! Foo()', 453 \ ' return [', 454 \ ' \ "' . join(map(range(0x4E00, 0x4E00 + 340), 'nr2char(v:val)'), '') . '",', 455 \ ' \ "' . join(map(range(0x4F00, 0x4F00 + 340), 'nr2char(v:val)'), '') . '",', 456 \ ' \ ]', 457 \ 'endfunc', 458 \ 'call Foo()', 459 \ ] 460 461 call writefile(lines, 'Xprofile_file.vim') 462 call system(GetVimCommandClean() 463 \ . ' -es --cmd "set enc=utf-8"' 464 \ . ' -c "profile start Xprofile_file.log"' 465 \ . ' -c "profile file Xprofile_file.vim"' 466 \ . ' -c "so Xprofile_file.vim"' 467 \ . ' -c "qall!"') 468 call assert_equal(0, v:shell_error) 469 470 split Xprofile_file.log 471 if &fenc != '' 472 call assert_equal('utf-8', &fenc) 473 endif 474 /func! Foo() 475 let lnum = line('.') 476 call assert_match('^\s*return \[$', getline(lnum + 1)) 477 call assert_match("\u4F52$", getline(lnum + 2)) 478 call assert_match("\u5052$", getline(lnum + 3)) 479 call assert_match('^\s*\\ \]$', getline(lnum + 4)) 480 bwipe! 481 482 call delete('Xprofile_file.vim') 483 call delete('Xprofile_file.log') 484endfunc 485 486func Test_profdel_func() 487 let lines =<< trim [CODE] 488 profile start Xprofile_file.log 489 func! Foo1() 490 endfunc 491 func! Foo2() 492 endfunc 493 func! Foo3() 494 endfunc 495 496 profile func Foo1 497 profile func Foo2 498 call Foo1() 499 call Foo2() 500 501 profile func Foo3 502 profdel func Foo2 503 profdel func Foo3 504 call Foo1() 505 call Foo2() 506 call Foo3() 507 [CODE] 508 call writefile(lines, 'Xprofile_file.vim') 509 call system(GetVimCommandClean() . ' -es -c "so Xprofile_file.vim" -c q') 510 call assert_equal(0, v:shell_error) 511 512 let lines = readfile('Xprofile_file.log') 513 call assert_equal(26, len(lines)) 514 515 " Check that: 516 " - Foo1() is called twice (profdel not invoked) 517 " - Foo2() is called once (profdel invoked after it was called) 518 " - Foo3() is not called (profdel invoked before it was called) 519 call assert_equal('FUNCTION Foo1()', lines[0]) 520 call assert_match('Defined:.*Xprofile_file.vim', lines[1]) 521 call assert_equal('Called 2 times', lines[2]) 522 call assert_equal('FUNCTION Foo2()', lines[8]) 523 call assert_equal('Called 1 time', lines[10]) 524 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[16]) 525 call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[21]) 526 527 call delete('Xprofile_file.vim') 528 call delete('Xprofile_file.log') 529endfunc 530 531func Test_profdel_star() 532 " Foo() is invoked once before and once after 'profdel *'. 533 " So profiling should report it only once. 534 let lines =<< trim [CODE] 535 profile start Xprofile_file.log 536 func! Foo() 537 endfunc 538 profile func Foo 539 call Foo() 540 profdel * 541 call Foo() 542 [CODE] 543 call writefile(lines, 'Xprofile_file.vim') 544 call system(GetVimCommandClean() . ' -es -c "so Xprofile_file.vim" -c q') 545 call assert_equal(0, v:shell_error) 546 547 let lines = readfile('Xprofile_file.log') 548 call assert_equal(16, len(lines)) 549 550 call assert_equal('FUNCTION Foo()', lines[0]) 551 call assert_match('Defined:.*Xprofile_file.vim', lines[1]) 552 call assert_equal('Called 1 time', lines[2]) 553 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[8]) 554 call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[12]) 555 556 call delete('Xprofile_file.vim') 557 call delete('Xprofile_file.log') 558endfunc 559 560" When typing the function it won't have a script ID, test that this works. 561func Test_profile_typed_func() 562 CheckScreendump 563 564 let lines =<< trim END 565 profile start XprofileTypedFunc 566 END 567 call writefile(lines, 'XtestProfile') 568 let buf = RunVimInTerminal('-S XtestProfile', #{}) 569 570 call term_sendkeys(buf, ":func DoSomething()\<CR>" 571 \ .. "echo 'hello'\<CR>" 572 \ .. "endfunc\<CR>") 573 call term_sendkeys(buf, ":profile func DoSomething\<CR>") 574 call term_sendkeys(buf, ":call DoSomething()\<CR>") 575 call TermWait(buf, 100) 576 call StopVimInTerminal(buf) 577 let lines = readfile('XprofileTypedFunc') 578 call assert_equal("FUNCTION DoSomething()", lines[0]) 579 call assert_equal("Called 1 time", lines[1]) 580 581 " clean up 582 call delete('XprofileTypedFunc') 583 call delete('XtestProfile') 584endfunc 585 586" vim: shiftwidth=2 sts=2 expandtab 587