Skip to content

Commit 818fc9a

Browse files
committed
patch 8.2.0293: various Ex commands not sufficiently tested
Problem: Various Ex commands not sufficiently tested. Solution: Add more test cases. (Yegappan Lakshmanan, closes #5673)
1 parent 09f28f4 commit 818fc9a

14 files changed

+198
-7
lines changed

src/testdir/test_arglist.vim

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,10 @@ func Test_quit_with_arglist()
515515
throw 'Skipped: cannot run vim in terminal'
516516
endif
517517
let buf = RunVimInTerminal('', {'rows': 6})
518+
call term_sendkeys(buf, ":set nomore\n")
518519
call term_sendkeys(buf, ":args a b c\n")
519520
call term_sendkeys(buf, ":quit\n")
521+
call term_wait(buf)
520522
call WaitForAssert({-> assert_match('^E173:', term_getline(buf, 6))})
521523
call StopVimInTerminal(buf)
522524

@@ -525,14 +527,18 @@ func Test_quit_with_arglist()
525527
call term_sendkeys(buf, ":set nomore\n")
526528
call term_sendkeys(buf, ":args a b c\n")
527529
call term_sendkeys(buf, ":confirm quit\n")
530+
call term_wait(buf)
528531
call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
529532
\ term_getline(buf, 6))})
530533
call term_sendkeys(buf, "N")
534+
call term_wait(buf)
531535
call term_sendkeys(buf, ":confirm quit\n")
532536
call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
533537
\ term_getline(buf, 6))})
534538
call term_sendkeys(buf, "Y")
535-
call StopVimInTerminal(buf)
539+
call term_wait(buf)
540+
call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))})
541+
only!
536542
endfunc
537543

538544
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_cmdline.vim

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,4 +977,33 @@ func Test_cmd_backtick()
977977
%argd
978978
endfunc
979979

980+
" Test for the :! command
981+
func Test_cmd_bang()
982+
if !has('unix')
983+
return
984+
endif
985+
986+
let lines =<< trim [SCRIPT]
987+
" Test for no previous command
988+
call assert_fails('!!', 'E34:')
989+
set nomore
990+
" Test for cmdline expansion with :!
991+
call setline(1, 'foo!')
992+
silent !echo <cWORD> > Xfile.out
993+
call assert_equal(['foo!'], readfile('Xfile.out'))
994+
" Test for using previous command
995+
silent !echo \! !
996+
call assert_equal(['! echo foo!'], readfile('Xfile.out'))
997+
call writefile(v:errors, 'Xresult')
998+
call delete('Xfile.out')
999+
qall!
1000+
[SCRIPT]
1001+
call writefile(lines, 'Xscript')
1002+
if RunVim([], [], '--clean -S Xscript')
1003+
call assert_equal([], readfile('Xresult'))
1004+
endif
1005+
call delete('Xscript')
1006+
call delete('Xresult')
1007+
endfunc
1008+
9801009
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_ex_mode.vim

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,14 @@ func Test_open_command()
111111
close!
112112
endfunc
113113

114-
func Test_Ex_feedkeys()
115-
" this doesn't do anything useful, just check it doesn't hang
114+
" Test for :g/pat/visual to run vi commands in Ex mode
115+
" This used to hang Vim before 8.2.0274.
116+
func Test_Ex_global()
116117
new
117-
call setline(1, ["foo"])
118-
call feedkeys("Qg/foo/visual\<CR>", "xt")
118+
call setline(1, ['', 'foo', 'bar', 'foo', 'bar', 'foo'])
119+
call feedkeys("Qg/bar/visual\<CR>$rxQ$ryQvisual\<CR>j", "xt")
120+
call assert_equal('bax', getline(3))
121+
call assert_equal('bay', getline(5))
119122
bwipe!
120123
endfunc
121124

src/testdir/test_excmd.vim

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,44 @@ func Test_run_excmd_with_text_locked()
349349
let cmd = ":\<C-\>eexecute('close')\<CR>\<C-C>"
350350
call assert_equal(2, winnr('$'))
351351
close
352+
353+
call assert_fails("call feedkeys(\":\<C-R>=execute('bnext')\<CR>\", 'xt')", 'E523:')
354+
endfunc
355+
356+
" Test for the :verbose command
357+
func Test_verbose_cmd()
358+
call assert_equal([' verbose=1'], split(execute('verbose set vbs'), "\n"))
359+
call assert_equal([' verbose=0'], split(execute('0verbose set vbs'), "\n"))
360+
let l = execute("4verbose set verbose | set verbose")
361+
call assert_equal([' verbose=4', ' verbose=0'], split(l, "\n"))
362+
endfunc
363+
364+
" Test for the :delete command and the related abbreviated commands
365+
func Test_excmd_delete()
366+
new
367+
call setline(1, ['foo', "\tbar"])
368+
call assert_equal(['^Ibar$'], split(execute('dl'), "\n"))
369+
call setline(1, ['foo', "\tbar"])
370+
call assert_equal(['^Ibar$'], split(execute('dell'), "\n"))
371+
call setline(1, ['foo', "\tbar"])
372+
call assert_equal(['^Ibar$'], split(execute('delel'), "\n"))
373+
call setline(1, ['foo', "\tbar"])
374+
call assert_equal(['^Ibar$'], split(execute('deletl'), "\n"))
375+
call setline(1, ['foo', "\tbar"])
376+
call assert_equal(['^Ibar$'], split(execute('deletel'), "\n"))
377+
call setline(1, ['foo', "\tbar"])
378+
call assert_equal([' bar'], split(execute('dp'), "\n"))
379+
call setline(1, ['foo', "\tbar"])
380+
call assert_equal([' bar'], split(execute('dep'), "\n"))
381+
call setline(1, ['foo', "\tbar"])
382+
call assert_equal([' bar'], split(execute('delp'), "\n"))
383+
call setline(1, ['foo', "\tbar"])
384+
call assert_equal([' bar'], split(execute('delep'), "\n"))
385+
call setline(1, ['foo', "\tbar"])
386+
call assert_equal([' bar'], split(execute('deletp'), "\n"))
387+
call setline(1, ['foo', "\tbar"])
388+
call assert_equal([' bar'], split(execute('deletep'), "\n"))
389+
close!
352390
endfunc
353391

354392
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_expand.vim

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ func Test_expandcmd()
8181
call assert_fails('call expandcmd("make <afile>")', 'E495:')
8282
enew
8383
call assert_fails('call expandcmd("make %")', 'E499:')
84-
close
84+
let $FOO="blue\tsky"
85+
call setline(1, "$FOO")
86+
call assert_equal("grep pat blue\tsky", expandcmd('grep pat <cfile>'))
87+
unlet $FOO
88+
close!
8589
endfunc
8690

8791
" Test for expanding <sfile>, <slnum> and <sflnum> outside of sourcing a script
@@ -108,5 +112,17 @@ func Test_source_sfile()
108112
call delete('Xresult')
109113
endfunc
110114

115+
" Test for expanding filenames multiple times in a command line
116+
func Test_expand_filename_multicmd()
117+
edit foo
118+
call setline(1, 'foo!')
119+
new
120+
call setline(1, 'foo!')
121+
new <cword> | new <cWORD>
122+
call assert_equal(4, winnr('$'))
123+
call assert_equal('foo!', bufname(winbufnr(1)))
124+
call assert_equal('foo', bufname(winbufnr(2)))
125+
%bwipe!
126+
endfunc
111127

112128
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_filetype.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,12 @@ func Test_filetype_indent_off()
637637
new Xtest.vim
638638
filetype indent on
639639
call assert_equal(1, g:did_indent_on)
640+
call assert_equal(['filetype detection:ON plugin:OFF indent:ON'],
641+
\ execute('filetype')->split("\n"))
640642
filetype indent off
641643
call assert_equal(0, exists('g:did_indent_on'))
644+
call assert_equal(['filetype detection:ON plugin:OFF indent:OFF'],
645+
\ execute('filetype')->split("\n"))
642646
close
643647
endfunc
644648

src/testdir/test_filter_cmd.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ func Test_filter_fails()
4747
call assert_fails('filter /pat', 'E476:')
4848
call assert_fails('filter /pat/', 'E476:')
4949
call assert_fails('filter /pat/ asdf', 'E492:')
50+
" Using assert_fails() causes E476 instead of E866. So use a try-catch.
51+
let caught_e866 = 0
52+
try
53+
filter /\@>b/ ls
54+
catch /E866:/
55+
let caught_e866 = 1
56+
endtry
57+
call assert_equal(1, caught_e866)
5058

5159
call assert_fails('filter!', 'E471:')
5260
call assert_fails('filter! pat', 'E476:')

src/testdir/test_global.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,16 @@ func Test_global_print()
5555
close!
5656
endfunc
5757

58+
" Test for global command with newline character
59+
func Test_global_newline()
60+
new
61+
call setline(1, ['foo'])
62+
exe "g/foo/s/f/h/\<NL>s/o$/w/"
63+
call assert_equal('how', getline(1))
64+
call setline(1, ["foo\<NL>bar"])
65+
exe "g/foo/s/foo\\\<NL>bar/xyz/"
66+
call assert_equal('xyz', getline(1))
67+
close!
68+
endfunc
69+
5870
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_normal.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,3 +2721,13 @@ func Test_normal_cpo_minus()
27212721
let &cpo = save_cpo
27222722
close!
27232723
endfunc
2724+
2725+
" Test for using : to run a multi-line Ex command in operator pending mode
2726+
func Test_normal_yank_with_excmd()
2727+
new
2728+
call setline(1, ['foo', 'bar', 'baz'])
2729+
let @a = ''
2730+
call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
2731+
call assert_equal('f', @a)
2732+
close!
2733+
endfunc

src/testdir/test_plus_arg_edit.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Test_edit_bad()
1818
e! ++enc=utf8 Xfile
1919
call assert_equal('[?][?][???][??]', getline(1))
2020

21-
e! ++enc=utf8 ++bad=_ Xfile
21+
e! ++encoding=utf8 ++bad=_ Xfile
2222
call assert_equal('[_][_][___][__]', getline(1))
2323

2424
e! ++enc=utf8 ++bad=drop Xfile

src/testdir/test_quickfix.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ func Xtest_browse(cchar)
484484
\ 'RegularLine2']
485485

486486
Xfirst
487+
call assert_fails('-5Xcc', 'E16:')
487488
call assert_fails('Xprev', 'E553')
488489
call assert_fails('Xpfile', 'E553')
489490
Xnfile

src/testdir/test_trycatch.vim

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,5 +1996,44 @@ func Test_reload_in_try_catch()
19961996
call delete('Xreload')
19971997
endfunc
19981998

1999+
" Test for errors with :catch, :throw, :finally {{{1
2000+
func Test_try_catch_errors()
2001+
call assert_fails('throw |', 'E471:')
2002+
call assert_fails("throw \n ", 'E471:')
2003+
call assert_fails('catch abc', 'E603:')
2004+
call assert_fails('try | let i = 1| finally | catch | endtry', 'E604:')
2005+
call assert_fails('finally', 'E606:')
2006+
call assert_fails('try | finally | finally | endtry', 'E607:')
2007+
call assert_fails('try | for i in range(5) | endif | endtry', 'E580:')
2008+
call assert_fails('try | while v:true | endtry', 'E170:')
2009+
call assert_fails('try | if v:true | endtry', 'E171:')
2010+
endfunc
2011+
2012+
" Test for verbose messages with :try :catch, and :finally {{{1
2013+
func Test_try_catch_verbose()
2014+
" This test works only when the language is English
2015+
if v:lang != "C" && v:lang !~ '^[Ee]n'
2016+
return
2017+
endif
2018+
2019+
set verbose=14
2020+
redir => msg
2021+
try
2022+
echo i
2023+
catch /E121:/
2024+
finally
2025+
endtry
2026+
redir END
2027+
let expected = [
2028+
\ 'Exception thrown: Vim(echo):E121: Undefined variable: i',
2029+
\ '',
2030+
\ 'Exception caught: Vim(echo):E121: Undefined variable: i',
2031+
\ '',
2032+
\ 'Exception finished: Vim(echo):E121: Undefined variable: i'
2033+
\ ]
2034+
call assert_equal(expected, split(msg, "\n"))
2035+
set verbose&
2036+
endfunc
2037+
19992038
" Modeline {{{1
20002039
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/testdir/test_vimscript.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,29 @@ func Test_missing_end()
19701970
call writefile(['try', 'echo "."'], 'Xscript')
19711971
call assert_fails('source Xscript', 'E600:')
19721972
call delete('Xscript')
1973+
1974+
" Using endfor with :while
1975+
let caught_e732 = 0
1976+
try
1977+
while v:true
1978+
endfor
1979+
catch /E732:/
1980+
let caught_e732 = 1
1981+
endtry
1982+
call assert_equal(1, caught_e732)
1983+
1984+
" Using endwhile with :for
1985+
let caught_e733 = 0
1986+
try
1987+
for i in range(1)
1988+
endwhile
1989+
catch /E733:/
1990+
let caught_e733 = 1
1991+
endtry
1992+
call assert_equal(1, caught_e733)
1993+
1994+
" Missing 'in' in a :for statement
1995+
call assert_fails('for i range(1) | endfor', 'E690:')
19731996
endfunc
19741997

19751998
" Test for deep nesting of if/for/while/try statements {{{1

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ static char *(features[]) =
738738

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
293,
741743
/**/
742744
292,
743745
/**/

0 commit comments

Comments
 (0)