Skip to content

Commit ee4e0c1

Browse files
committed
patch 8.2.0522: several errors are not tested for
Problem: Several errors are not tested for. Solution: Add tests. (Yegappan Lakshmanan, closes #5892)
1 parent 15352dc commit ee4e0c1

21 files changed

Lines changed: 243 additions & 41 deletions

src/testdir/test_autocmd.vim

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,4 +2483,28 @@ func Test_autocmd_FileReadCmd()
24832483
delfunc ReadFileCmd
24842484
endfunc
24852485

2486+
" Test for passing invalid arguments to autocmd
2487+
func Test_autocmd_invalid_args()
2488+
" Additional character after * for event
2489+
call assert_fails('autocmd *a Xfile set ff=unix', 'E215:')
2490+
augroup Test
2491+
augroup END
2492+
" Invalid autocmd event
2493+
call assert_fails('autocmd Bufabc Xfile set ft=vim', 'E216:')
2494+
" Invalid autocmd event in a autocmd group
2495+
call assert_fails('autocmd Test Bufabc Xfile set ft=vim', 'E216:')
2496+
augroup! Test
2497+
" Execute all autocmds
2498+
call assert_fails('doautocmd * BufEnter', 'E217:')
2499+
call assert_fails('augroup! x1a2b3', 'E367:')
2500+
call assert_fails('autocmd BufNew <buffer=999> pwd', 'E680:')
2501+
endfunc
2502+
2503+
" Test for deep nesting of autocmds
2504+
func Test_autocmd_deep_nesting()
2505+
autocmd BufEnter Xfile doautocmd BufEnter Xfile
2506+
call assert_fails('doautocmd BufEnter Xfile', 'E218:')
2507+
autocmd! BufEnter Xfile
2508+
endfunc
2509+
24862510
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_clientserver.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
source check.vim
44
CheckFeature job
5+
6+
if !has('clientserver')
7+
call assert_fails('call remote_startserver("local")', 'E942:')
8+
endif
9+
510
CheckFeature clientserver
611

712
source shared.vim
@@ -161,6 +166,7 @@ func Test_client_server()
161166

162167
call assert_fails("let x = remote_peek([])", 'E730:')
163168
call assert_fails("let x = remote_read('vim10')", 'E277:')
169+
call assert_fails("call server2client('abc', 'xyz')", 'E258:')
164170
endfunc
165171

166172
" Uncomment this line to get a debugging log

src/testdir/test_digraph.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ func Test_digraphs()
210210
call Put_Dig("00")
211211
call Put_Dig("el")
212212
call assert_equal(['', 'ü', '', 'l'], getline(line('.')-3,line('.')))
213+
call assert_fails('exe "digraph a\<Esc> 100"', 'E104:')
214+
call assert_fails('exe "digraph \<Esc>a 100"', 'E104:')
213215
bw!
214216
endfunc
215217

@@ -475,4 +477,15 @@ func Test_show_digraph_cp1251()
475477
bwipe!
476478
endfunc
477479

480+
" Test for error in a keymap file
481+
func Test_loadkeymap_error()
482+
if !has('keymap')
483+
return
484+
endif
485+
call assert_fails('loadkeymap', 'E105:')
486+
call writefile(['loadkeymap', 'a'], 'Xkeymap')
487+
call assert_fails('source Xkeymap', 'E791:')
488+
call delete('Xkeymap')
489+
endfunc
490+
478491
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_expand.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func Test_expand_filename_multicmd()
131131
call assert_equal(4, winnr('$'))
132132
call assert_equal('foo!', bufname(winbufnr(1)))
133133
call assert_equal('foo', bufname(winbufnr(2)))
134+
call assert_fails('e %:s/.*//', 'E500:')
134135
%bwipe!
135136
endfunc
136137

src/testdir/test_expr.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ func Test_funcref()
502502
call assert_fails('echo funcref("{")', 'E475:')
503503
let OneByRef = funcref("One", repeat(["foo"], 20))
504504
call assert_fails('let OneByRef = funcref("One", repeat(["foo"], 21))', 'E118:')
505+
call assert_fails('echo function("min") =~ function("min")', 'E694:')
505506
endfunc
506507

507508
func Test_setmatches()

src/testdir/test_functions.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,7 @@ func Test_range()
19661966
execute "normal! a\<C-r>=[complete(col('.'), range(10)), ''][1]\<CR>"
19671967
" complete_info()
19681968
execute "normal! a\<C-r>=[complete(col('.'), range(10)), ''][1]\<CR>\<C-r>=[complete_info(range(5)), ''][1]\<CR>"
1969+
call assert_fails('call complete(1, ["a"])', 'E785:')
19691970

19701971
" copy()
19711972
call assert_equal([1, 2, 3], copy(range(1, 3)))

src/testdir/test_gui.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ func Test_set_guifont()
388388
call assert_equal('Monospace 10', getfontname())
389389
endif
390390

391+
if has('win32')
392+
" Invalid font names are accepted in GTK GUI
393+
call assert_fails('set guifont=xa1bc23d7f', 'E596:')
394+
endif
395+
391396
if has('xfontset')
392397
let &guifontset = guifontset_saved
393398
endif
@@ -402,6 +407,8 @@ func Test_set_guifontset()
402407
CheckFeature xfontset
403408
let skipped = ''
404409

410+
call assert_fails('set guifontset=*', 'E597:')
411+
405412
let ctype_saved = v:ctype
406413

407414
" First, since XCreateFontSet(3) is very sensitive to locale, fonts must
@@ -468,6 +475,7 @@ func Test_set_guifontset()
468475
endfunc
469476

470477
func Test_set_guifontwide()
478+
call assert_fails('set guifontwide=*', 'E533:')
471479
let skipped = ''
472480

473481
if !g:x11_based_gui
@@ -785,6 +793,7 @@ func Test_set_term()
785793
" It's enough to check the current value since setting 'term' to anything
786794
" other than builtin_gui makes no sense at all.
787795
call assert_equal('builtin_gui', &term)
796+
call assert_fails('set term=xterm', 'E530:')
788797
endfunc
789798

790799
func Test_windowid_variable()

src/testdir/test_highlight.vim

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,28 @@ func Test_1_highlight_Normalgroup_exists()
689689
endfunc
690690

691691
" Do this test last, sometimes restoring the columns doesn't work
692-
function Test_z_no_space_before_xxx()
692+
func Test_z_no_space_before_xxx()
693693
let l:org_columns = &columns
694694
set columns=17
695695
let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
696696
call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
697697
let &columns = l:org_columns
698-
endfunction
698+
endfunc
699+
700+
" Test for :highlight command errors
701+
func Test_highlight_cmd_errors()
702+
if has('gui_running')
703+
" This test doesn't fail in the MS-Windows console version.
704+
call assert_fails('hi Xcomment ctermfg=fg', 'E419:')
705+
call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
706+
endif
707+
708+
" Try using a very long terminal code. Define a dummy terminal code for this
709+
" test.
710+
let &t_fo = "\<Esc>1;"
711+
let c = repeat("t_fo,", 100) . "t_fo"
712+
call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
713+
let &t_fo = ""
714+
endfunc
715+
716+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_ins_complete.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,23 @@ func Test_ins_compl_tag_sft()
465465
set tags&
466466
%bwipe!
467467
endfunc
468+
469+
" Test for 'completefunc' deleting text
470+
func Test_completefunc_error()
471+
new
472+
func CompleteFunc(findstart, base)
473+
if a:findstart == 1
474+
normal dd
475+
return col('.') - 1
476+
endif
477+
return ['a', 'b']
478+
endfunc
479+
set completefunc=CompleteFunc
480+
call setline(1, ['', 'abcd', ''])
481+
call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E840:')
482+
set completefunc&
483+
delfunc CompleteFunc
484+
close!
485+
endfunc
486+
487+
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_lambda.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,20 @@ func Test_lambda_error()
311311
call assert_fails('ec{@{->{d->()()', 'E15')
312312
endfunc
313313

314+
func Test_closure_error()
315+
let l =<< trim END
316+
func F1() closure
317+
return 1
318+
endfunc
319+
END
320+
call writefile(l, 'Xscript')
321+
let caught_932 = 0
322+
try
323+
source Xscript
324+
catch /E932:/
325+
let caught_932 = 1
326+
endtry
327+
call assert_equal(1, caught_932)
328+
endfunc
329+
314330
" vim: shiftwidth=2 sts=2 expandtab

0 commit comments

Comments
 (0)