]> granicus.if.org Git - vim/commitdiff
patch 8.2.0293: various Ex commands not sufficiently tested v8.2.0293
authorBram Moolenaar <Bram@vim.org>
Fri, 21 Feb 2020 16:54:45 +0000 (17:54 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 21 Feb 2020 16:54:45 +0000 (17:54 +0100)
Problem:    Various Ex commands not sufficiently tested.
Solution:   Add more test cases. (Yegappan Lakshmanan, closes #5673)

14 files changed:
src/testdir/test_arglist.vim
src/testdir/test_cmdline.vim
src/testdir/test_ex_mode.vim
src/testdir/test_excmd.vim
src/testdir/test_expand.vim
src/testdir/test_filetype.vim
src/testdir/test_filter_cmd.vim
src/testdir/test_global.vim
src/testdir/test_normal.vim
src/testdir/test_plus_arg_edit.vim
src/testdir/test_quickfix.vim
src/testdir/test_trycatch.vim
src/testdir/test_vimscript.vim
src/version.c

index af90ddc7926e206da2f217004dafba322aa14ff7..a3921c180851f19cb80defc382312d182de7ca94 100644 (file)
@@ -515,8 +515,10 @@ func Test_quit_with_arglist()
     throw 'Skipped: cannot run vim in terminal'
   endif
   let buf = RunVimInTerminal('', {'rows': 6})
+  call term_sendkeys(buf, ":set nomore\n")
   call term_sendkeys(buf, ":args a b c\n")
   call term_sendkeys(buf, ":quit\n")
+  call term_wait(buf)
   call WaitForAssert({-> assert_match('^E173:', term_getline(buf, 6))})
   call StopVimInTerminal(buf)
 
@@ -525,14 +527,18 @@ func Test_quit_with_arglist()
   call term_sendkeys(buf, ":set nomore\n")
   call term_sendkeys(buf, ":args a b c\n")
   call term_sendkeys(buf, ":confirm quit\n")
+  call term_wait(buf)
   call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
         \ term_getline(buf, 6))})
   call term_sendkeys(buf, "N")
+  call term_wait(buf)
   call term_sendkeys(buf, ":confirm quit\n")
   call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
         \ term_getline(buf, 6))})
   call term_sendkeys(buf, "Y")
-  call StopVimInTerminal(buf)
+  call term_wait(buf)
+  call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))})
+  only!
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index ff15cbbe3b56a7c552a39e139d171a881522fa2c..545f09b16f605b236bc3d9d195f19f5f1923baf1 100644 (file)
@@ -977,4 +977,33 @@ func Test_cmd_backtick()
   %argd
 endfunc
 
+" Test for the :! command
+func Test_cmd_bang()
+  if !has('unix')
+    return
+  endif
+
+  let lines =<< trim [SCRIPT]
+    " Test for no previous command
+    call assert_fails('!!', 'E34:')
+    set nomore
+    " Test for cmdline expansion with :!
+    call setline(1, 'foo!')
+    silent !echo <cWORD> > Xfile.out
+    call assert_equal(['foo!'], readfile('Xfile.out'))
+    " Test for using previous command
+    silent !echo \! !
+    call assert_equal(['! echo foo!'], readfile('Xfile.out'))
+    call writefile(v:errors, 'Xresult')
+    call delete('Xfile.out')
+    qall!
+  [SCRIPT]
+  call writefile(lines, 'Xscript')
+  if RunVim([], [], '--clean -S Xscript')
+    call assert_equal([], readfile('Xresult'))
+  endif
+  call delete('Xscript')
+  call delete('Xresult')
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 910c1a6377686165a5cabf9413eea4f5e56792af..7869c762e64f14a914e3abf5694e2b911691a162 100644 (file)
@@ -111,11 +111,14 @@ func Test_open_command()
   close!
 endfunc
 
-func Test_Ex_feedkeys()
-  " this doesn't do anything useful, just check it doesn't hang
+" Test for :g/pat/visual to run vi commands in Ex mode
+" This used to hang Vim before 8.2.0274.
+func Test_Ex_global()
   new
-  call setline(1, ["foo"])
-  call feedkeys("Qg/foo/visual\<CR>", "xt")
+  call setline(1, ['', 'foo', 'bar', 'foo', 'bar', 'foo'])
+  call feedkeys("Qg/bar/visual\<CR>$rxQ$ryQvisual\<CR>j", "xt")
+  call assert_equal('bax', getline(3))
+  call assert_equal('bay', getline(5))
   bwipe!
 endfunc
 
index 472945d2537f986d1eea3386eb747dc1c06d1225..c594548647e31dc8819b7a4000eda8982964774b 100644 (file)
@@ -349,6 +349,44 @@ func Test_run_excmd_with_text_locked()
   let cmd = ":\<C-\>eexecute('close')\<CR>\<C-C>"
   call assert_equal(2, winnr('$'))
   close
+
+  call assert_fails("call feedkeys(\":\<C-R>=execute('bnext')\<CR>\", 'xt')", 'E523:')
+endfunc
+
+" Test for the :verbose command
+func Test_verbose_cmd()
+  call assert_equal(['  verbose=1'], split(execute('verbose set vbs'), "\n"))
+  call assert_equal(['  verbose=0'], split(execute('0verbose set vbs'), "\n"))
+  let l = execute("4verbose set verbose | set verbose")
+  call assert_equal(['  verbose=4', '  verbose=0'], split(l, "\n"))
+endfunc
+
+" Test for the :delete command and the related abbreviated commands
+func Test_excmd_delete()
+  new
+  call setline(1, ['foo', "\tbar"])
+  call assert_equal(['^Ibar$'], split(execute('dl'), "\n"))
+  call setline(1, ['foo', "\tbar"])
+  call assert_equal(['^Ibar$'], split(execute('dell'), "\n"))
+  call setline(1, ['foo', "\tbar"])
+  call assert_equal(['^Ibar$'], split(execute('delel'), "\n"))
+  call setline(1, ['foo', "\tbar"])
+  call assert_equal(['^Ibar$'], split(execute('deletl'), "\n"))
+  call setline(1, ['foo', "\tbar"])
+  call assert_equal(['^Ibar$'], split(execute('deletel'), "\n"))
+  call setline(1, ['foo', "\tbar"])
+  call assert_equal(['        bar'], split(execute('dp'), "\n"))
+  call setline(1, ['foo', "\tbar"])
+  call assert_equal(['        bar'], split(execute('dep'), "\n"))
+  call setline(1, ['foo', "\tbar"])
+  call assert_equal(['        bar'], split(execute('delp'), "\n"))
+  call setline(1, ['foo', "\tbar"])
+  call assert_equal(['        bar'], split(execute('delep'), "\n"))
+  call setline(1, ['foo', "\tbar"])
+  call assert_equal(['        bar'], split(execute('deletp'), "\n"))
+  call setline(1, ['foo', "\tbar"])
+  call assert_equal(['        bar'], split(execute('deletep'), "\n"))
+  close!
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index 5a51903712a3b6dbda15f9c2c65c544429b2e61a..d86fea4f459daa88ebb0fb4e1f248e33bcbd6201 100644 (file)
@@ -81,7 +81,11 @@ func Test_expandcmd()
   call assert_fails('call expandcmd("make <afile>")', 'E495:')
   enew
   call assert_fails('call expandcmd("make %")', 'E499:')
-  close
+  let $FOO="blue\tsky"
+  call setline(1, "$FOO")
+  call assert_equal("grep pat blue\tsky", expandcmd('grep pat <cfile>'))
+  unlet $FOO
+  close!
 endfunc
 
 " Test for expanding <sfile>, <slnum> and <sflnum> outside of sourcing a script
@@ -108,5 +112,17 @@ func Test_source_sfile()
   call delete('Xresult')
 endfunc
 
+" Test for expanding filenames multiple times in a command line
+func Test_expand_filename_multicmd()
+  edit foo
+  call setline(1, 'foo!')
+  new
+  call setline(1, 'foo!')
+  new <cword> | new <cWORD>
+  call assert_equal(4, winnr('$'))
+  call assert_equal('foo!', bufname(winbufnr(1)))
+  call assert_equal('foo', bufname(winbufnr(2)))
+  %bwipe!
+endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index 213f2de1c96c7166f97b0f85614bd2244538ecc6..7ea1a7427a4426f0db636482da01e81857b117bf 100644 (file)
@@ -637,8 +637,12 @@ func Test_filetype_indent_off()
   new Xtest.vim
   filetype indent on
   call assert_equal(1, g:did_indent_on)
+  call assert_equal(['filetype detection:ON  plugin:OFF  indent:ON'],
+        \ execute('filetype')->split("\n"))
   filetype indent off
   call assert_equal(0, exists('g:did_indent_on'))
+  call assert_equal(['filetype detection:ON  plugin:OFF  indent:OFF'],
+        \ execute('filetype')->split("\n"))
   close
 endfunc
 
index 543c563baccfb28c4e01c3531f24eb9d12b61077..de9a5d9046a50e13a6436a7354980541f82f720d 100644 (file)
@@ -47,6 +47,14 @@ func Test_filter_fails()
   call assert_fails('filter /pat', 'E476:')
   call assert_fails('filter /pat/', 'E476:')
   call assert_fails('filter /pat/ asdf', 'E492:')
+  " Using assert_fails() causes E476 instead of E866. So use a try-catch.
+  let caught_e866 = 0
+  try
+    filter /\@>b/ ls
+  catch /E866:/
+    let caught_e866 = 1
+  endtry
+  call assert_equal(1, caught_e866)
 
   call assert_fails('filter!', 'E471:')
   call assert_fails('filter! pat', 'E476:')
index 8ce68531ef6eef64f6ce0bd7f319549d74909922..7804ca470e2dc3e055f2dd73e042a19965e5993c 100644 (file)
@@ -55,4 +55,16 @@ func Test_global_print()
   close!
 endfunc
 
