forked from aniani/vim
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.
This commit is contained in:
parent
47a519a933
commit
b340baed9f
@ -165,6 +165,8 @@ test_override({name}, {val}) *test_override()*
|
|||||||
terminals
|
terminals
|
||||||
no_wait_return set the "no_wait_return" flag. Not restored
|
no_wait_return set the "no_wait_return" flag. Not restored
|
||||||
with "ALL".
|
with "ALL".
|
||||||
|
ui_delay time in msec to use in ui_delay(); overrules a
|
||||||
|
wait time of up to 3 seconds for messages
|
||||||
term_props reset all terminal properties when the version
|
term_props reset all terminal properties when the version
|
||||||
string is detected
|
string is detected
|
||||||
ALL clear all overrides ({val} is not used)
|
ALL clear all overrides ({val} is not used)
|
||||||
|
@ -1841,6 +1841,7 @@ EXTERN int disable_redraw_for_testing INIT(= FALSE);
|
|||||||
EXTERN int ignore_redraw_flag_for_testing INIT(= FALSE);
|
EXTERN int ignore_redraw_flag_for_testing INIT(= FALSE);
|
||||||
EXTERN int nfa_fail_for_testing INIT(= FALSE);
|
EXTERN int nfa_fail_for_testing INIT(= FALSE);
|
||||||
EXTERN int no_query_mouse_for_testing INIT(= FALSE);
|
EXTERN int no_query_mouse_for_testing INIT(= FALSE);
|
||||||
|
EXTERN int ui_delay_for_testing INIT(= 0);
|
||||||
EXTERN int reset_term_props_on_termresponse INIT(= FALSE);
|
EXTERN int reset_term_props_on_termresponse INIT(= FALSE);
|
||||||
|
|
||||||
EXTERN int in_free_unref_items INIT(= FALSE);
|
EXTERN int in_free_unref_items INIT(= FALSE);
|
||||||
|
@ -2526,4 +2526,57 @@ func Test_autocmd_sigusr1()
|
|||||||
unlet g:sigusr1_passed
|
unlet g:sigusr1_passed
|
||||||
endfunc
|
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
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@ -1486,6 +1486,7 @@ func Test_edit_InsertLeave_undo()
|
|||||||
bwipe!
|
bwipe!
|
||||||
au! InsertLeave
|
au! InsertLeave
|
||||||
call delete('XtestUndo')
|
call delete('XtestUndo')
|
||||||
|
call delete(undofile('XtestUndo'))
|
||||||
set undofile&
|
set undofile&
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
@ -1557,11 +1558,11 @@ func Test_edit_noesckeys()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test for running an invalid ex command in insert mode using CTRL-O
|
" Test for running an invalid ex command in insert mode using CTRL-O
|
||||||
" Note that vim has a hard-coded sleep of 3 seconds. So this test will take
|
|
||||||
" more than 3 seconds to complete.
|
|
||||||
func Test_edit_ctrl_o_invalid_cmd()
|
func Test_edit_ctrl_o_invalid_cmd()
|
||||||
new
|
new
|
||||||
set showmode showcmd
|
set showmode showcmd
|
||||||
|
" Avoid a sleep of 3 seconds. Zero might have side effects.
|
||||||
|
call test_override('ui_delay', 50)
|
||||||
let caught_e492 = 0
|
let caught_e492 = 0
|
||||||
try
|
try
|
||||||
call feedkeys("i\<C-O>:invalid\<CR>abc\<Esc>", "xt")
|
call feedkeys("i\<C-O>:invalid\<CR>abc\<Esc>", "xt")
|
||||||
@ -1571,7 +1572,115 @@ func Test_edit_ctrl_o_invalid_cmd()
|
|||||||
call assert_equal(1, caught_e492)
|
call assert_equal(1, caught_e492)
|
||||||
call assert_equal('abc', getline(1))
|
call assert_equal('abc', getline(1))
|
||||||
set showmode& showcmd&
|
set showmode& showcmd&
|
||||||
|
call test_override('ui_delay', 0)
|
||||||
close!
|
close!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test for editing a file with a very long name
|
||||||
|
func Test_edit_illegal_filename()
|
||||||
|
CheckEnglish
|
||||||
|
new
|
||||||
|
redir => msg
|
||||||
|
exe 'edit ' . repeat('f', 5000)
|
||||||
|
redir END
|
||||||
|
call assert_match("Illegal file name$", split(msg, "\n")[0])
|
||||||
|
close!
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test for editing a file using invalid file encoding
|
||||||
|
func Test_edit_invalid_encoding()
|
||||||
|
CheckEnglish
|
||||||
|
call writefile([], 'Xfile')
|
||||||
|
redir => msg
|
||||||
|
new ++enc=axbyc Xfile
|
||||||
|
redir END
|
||||||
|
call assert_match('\[NOT converted\]', msg)
|
||||||
|
call delete('Xfile')
|
||||||
|
close!
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test for the "charconvert" option
|
||||||
|
func Test_edit_charconvert()
|
||||||
|
CheckEnglish
|
||||||
|
call writefile(['one', 'two'], 'Xfile')
|
||||||
|
|
||||||
|
" set 'charconvert' to a non-existing function
|
||||||
|
set charconvert=NonExitingFunc()
|
||||||
|
new
|
||||||
|
let caught_e117 = v:false
|
||||||
|
try
|
||||||
|
redir => msg
|
||||||
|
edit ++enc=axbyc Xfile
|
||||||
|
catch /E117:/
|
||||||
|
let caught_e117 = v:true
|
||||||
|
finally
|
||||||
|
redir END
|
||||||
|
endtry
|
||||||
|
call assert_true(caught_e117)
|
||||||
|
call assert_equal(['one', 'two'], getline(1, '$'))
|
||||||
|
call assert_match("Conversion with 'charconvert' failed", msg)
|
||||||
|
close!
|
||||||
|
set charconvert&
|
||||||
|
|
||||||
|
" 'charconvert' function doesn't create a output file
|
||||||
|
func Cconv1()
|
||||||
|
endfunc
|
||||||
|
set charconvert=Cconv1()
|
||||||
|
new
|
||||||
|
redir => msg
|
||||||
|
edit ++enc=axbyc Xfile
|
||||||
|
redir END
|
||||||
|
call assert_equal(['one', 'two'], getline(1, '$'))
|
||||||
|
call assert_match("can't read output of 'charconvert'", msg)
|
||||||
|
close!
|
||||||
|
delfunc Cconv1
|
||||||
|
set charconvert&
|
||||||
|
|
||||||
|
" 'charconvert' function to convert to upper case
|
||||||
|
func Cconv2()
|
||||||
|
let data = readfile(v:fname_in)
|
||||||
|
call map(data, 'toupper(v:val)')
|
||||||
|
call writefile(data, v:fname_out)
|
||||||
|
endfunc
|
||||||
|
set charconvert=Cconv2()
|
||||||
|
new Xfile
|
||||||
|
write ++enc=ucase Xfile1
|
||||||
|
call assert_equal(['ONE', 'TWO'], readfile('Xfile1'))
|
||||||
|
call delete('Xfile1')
|
||||||
|
close!
|
||||||
|
delfunc Cconv2
|
||||||
|
set charconvert&
|
||||||
|
|
||||||
|
" 'charconvert' function removes the input file
|
||||||
|
func Cconv3()
|
||||||
|
call delete(v:fname_in)
|
||||||
|
endfunc
|
||||||
|
set charconvert=Cconv3()
|
||||||
|
new
|
||||||
|
call assert_fails('edit ++enc=lcase Xfile', 'E202:')
|
||||||
|
call assert_equal([''], getline(1, '$'))
|
||||||
|
close!
|
||||||
|
delfunc Cconv3
|
||||||
|
set charconvert&
|
||||||
|
|
||||||
|
call delete('Xfile')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test for editing a file without read permission
|
||||||
|
func Test_edit_file_no_read_perm()
|
||||||
|
CheckUnix
|
||||||
|
CheckNotBSD
|
||||||
|
call writefile(['one', 'two'], 'Xfile')
|
||||||
|
call setfperm('Xfile', '-w-------')
|
||||||
|
new
|
||||||
|
redir => msg
|
||||||
|
edit Xfile
|
||||||
|
redir END
|
||||||
|
call assert_equal(1, &readonly)
|
||||||
|
call assert_equal([''], getline(1, '$'))
|
||||||
|
call assert_match('\[Permission Denied\]', msg)
|
||||||
|
close!
|
||||||
|
call delete('Xfile')
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@ -143,6 +143,15 @@ func Test_file_changed_dialog()
|
|||||||
call assert_equal(1, line('$'))
|
call assert_equal(1, line('$'))
|
||||||
call assert_equal('new line', getline(1))
|
call assert_equal('new line', getline(1))
|
||||||
|
|
||||||
|
" File created after starting to edit it
|
||||||
|
call delete('Xchanged_d')
|
||||||
|
new Xchanged_d
|
||||||
|
call writefile(['one'], 'Xchanged_d')
|
||||||
|
call feedkeys('L', 'L')
|
||||||
|
checktime Xchanged_d
|
||||||
|
call assert_equal(['one'], getline(1, '$'))
|
||||||
|
close!
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
call delete('Xchanged_d')
|
call delete('Xchanged_d')
|
||||||
endfunc
|
endfunc
|
||||||
|
@ -434,4 +434,12 @@ func Test_write_readonly_dir()
|
|||||||
set backupdir& patchmode&
|
set backupdir& patchmode&
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test for writing a file using invalid file encoding
|
||||||
|
func Test_write_invalid_encoding()
|
||||||
|
new
|
||||||
|
call setline(1, 'abc')
|
||||||
|
call assert_fails('write ++enc=axbyc Xfile', 'E213:')
|
||||||
|
close!
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@ -854,6 +854,8 @@ f_test_override(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
no_query_mouse_for_testing = val;
|
no_query_mouse_for_testing = val;
|
||||||
else if (STRCMP(name, (char_u *)"no_wait_return") == 0)
|
else if (STRCMP(name, (char_u *)"no_wait_return") == 0)
|
||||||
no_wait_return = val;
|
no_wait_return = val;
|
||||||
|
else if (STRCMP(name, (char_u *)"ui_delay") == 0)
|
||||||
|
ui_delay_for_testing = val;
|
||||||
else if (STRCMP(name, (char_u *)"term_props") == 0)
|
else if (STRCMP(name, (char_u *)"term_props") == 0)
|
||||||
reset_term_props_on_termresponse = val;
|
reset_term_props_on_termresponse = val;
|
||||||
else if (STRCMP(name, (char_u *)"ALL") == 0)
|
else if (STRCMP(name, (char_u *)"ALL") == 0)
|
||||||
@ -863,6 +865,7 @@ f_test_override(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
ignore_redraw_flag_for_testing = FALSE;
|
ignore_redraw_flag_for_testing = FALSE;
|
||||||
nfa_fail_for_testing = FALSE;
|
nfa_fail_for_testing = FALSE;
|
||||||
no_query_mouse_for_testing = FALSE;
|
no_query_mouse_for_testing = FALSE;
|
||||||
|
ui_delay_for_testing = 0;
|
||||||
reset_term_props_on_termresponse = FALSE;
|
reset_term_props_on_termresponse = FALSE;
|
||||||
if (save_starting >= 0)
|
if (save_starting >= 0)
|
||||||
{
|
{
|
||||||
|
8
src/ui.c
8
src/ui.c
@ -523,8 +523,14 @@ ui_char_avail(void)
|
|||||||
* cancel the delay if a key is hit.
|
* cancel the delay if a key is hit.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ui_delay(long msec, int ignoreinput)
|
ui_delay(long msec_arg, int ignoreinput)
|
||||||
{
|
{
|
||||||
|
long msec = msec_arg;
|
||||||
|
|
||||||
|
#ifdef FEAT_EVAL
|
||||||
|
if (ui_delay_for_testing > 0)
|
||||||
|
msec = ui_delay_for_testing;
|
||||||
|
#endif
|
||||||
#ifdef FEAT_JOB_CHANNEL
|
#ifdef FEAT_JOB_CHANNEL
|
||||||
ch_log(NULL, "ui_delay(%ld)", msec);
|
ch_log(NULL, "ui_delay(%ld)", msec);
|
||||||
#endif
|
#endif
|
||||||
|
@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
982,
|
||||||
/**/
|
/**/
|
||||||
981,
|
981,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user