patch 8.2.0982: insufficient testing for reading/writing files
Problem: Insufficient testing for reading/writing files.
Solution: Add more tests. (Yegappan Lakshmanan, closes #6257)
Add "ui_delay" to test_override() and use it for the CTRL-O test.
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index cd3559e..ffeaeca 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -2526,4 +2526,57 @@
unlet g:sigusr1_passed
endfunc
+" Test for BufReadPre autocmd deleting the file
+func Test_BufReadPre_delfile()
+ augroup TestAuCmd
+ au!
+ autocmd BufReadPre Xfile call delete('Xfile')
+ augroup END
+ call writefile([], 'Xfile')
+ call assert_fails('new Xfile', 'E200:')
+ call assert_equal('Xfile', @%)
+ call assert_equal(1, &readonly)
+ call delete('Xfile')
+ augroup TestAuCmd
+ au!
+ augroup END
+ close!
+endfunc
+
+" Test for BufReadPre autocmd changing the current buffer
+func Test_BufReadPre_changebuf()
+ augroup TestAuCmd
+ au!
+ autocmd BufReadPre Xfile edit Xsomeotherfile
+ augroup END
+ call writefile([], 'Xfile')
+ call assert_fails('new Xfile', 'E201:')
+ call assert_equal('Xsomeotherfile', @%)
+ call assert_equal(1, &readonly)
+ call delete('Xfile')
+ augroup TestAuCmd
+ au!
+ augroup END
+ close!
+endfunc
+
+" Test for BufWipeouti autocmd changing the current buffer when reading a file
+" in an empty buffer with 'f' flag in 'cpo'
+func Test_BufDelete_changebuf()
+ new
+ augroup TestAuCmd
+ au!
+ autocmd BufWipeout * let bufnr = bufadd('somefile') | exe "b " .. bufnr
+ augroup END
+ let save_cpo = &cpo
+ set cpo+=f
+ call assert_fails('r Xfile', 'E484:')
+ call assert_equal('somefile', @%)
+ let &cpo = save_cpo
+ augroup TestAuCmd
+ au!
+ augroup END
+ close!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab