comparison src/testdir/test_autocmd.vim @ 16720:9c90cf08cfa8 v8.1.1362

patch 8.1.1362: code and data in tests can be hard to read commit https://github.com/vim/vim/commit/c79745a82faeb5a6058e915ca49a4c69fa60ea01 Author: Bram Moolenaar <Bram@vim.org> Date: Mon May 20 22:12:34 2019 +0200 patch 8.1.1362: code and data in tests can be hard to read Problem: Code and data in tests can be hard to read. Solution: Use the new heredoc style. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/4400)
author Bram Moolenaar <Bram@vim.org>
date Mon, 20 May 2019 22:15:06 +0200
parents ea0f9a2df961
children 620e9011b685
comparison
equal deleted inserted replaced
16719:27f2a2799604 16720:9c90cf08cfa8
421 tabnew 421 tabnew
422 file Xsomething 422 file Xsomething
423 set noswapfile 423 set noswapfile
424 mksession! 424 mksession!
425 425
426 let content = ['set nocp noswapfile', 426 let content =<< trim [CODE]
427 \ 'let v:swapchoice="e"', 427 set nocp noswapfile
428 \ 'augroup test_autocmd_sessionload', 428 let v:swapchoice="e"
429 \ 'autocmd!', 429 augroup test_autocmd_sessionload
430 \ 'autocmd SessionLoadPost * exe bufnr("Xsomething") . "bw!"', 430 autocmd!
431 \ 'augroup END', 431 autocmd SessionLoadPost * exe bufnr("Xsomething") . "bw!"
432 \ '', 432 augroup END
433 \ 'func WriteErrors()', 433
434 \ ' call writefile([execute("messages")], "Xerrors")', 434 func WriteErrors()
435 \ 'endfunc', 435 call writefile([execute("messages")], "Xerrors")
436 \ 'au VimLeave * call WriteErrors()', 436 endfunc
437 \ ] 437 au VimLeave * call WriteErrors()
438 [CODE]
439
438 call writefile(content, 'Xvimrc') 440 call writefile(content, 'Xvimrc')
439 call system(v:progpath. ' -u Xvimrc --not-a-term --noplugins -S Session.vim -c cq') 441 call system(v:progpath. ' -u Xvimrc --not-a-term --noplugins -S Session.vim -c cq')
440 let errors = join(readfile('Xerrors')) 442 let errors = join(readfile('Xerrors'))
441 call assert_match('E814', errors) 443 call assert_match('E814', errors)
442 444
450 func Test_autocmd_bufwipe_in_SessLoadPost2() 452 func Test_autocmd_bufwipe_in_SessLoadPost2()
451 tabnew 453 tabnew
452 set noswapfile 454 set noswapfile
453 mksession! 455 mksession!
454 456
455 let content = ['set nocp noswapfile', 457 let content =<< trim [CODE]
456 \ 'function! DeleteInactiveBufs()', 458 set nocp noswapfile
457 \ ' tabfirst', 459 function! DeleteInactiveBufs()
458 \ ' let tabblist = []', 460 tabfirst
459 \ ' for i in range(1, tabpagenr(''$''))', 461 let tabblist = []
460 \ ' call extend(tabblist, tabpagebuflist(i))', 462 for i in range(1, tabpagenr(''$''))
461 \ ' endfor', 463 call extend(tabblist, tabpagebuflist(i))
462 \ ' for b in range(1, bufnr(''$''))', 464 endfor
463 \ ' if bufexists(b) && buflisted(b) && (index(tabblist, b) == -1 || bufname(b) =~# ''^$'')', 465 for b in range(1, bufnr(''$''))
464 \ ' exec ''bwipeout '' . b', 466 if bufexists(b) && buflisted(b) && (index(tabblist, b) == -1 || bufname(b) =~# ''^$'')
465 \ ' endif', 467 exec ''bwipeout '' . b
466 \ ' endfor', 468 endif
467 \ ' echomsg "SessionLoadPost DONE"', 469 endfor
468 \ 'endfunction', 470 echomsg "SessionLoadPost DONE"
469 \ 'au SessionLoadPost * call DeleteInactiveBufs()', 471 endfunction
470 \ '', 472 au SessionLoadPost * call DeleteInactiveBufs()
471 \ 'func WriteErrors()', 473
472 \ ' call writefile([execute("messages")], "Xerrors")', 474 func WriteErrors()
473 \ 'endfunc', 475 call writefile([execute("messages")], "Xerrors")
474 \ 'au VimLeave * call WriteErrors()', 476 endfunc
475 \ ] 477 au VimLeave * call WriteErrors()
478 [CODE]
479
476 call writefile(content, 'Xvimrc') 480 call writefile(content, 'Xvimrc')
477 call system(v:progpath. ' -u Xvimrc --not-a-term --noplugins -S Session.vim -c cq') 481 call system(v:progpath. ' -u Xvimrc --not-a-term --noplugins -S Session.vim -c cq')
478 let errors = join(readfile('Xerrors')) 482 let errors = join(readfile('Xerrors'))
479 " This probably only ever matches on unix. 483 " This probably only ever matches on unix.
480 call assert_notmatch('Caught deadly signal SEGV', errors) 484 call assert_notmatch('Caught deadly signal SEGV', errors)
931 " Test for BufUnload autocommand that unloads all the other buffers 935 " Test for BufUnload autocommand that unloads all the other buffers
932 func Test_bufunload_all() 936 func Test_bufunload_all()
933 call writefile(['Test file Xxx1'], 'Xxx1')" 937 call writefile(['Test file Xxx1'], 'Xxx1')"
934 call writefile(['Test file Xxx2'], 'Xxx2')" 938 call writefile(['Test file Xxx2'], 'Xxx2')"
935 939
936 let content = [ 940 let content =<< trim [CODE]
937 \ "func UnloadAllBufs()", 941 func UnloadAllBufs()
938 \ " let i = 1", 942 let i = 1
939 \ " while i <= bufnr('$')", 943 while i <= bufnr('$')
940 \ " if i != bufnr('%') && bufloaded(i)", 944 if i != bufnr('%') && bufloaded(i)
941 \ " exe i . 'bunload'", 945 exe i . 'bunload'
942 \ " endif", 946 endif
943 \ " let i += 1", 947 let i += 1
944 \ " endwhile", 948 endwhile
945 \ "endfunc", 949 endfunc
946 \ "au BufUnload * call UnloadAllBufs()", 950 au BufUnload * call UnloadAllBufs()
947 \ "au VimLeave * call writefile(['Test Finished'], 'Xout')", 951 au VimLeave * call writefile(['Test Finished'], 'Xout')
948 \ "edit Xxx1", 952 edit Xxx1
949 \ "split Xxx2", 953 split Xxx2
950 \ "q"] 954 q
955 [CODE]
956
951 call writefile(content, 'Xtest') 957 call writefile(content, 'Xtest')
952 958
953 call delete('Xout') 959 call delete('Xout')
954 call system(v:progpath. ' --clean -N --not-a-term -S Xtest') 960 call system(v:progpath. ' --clean -N --not-a-term -S Xtest')
955 call assert_true(filereadable('Xout')) 961 call assert_true(filereadable('Xout'))