+" Test for global command with newline character
+func Test_global_newline()
+  new
+  call setline(1, ['foo'])
+  exe "g/foo/s/f/h/\<NL>s/o$/w/"
+  call assert_equal('how', getline(1))
+  call setline(1, ["foo\<NL>bar"])
+  exe "g/foo/s/foo\\\<NL>bar/xyz/"
+  call assert_equal('xyz', getline(1))
+  close!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 843374d26ed34585435b8ca76dd83bbf1d2b7014..35d5d5fa729b6cd8ed159fb35dd8f1c02159ce50 100644 (file)
@@ -2721,3 +2721,13 @@ func Test_normal_cpo_minus()
   let &cpo = save_cpo
   close!
 endfunc
+
+" Test for using : to run a multi-line Ex command in operator pending mode
+func Test_normal_yank_with_excmd()
+  new
+  call setline(1, ['foo', 'bar', 'baz'])
+  let @a = ''
+  call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
+  call assert_equal('f', @a)
+  close!
+endfunc
index 64533e71cfa34f42942309ff8e813c310f335a87..c52044d064da33cb4ac4edafc0e0d59f84316484 100644 (file)
@@ -18,7 +18,7 @@ func Test_edit_bad()
   e! ++enc=utf8 Xfile
   call assert_equal('[?][?][???][??]', getline(1))
 
-  e! ++enc=utf8 ++bad=_ Xfile
+  e! ++encoding=utf8 ++bad=_ Xfile
   call assert_equal('[_][_][___][__]', getline(1))
 
   e! ++enc=utf8 ++bad=drop Xfile
index 276719c1474d4eea858f9d0359d26b6ef5983c2a..2b51b576c0c39d5943a766831caff295602ce734 100644 (file)
@@ -484,6 +484,7 @@ func Xtest_browse(cchar)
                \ 'RegularLine2']
 
   Xfirst
+  call assert_fails('-5Xcc', 'E16:')
   call assert_fails('Xprev', 'E553')
   call assert_fails('Xpfile', 'E553')
   Xnfile
index adc1745b3939b062c4de43edf8c8a30e72d66efb..e9917dd7875bcb61451c8e684540c9ec52c71303 100644 (file)
@@ -1996,5 +1996,44 @@ func Test_reload_in_try_catch()
   call delete('Xreload')
 endfunc
 
+" Test for errors with :catch, :throw, :finally                            {{{1
+func Test_try_catch_errors()
+  call assert_fails('throw |', 'E471:')
+  call assert_fails("throw \n ", 'E471:')
+  call assert_fails('catch abc', 'E603:')
+  call assert_fails('try | let i = 1| finally | catch | endtry', 'E604:')
+  call assert_fails('finally', 'E606:')
+  call assert_fails('try | finally | finally | endtry', 'E607:')
+  call assert_fails('try | for i in range(5) | endif | endtry', 'E580:')
+  call assert_fails('try | while v:true | endtry', 'E170:')
+  call assert_fails('try | if v:true | endtry', 'E171:')
+endfunc
+
+" Test for verbose messages with :try :catch, and :finally                 {{{1
+func Test_try_catch_verbose()
+  " This test works only when the language is English
+  if v:lang != "C" && v:lang !~ '^[Ee]n'
+    return
+  endif
+
+  set verbose=14
+  redir => msg
+  try
+    echo i
+  catch /E121:/
+  finally
+  endtry
+  redir END
+  let expected = [
+        \ 'Exception thrown: Vim(echo):E121: Undefined variable: i',
+        \ '',
+        \ 'Exception caught: Vim(echo):E121: Undefined variable: i',
+        \ '',
+        \ 'Exception finished: Vim(echo):E121: Undefined variable: i'
+        \ ]
+  call assert_equal(expected, split(msg, "\n"))
+  set verbose&
+endfunc
+
 " Modeline                                                                 {{{1
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index b16b05b02c9f10afe29bf94a0c546e48404143ed..7a49b5783584369cdcded4638d559ae52106be35 100644 (file)
@@ -1970,6 +1970,29 @@ func Test_missing_end()
   call writefile(['try', 'echo "."'], 'Xscript')
   call assert_fails('source Xscript', 'E600:')
   call delete('Xscript')
+
+  " Using endfor with :while
+  let caught_e732 = 0
+  try
+    while v:true
+    endfor
+  catch /E732:/
+    let caught_e732 = 1
+  endtry
+  call assert_equal(1, caught_e732)
+
+  " Using endwhile with :for
+  let caught_e733 = 0
+  try
+    for i in range(1)
+    endwhile
+  catch /E733:/
+    let caught_e733 = 1
+  endtry
+  call assert_equal(1, caught_e733)
+
+  " Missing 'in' in a :for statement
+  call assert_fails('for i range(1) | endfor', 'E690:')
 endfunc
 
 " Test for deep nesting of if/for/while/try statements              {{{1
index 8aca2769a0ada2378ea3e05718e1385448117918..196941ff416830ca0d655b6543f8bfd24c7a8545 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    293,
 /**/
     292,
 /**/