summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_autocmd.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-09-04 21:29:08 +0100
committerBram Moolenaar <Bram@vim.org>2022-09-04 21:29:08 +0100
commite1f3ab73bc7c4b3eee03b673c2983ed7eca6ea80 (patch)
tree1f99f6b4b97dce107b1fb8b311db7cbc21c9a541 /src/testdir/test_autocmd.vim
parent8f7116caddc6f0725cf1211407d97645c4eb7b65 (diff)
patch 9.0.0380: deleting files in tests is a hassle
Problem: Deleting files in tests is a hassle. Solution: Use the new 'D' flag of writefile().
Diffstat (limited to 'src/testdir/test_autocmd.vim')
-rw-r--r--src/testdir/test_autocmd.vim103
1 files changed, 37 insertions, 66 deletions
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 0072e3d0d8..028e3d22e7 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -24,12 +24,12 @@ endfunc
" Test for the CursorHold autocmd
func Test_CursorHold_autocmd()
CheckRunVimInTerminal
- call writefile(['one', 'two', 'three'], 'XoneTwoThree')
+ call writefile(['one', 'two', 'three'], 'XoneTwoThree', 'D')
let before =<< trim END
set updatetime=10
au CursorHold * call writefile([line('.')], 'XCHoutput', 'a')
END
- call writefile(before, 'XCHinit')
+ call writefile(before, 'XCHinit', 'D')
let buf = RunVimInTerminal('-S XCHinit XoneTwoThree', {})
call term_sendkeys(buf, "G")
call term_wait(buf, 50)
@@ -44,9 +44,7 @@ func Test_CursorHold_autocmd()
call WaitForAssert({-> assert_equal(['1', '2', '3'], readfile('XCHoutput')[-3:-1])})
call StopVimInTerminal(buf)
- call delete('XCHinit')
call delete('XCHoutput')
- call delete('XoneTwoThree')
endfunc
if has('timers')
@@ -124,7 +122,7 @@ if has('timers')
augroup set_tabstop
au OptionSet tabstop call timer_start(1, {-> execute("echo 'Handler called'", "")})
augroup END
- call writefile(['vim: set ts=7 sw=5 :', 'something'], 'XoptionsetModeline')
+ call writefile(['vim: set ts=7 sw=5 :', 'something'], 'XoptionsetModeline', 'D')
set modeline
let v:errmsg = ''
call assert_fails('split XoptionsetModeline', 'E12:')
@@ -136,7 +134,6 @@ if has('timers')
augroup END
bwipe!
set ts&
- call delete('XoptionsetModeline')
call test_override('starting', 0)
endfunc
@@ -246,8 +243,8 @@ endfunc
func Test_autocmd_dummy_wipeout()
" prepare files
- call writefile([''], 'Xdummywipetest1.txt')
- call writefile([''], 'Xdummywipetest2.txt')
+ call writefile([''], 'Xdummywipetest1.txt', 'D')
+ call writefile([''], 'Xdummywipetest2.txt', 'D')
augroup test_bufunload_group
autocmd!
autocmd BufUnload * call add(s:li, "bufunload")
@@ -261,8 +258,6 @@ func Test_autocmd_dummy_wipeout()
call assert_equal(["bufunload", "bufwipeout"], s:li)
bwipeout
- call delete('Xdummywipetest1.txt')
- call delete('Xdummywipetest2.txt')
au! test_bufunload_group
augroup! test_bufunload_group
endfunc
@@ -326,7 +321,7 @@ func Test_WinScrolled()
au WinScrolled * let g:amatch = str2nr(expand('<amatch>'))
au WinScrolled * let g:afile = str2nr(expand('<afile>'))
END
- call writefile(lines, 'Xtest_winscrolled')
+ call writefile(lines, 'Xtest_winscrolled', 'D')
let buf = RunVimInTerminal('-S Xtest_winscrolled', {'rows': 6})
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
@@ -361,7 +356,6 @@ func Test_WinScrolled()
call WaitForAssert({-> assert_match('^v:true ', term_getline(buf, 6))}, 1000)
call StopVimInTerminal(buf)
- call delete('Xtest_winscrolled')
endfunc
func Test_WinScrolled_mouse()
@@ -375,7 +369,7 @@ func Test_WinScrolled_mouse()
let g:scrolled = 0
au WinScrolled * let g:scrolled += 1
END
- call writefile(lines, 'Xtest_winscrolled_mouse')
+ call writefile(lines, 'Xtest_winscrolled_mouse', 'D')
let buf = RunVimInTerminal('-S Xtest_winscrolled_mouse', {'rows': 10})
" With the upper split focused, send a scroll-down event to the unfocused one.
@@ -392,7 +386,6 @@ func Test_WinScrolled_mouse()
call WaitForAssert({-> assert_match('^2', term_getline(buf, 10))}, 1000)
call StopVimInTerminal(buf)
- call delete('Xtest_winscrolled_mouse')
endfunc
func Test_WinScrolled_close_curwin()
@@ -405,7 +398,7 @@ func Test_WinScrolled_close_curwin()
au WinScrolled * close
au VimLeave * call writefile(['123456'], 'Xtestout')
END
- call writefile(lines, 'Xtest_winscrolled_close_curwin')
+ call writefile(lines, 'Xtest_winscrolled_close_curwin', 'D')
let buf = RunVimInTerminal('-S Xtest_winscrolled_close_curwin', {'rows': 6})
" This was using freed memory
@@ -415,7 +408,6 @@ func Test_WinScrolled_close_curwin()
call assert_equal(['123456'], readfile('Xtestout'))
- call delete('Xtest_winscrolled_close_curwin')
call delete('Xtestout')
endfunc
@@ -431,7 +423,7 @@ func Test_WinScrolled_long_wrapped()
call setline(1, repeat('foo', height * width))
call cursor(1, height * width)
END
- call writefile(lines, 'Xtest_winscrolled_long_wrapped')
+ call writefile(lines, 'Xtest_winscrolled_long_wrapped', 'D')
let buf = RunVimInTerminal('-S Xtest_winscrolled_long_wrapped', {'rows': 6})
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
@@ -448,8 +440,6 @@ func Test_WinScrolled_long_wrapped()
call term_sendkeys(buf, '$')
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
call WaitForAssert({-> assert_match('^3 ', term_getline(buf, 6))}, 1000)
-
- call delete('Xtest_winscrolled_long_wrapped')
endfunc
func Test_WinClosed()
@@ -772,13 +762,13 @@ func Test_autocmd_bufwipe_in_SessLoadPost()
au VimLeave * call WriteErrors()
[CODE]
- call writefile(content, 'Xvimrc')
+ call writefile(content, 'Xvimrc', 'D')
call system(GetVimCommand('Xvimrc') .. ' --not-a-term --noplugins -S Session.vim -c cq')
let errors = join(readfile('Xerrors'))
call assert_match('E814:', errors)
set swapfile
- for file in ['Session.vim', 'Xvimrc', 'Xerrors']
+ for file in ['Session.vim', 'Xerrors']
call delete(file)
endfor
endfunc
@@ -795,11 +785,10 @@ func Test_autocmd_blast_badd()
qall
[CODE]
- call writefile(content, 'XblastBall')
+ call writefile(content, 'XblastBall', 'D')
call system(GetVimCommand() .. ' --clean -S XblastBall')
call assert_match('OK', readfile('Xerrors')->join())
- call delete('XblastBall')
call delete('Xerrors')
endfunc
@@ -832,7 +821,7 @@ func Test_autocmd_bufwipe_in_SessLoadPost2()
au VimLeave * call WriteErrors()
[CODE]
- call writefile(content, 'Xvimrc')
+ call writefile(content, 'Xvimrc', 'D')
call system(GetVimCommand('Xvimrc') .. ' --not-a-term --noplugins -S Session.vim -c cq')
let errors = join(readfile('Xerrors'))
" This probably only ever matches on unix.
@@ -840,7 +829,7 @@ func Test_autocmd_bufwipe_in_SessLoadPost2()
call assert_match('SessionLoadPost DONE', errors)
set swapfile
- for file in ['Session.vim', 'Xvimrc', 'Xerrors']
+ for file in ['Session.vim', 'Xerrors']
call delete(file)
endfor
endfunc
@@ -1542,9 +1531,9 @@ endfunc
func Test_Acmd_BufAll()
enew!
%bwipe!
- call writefile(['Test file Xxx1'], 'Xxx1')
- call writefile(['Test file Xxx2'], 'Xxx2')
- call writefile(['Test file Xxx3'], 'Xxx3')
+ call writefile(['Test file Xxx1'], 'Xxx1', 'D')
+ call writefile(['Test file Xxx2'], 'Xxx2', 'D')
+ call writefile(['Test file Xxx3'], 'Xxx3', 'D')
" Add three files to the buffer list
split Xxx1
@@ -1566,9 +1555,6 @@ func Test_Acmd_BufAll()
au! BufReadPost
%bwipe!
- call delete('Xxx1')
- call delete('Xxx2')
- call delete('Xxx3')
enew! | only
endfunc
@@ -1578,11 +1564,11 @@ func Test_Acmd_BufEnter()
%bwipe!
call writefile(['start of test file Xxx1',
\ "\<Tab>this is a test",
- \ 'end of test file Xxx1'], 'Xxx1')
+ \ 'end of test file Xxx1'], 'Xxx1', 'D')
call writefile(['start of test file Xxx2',
\ 'vim: set noai :',
\ "\<Tab>this is a test",
- \ 'end of test file Xxx2'], 'Xxx2')
+ \ 'end of test file Xxx2'], 'Xxx2', 'D')
au BufEnter Xxx2 brew
set ai modeline modelines=3
@@ -1604,8 +1590,6 @@ func Test_Acmd_BufEnter()
call assert_equal(4, line('.'))
%bwipe!
- call delete('Xxx1')
- call delete('Xxx2')
set ai&vim modeline&vim modelines&vim
endfunc
@@ -1632,8 +1616,8 @@ func Test_BufLeave_Wipe()
let content = ['start of test file Xxx',
\ 'this is a test',
\ 'end of test file Xxx']
- call writefile(content, 'Xxx1')
- call writefile(content, 'Xxx2')
+ call writefile(content, 'Xxx1', 'D')
+ call writefile(content, 'Xxx2', 'D')
au BufLeave Xxx2 bwipe
edit Xxx1
@@ -1659,8 +1643,6 @@ func Test_BufLeave_Wipe()
let g:bufinfo = getbufinfo()
call assert_equal(1, len(g:bufinfo))
- call delete('Xxx1')
- call delete('Xxx2')
call delete('test.out')
%bwipe
au! BufLeave
@@ -1729,8 +1711,8 @@ func Test_BufWritePre()
au BufWritePre Xxx1 bunload
au BufWritePre Xxx2 bwipe
- call writefile(['start of Xxx1', 'test', 'end of Xxx1'], 'Xxx1')
- call writefile(['start of Xxx2', 'test', 'end of Xxx2'], 'Xxx2')
+ call writefile(['start of Xxx1', 'test', 'end of Xxx1'], 'Xxx1', 'D')
+ call writefile(['start of Xxx2', 'test', 'end of Xxx2'], 'Xxx2', 'D')
edit Xtest
e! Xxx2
@@ -1746,15 +1728,13 @@ func Test_BufWritePre()
call assert_fails('w', 'E203:')
call assert_equal('Xxx1', bufname('%'))
au! BufWritePre
- call delete('Xxx1')
- call delete('Xxx2')
endfunc
" Test for BufUnload autocommand that unloads all the other buffers
func Test_bufunload_all()
let g:test_is_flaky = 1
- call writefile(['Test file Xxx1'], 'Xxx1')"
- call writefile(['Test file Xxx2'], 'Xxx2')"
+ call writefile(['Test file Xxx1'], 'Xxx1', 'D')"
+ call writefile(['Test file Xxx2'], 'Xxx2', 'D')"
let content =<< trim [CODE]
func UnloadAllBufs()
@@ -1773,15 +1753,12 @@ func Test_bufunload_all()
q
[CODE]
- call writefile(content, 'Xtest')
+ call writefile(content, 'Xbunloadtest', 'D')
call delete('Xout')
- call system(GetVimCommandClean() .. ' -N --not-a-term -S Xtest')
+ call system(GetVimCommandClean() .. ' -N --not-a-term -S Xbunloadtest')
call assert_true(filereadable('Xout'))
- call delete('Xxx1')
- call delete('Xxx2')
- call delete('Xtest')
call delete('Xout')
endfunc
@@ -1809,7 +1786,7 @@ endfunc
" Test for "*Cmd" autocommands
func Test_Cmd_Autocmds()
- call writefile(['start of Xxx', "\tabc2", 'end of Xxx'], 'Xxx')
+ call writefile(['start of Xxx', "\tabc2", 'end of Xxx'], 'Xxx', 'D')
enew!
au BufReadCmd XtestA 0r Xxx|$del
@@ -1884,7 +1861,6 @@ func Test_Cmd_Autocmds()
au! FileWriteCmd
au! FileAppendCmd
%bwipe!
- call delete('Xxx')
enew!
endfunc
@@ -1909,7 +1885,7 @@ func Test_BufReadCmd()
autocmd BufReadCmd *.test call s:ReadFile()
autocmd BufWriteCmd *.test call s:WriteFile()
- call writefile(['one', 'two', 'three'], 'Xcmd.test')
+ call writefile(['one', 'two', 'three'], 'Xcmd.test', 'D')
edit Xcmd.test
call assert_match('Xcmd.test" line 1 of 3', execute('file'))
normal! Gofour
@@ -1917,7 +1893,6 @@ func Test_BufReadCmd()
call assert_equal(['one', 'two', 'three', 'four'], readfile('Xcmd.test'))
bwipe!
- call delete('Xcmd.test')
au! BufReadCmd
au! BufWriteCmd
endfunc
@@ -2324,7 +2299,7 @@ func Test_Changed_FirstTime()
let g:test_is_flaky = 1
" Prepare file for TextChanged event.
- call writefile([''], 'Xchanged.txt')
+ call writefile([''], 'Xchanged.txt', 'D')
let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3})
call assert_equal('running', term_getstatus(buf))
" Wait for the ruler (in the status line) to be shown.
@@ -2342,7 +2317,6 @@ func Test_Changed_FirstTime()
call assert_equal([''], readfile('Xchanged.txt'))
" clean up
- call delete('Xchanged.txt')
bwipe!
endfunc
@@ -2432,13 +2406,12 @@ func Test_autocmd_nested_switch_window()
autocmd BufReadPost * autocmd SafeState * ++once foldclosed('.')
autocmd WinEnter * matchadd('ErrorMsg', 'pat')
END
- call writefile(lines, 'Xautoscript')
+ call writefile(lines, 'Xautoscript', 'D')
let buf = RunVimInTerminal('-S Xautoscript', {'rows': 10})
call VerifyScreenDump(buf, 'Test_autocmd_nested_switch', {})
call StopVimInTerminal(buf)
call delete('Xautofile')
- call delete('Xautoscript')
endfunc
func Test_autocmd_once()
@@ -2590,7 +2563,7 @@ func Test_ReadWrite_Autocmds()
au FileAppendPost *.out !cat Xtest.c >> test.out
augroup END
- call writefile(['/*', ' * Here is a new .c file', ' */'], 'Xtest.c')
+ call writefile(['/*', ' * Here is a new .c file', ' */'], 'Xtest.c', 'D')
new foo.c " should load Xtest.c
call assert_equal(['/*', ' * Here is a new .c file', ' */'], getline(2, 4))
w! >> test.out " append it to the output file
@@ -2714,7 +2687,6 @@ func Test_ReadWrite_Autocmds()
au! FileChangedShell
call delete('Xtestfile.gz')
- call delete('Xtest.c')
call delete('test.out')
endfunc
@@ -2762,7 +2734,7 @@ func Test_autocmd_SafeState()
call timer_start(10, {id -> execute('let g:again ..= "t"')})
endfunc
END
- call writefile(lines, 'XSafeState')
+ call writefile(lines, 'XSafeState', 'D')
let buf = RunVimInTerminal('-S XSafeState', #{rows: 6})
" Sometimes we loop to handle a K_IGNORE, SafeState may be triggered once or
@@ -2782,7 +2754,6 @@ func Test_autocmd_SafeState()
call WaitForAssert({-> assert_match('xtx', term_getline(buf, 6))}, 1000)
call StopVimInTerminal(buf)
- call delete('XSafeState')
endfunc
func Test_autocmd_CmdWinEnter()
@@ -3024,11 +2995,11 @@ func Test_BufReadPre_delfile()
au!
autocmd BufReadPre XbufreadPre call delete('XbufreadPre')
augroup END
- call writefile([], 'XbufreadPre')
+ call writefile([], 'XbufreadPre', 'D')
call assert_fails('new XbufreadPre', 'E200:')
call assert_equal('XbufreadPre', @%)
call assert_equal(1, &readonly)
- call delete('XbufreadPre')
+
augroup TestAuCmd
au!
augroup END
@@ -3041,11 +3012,11 @@ func Test_BufReadPre_changebuf()
au!
autocmd BufReadPre Xchangebuf edit Xsomeotherfile
augroup END
- call writefile([], 'Xchangebuf')
+ call writefile([], 'Xchangebuf', 'D')
call assert_fails('new Xchangebuf', 'E201:')
call assert_equal('Xsomeotherfile', @%)
call assert_equal(1, &readonly)
- call delete('Xchangebuf')
+
augroup TestAuCmd
au!
augroup END