404 lines
12 KiB
Diff
404 lines
12 KiB
Diff
From 9f6277bdde97b7767ded43a0b5a2023eb601b3b7 Mon Sep 17 00:00:00 2001
|
|
From: Bram Moolenaar <Bram@vim.org>
|
|
Date: Tue, 11 Feb 2020 22:04:02 +0100
|
|
Subject: [PATCH] patch 8.2.0243: insufficient code coverage for ex_docmd.c
|
|
functions
|
|
|
|
Problem: Insufficient code coverage for ex_docmd.c functions.
|
|
Solution: Add more tests. (Yegappan Lakshmanan, closes #5618)
|
|
---
|
|
src/testdir/test_arglist.vim | 17 +++++++
|
|
src/testdir/test_cd.vim | 16 ++++++
|
|
src/testdir/test_cmdline.vim | 9 ++++
|
|
src/testdir/test_ex_mode.vim | 22 +++++++++
|
|
src/testdir/test_excmd.vim | 37 ++++++++++++++
|
|
src/testdir/test_quickfix.vim | 15 ++++++
|
|
src/testdir/test_sort.vim | 16 ++++++
|
|
src/testdir/test_source.vim | 10 ++++
|
|
src/testdir/test_substitute.vim | 2 ++
|
|
src/testdir/test_undo.vim | 2 +
|
|
src/testdir/test_vimscript.vim | 86 +++++++++++++++++++++++++++++++++
|
|
src/testdir/test_window_cmd.vim | 14 ++++++
|
|
12 files changed, 246 insertions(+)
|
|
|
|
diff --git a/src/testdir/test_arglist.vim b/src/testdir/test_arglist.vim
|
|
index e5a5e89..d4ad0f5 100644
|
|
--- a/src/testdir/test_arglist.vim
|
|
+++ b/src/testdir/test_arglist.vim
|
|
@@ -1,5 +1,8 @@
|
|
" Test argument list commands
|
|
|
|
+source shared.vim
|
|
+source term_util.vim
|
|
+
|
|
func Test_argidx()
|
|
args a b c
|
|
last
|
|
@@ -517,3 +520,17 @@ func Test_clear_arglist_in_all()
|
|
call assert_fails("all", "E1156")
|
|
au! *
|
|
endfunc
|
|
+
|
|
+" Test for quiting Vim with unedited files in the argument list
|
|
+func Test_quit_with_arglist()
|
|
+ if !CanRunVimInTerminal()
|
|
+ throw 'Skipped: cannot run vim in terminal'
|
|
+ endif
|
|
+ let buf = RunVimInTerminal('', {'rows': 6})
|
|
+ call term_sendkeys(buf, ":args a b c\n")
|
|
+ call term_sendkeys(buf, ":quit\n")
|
|
+ call WaitForAssert({-> assert_match('^E173:', term_getline(buf, 6))})
|
|
+ call StopVimInTerminal(buf)
|
|
+endfunc
|
|
+
|
|
+" vim: shiftwidth=2 sts=2 expandtab
|
|
diff --git a/src/testdir/test_cd.vim b/src/testdir/test_cd.vim
|
|
index bdb26cd..0e63538 100644
|
|
--- a/src/testdir/test_cd.vim
|
|
+++ b/src/testdir/test_cd.vim
|
|
@@ -1,5 +1,7 @@
|
|
" Test for :cd and chdir()
|
|
|
|
+source shared.vim
|
|
+
|
|
func Test_cd_large_path()
|
|
" This used to crash with a heap write overflow.
|
|
call assert_fails('cd ' . repeat('x', 5000), 'E472:')
|
|
@@ -40,6 +42,20 @@ func Test_cd_minus()
|
|
call assert_equal(path_dotdot, getcwd())
|
|
cd -
|
|
call assert_equal(path, getcwd())
|
|
+
|
|
+ " Test for :cd - without a previous directory
|
|
+ let lines =<< trim [SCRIPT]
|
|
+ call assert_fails('cd -', 'E186:')
|
|
+ call assert_fails('call chdir("-")', 'E186:')
|
|
+ call writefile(v:errors, 'Xresult')
|
|
+ qall!
|
|
+ [SCRIPT]
|
|
+ call writefile(lines, 'Xscript')
|
|
+ if RunVim([], [], '--clean -S Xscript')
|
|
+ call assert_equal([], readfile('Xresult'))
|
|
+ endif
|
|
+ call delete('Xscript')
|
|
+ call delete('Xresult')
|
|
endfunc
|
|
|
|
func Test_cd_with_cpo_chdir()
|
|
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
|
|
index f3860b7..41b36e7 100644
|
|
--- a/src/testdir/test_cmdline.vim
|
|
+++ b/src/testdir/test_cmdline.vim
|
|
@@ -943,4 +943,13 @@ func Test_cmdwin_virtual_edit()
|
|
set ve= cpo-=$
|
|
endfunc
|
|
|
|
+" Test for failure in expanding special keywords in cmdline
|
|
+func Test_cmdline_expand_special()
|
|
+ %bwipe!
|
|
+ call assert_fails('e #', 'E499:')
|
|
+ call assert_fails('e <afile>', 'E495:')
|
|
+ call assert_fails('e <abuf>', 'E496:')
|
|
+ call assert_fails('e <amatch>', 'E497:')
|
|
+endfunc
|
|
+
|
|
" vim: shiftwidth=2 sts=2 expandtab
|
|
diff --git a/src/testdir/test_ex_mode.vim b/src/testdir/test_ex_mode.vim
|
|
index 00a35a3..3842fc3 100644
|
|
--- a/src/testdir/test_ex_mode.vim
|
|
+++ b/src/testdir/test_ex_mode.vim
|
|
@@ -52,3 +52,25 @@ func Test_ex_mode()
|
|
set sw&
|
|
let &encoding = encoding_save
|
|
endfunc
|
|
+
|
|
+" Test for displaying lines from an empty buffer in Ex mode
|
|
+func Test_Ex_emptybuf()
|
|
+ new
|
|
+ call assert_fails('call feedkeys("Q\<CR>", "xt")', 'E749:')
|
|
+ call setline(1, "abc")
|
|
+ call assert_fails('call feedkeys("Q\<CR>", "xt")', 'E501:')
|
|
+ call assert_fails('call feedkeys("Q%d\<CR>", "xt")', 'E749:')
|
|
+ close!
|
|
+endfunc
|
|
+
|
|
+" Test for the :open command
|
|
+func Test_open_command()
|
|
+ new
|
|
+ call setline(1, ['foo foo', 'foo bar', 'foo baz'])
|
|
+ call feedkeys("Qopen\<CR>j", 'xt')
|
|
+ call assert_equal('foo bar', getline('.'))
|
|
+ call feedkeys("Qopen /bar/\<CR>", 'xt')
|
|
+ call assert_equal(5, col('.'))
|
|
+ call assert_fails('call feedkeys("Qopen /baz/\<CR>", "xt")', 'E479:')
|
|
+ close!
|
|
+endfunc
|
|
diff --git a/src/testdir/test_excmd.vim b/src/testdir/test_excmd.vim
|
|
index 17d9028..98b74fc 100644
|
|
--- a/src/testdir/test_excmd.vim
|
|
+++ b/src/testdir/test_excmd.vim
|
|
@@ -18,6 +18,7 @@ func Test_range_error()
|
|
call assert_fails(':\/echo 1', 'E481:')
|
|
normal vv
|
|
call assert_fails(":'<,'>echo 1", 'E481:')
|
|
+ call assert_fails(":\\xcenter", 'E10:')
|
|
endfunc
|
|
|
|
func Test_buffers_lastused()
|
|
@@ -53,3 +54,39 @@ func Test_using_zero_in_range()
|
|
bwipe!
|
|
endfunc
|
|
|
|
+" Test for the :print command
|
|
+func Test_print_cmd()
|
|
+ call assert_fails('print', 'E749:')
|
|
+endfunc
|
|
+
|
|
+" Test for the :winsize command
|
|
+func Test_winsize_cmd()
|
|
+ call assert_fails('winsize 1', 'E465:')
|
|
+endfunc
|
|
+
|
|
+" Test for the :redir command
|
|
+func Test_redir_cmd()
|
|
+ call assert_fails('redir @@', 'E475:')
|
|
+ call assert_fails('redir abc', 'E475:')
|
|
+ if has('unix')
|
|
+ call mkdir('Xdir')
|
|
+ call assert_fails('redir > Xdir', 'E17:')
|
|
+ call delete('Xdir', 'd')
|
|
+ endif
|
|
+ if !has('bsd')
|
|
+ call writefile([], 'Xfile')
|
|
+ call setfperm('Xfile', 'r--r--r--')
|
|
+ call assert_fails('redir! > Xfile', 'E190:')
|
|
+ call delete('Xfile')
|
|
+ endif
|
|
+endfunc
|
|
+
|
|
+" Test for the :filetype command
|
|
+func Test_filetype_cmd()
|
|
+ call assert_fails('filetype abc', 'E475:')
|
|
+endfunc
|
|
+
|
|
+" Test for the :mode command
|
|
+func Test_mode_cmd()
|
|
+ call assert_fails('mode abc', 'E359:')
|
|
+endfunc
|
|
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
|
|
index 72f3172..a3dfaa9 100644
|
|
--- a/src/testdir/test_quickfix.vim
|
|
+++ b/src/testdir/test_quickfix.vim
|
|
@@ -2810,6 +2810,21 @@ func Test_vimgrep_incsearch()
|
|
set noincsearch
|
|
endfunc
|
|
|
|
+" Test vimgrep with the last search pattern not set
|
|
+func Test_vimgrep_with_no_last_search_pat()
|
|
+ let lines =<< trim [SCRIPT]
|
|
+ call assert_fails('vimgrep // *', 'E35:')
|
|
+ call writefile(v:errors, 'Xresult')
|
|
+ qall!
|
|
+ [SCRIPT]
|
|
+ call writefile(lines, 'Xscript')
|
|
+ if RunVim([], [], '--clean -S Xscript')
|
|
+ call assert_equal([], readfile('Xresult'))
|
|
+ endif
|
|
+ call delete('Xscript')
|
|
+ call delete('Xresult')
|
|
+endfunc
|
|
+
|
|
func XfreeTests(cchar)
|
|
call s:setup_commands(a:cchar)
|
|
|
|
diff --git a/src/testdir/test_sort.vim b/src/testdir/test_sort.vim
|
|
index 7da82b0..4332664 100644
|
|
--- a/src/testdir/test_sort.vim
|
|
+++ b/src/testdir/test_sort.vim
|
|
@@ -1322,3 +1322,19 @@ func Test_sort_cmd_report()
|
|
call assert_match("6 fewer lines", res)
|
|
enew!
|
|
endfunc
|
|
+
|
|
+" Test for :sort with no last search pattern
|
|
+func Test_sort_with_no_last_search_pat()
|
|
+ let lines =<< trim [SCRIPT]
|
|
+ call setline(1, ['3b', '1c', '2a'])
|
|
+ call assert_fails('sort //', 'E35:')
|
|
+ call writefile(v:errors, 'Xresult')
|
|
+ qall!
|
|
+ [SCRIPT]
|
|
+ call writefile(lines, 'Xscript')
|
|
+ if RunVim([], [], '--clean -S Xscript')
|
|
+ call assert_equal([], readfile('Xresult'))
|
|
+ endif
|
|
+ call delete('Xscript')
|
|
+ call delete('Xresult')
|
|
+endfunc
|
|
diff --git a/src/testdir/test_source.vim b/src/testdir/test_source.vim
|
|
index 09baec0..1d6bff0 100644
|
|
--- a/src/testdir/test_source.vim
|
|
+++ b/src/testdir/test_source.vim
|
|
@@ -46,3 +46,13 @@ func Test_source_sandbox()
|
|
bwipe!
|
|
call delete('Xsourcehello')
|
|
endfunc
|
|
+
|
|
+" When sourcing a vim script, shebang should be ignored.
|
|
+func Test_source_ignore_shebang()
|
|
+ call writefile(['#!./xyzabc', 'let g:val=369'], 'Xfile.vim')
|
|
+ source Xfile.vim
|
|
+ call assert_equal(g:val, 369)
|
|
+ call delete('Xfile.vim')
|
|
+endfunc
|
|
+
|
|
+" vim: shiftwidth=2 sts=2 expandtab
|
|
diff --git a/src/testdir/test_substitute.vim b/src/testdir/test_substitute.vim
|
|
index c590005..4cdbc15 100644
|
|
--- a/src/testdir/test_substitute.vim
|
|
+++ b/src/testdir/test_substitute.vim
|
|
@@ -1,5 +1,7 @@
|
|
" Tests for multi-line regexps with ":s".
|
|
|
|
+source shared.vim
|
|
+
|
|
func Test_multiline_subst()
|
|
enew!
|
|
call append(0, ["1 aa",
|
|
diff --git a/src/testdir/test_undo.vim b/src/testdir/test_undo.vim
|
|
index 12d835b..79944d9 100644
|
|
--- a/src/testdir/test_undo.vim
|
|
+++ b/src/testdir/test_undo.vim
|
|
@@ -275,6 +275,8 @@ func Test_undo_write()
|
|
close!
|
|
call delete('Xtest')
|
|
bwipe! Xtest
|
|
+
|
|
+ call assert_fails('earlier xyz', 'E475:')
|
|
endfunc
|
|
|
|
func Test_insert_expr()
|
|
diff --git a/src/testdir/test_vimscript.vim b/src/testdir/test_vimscript.vim
|
|
index 89112de..90f1f56 100644
|
|
--- a/src/testdir/test_vimscript.vim
|
|
+++ b/src/testdir/test_vimscript.vim
|
|
@@ -1944,6 +1945,92 @@ func Test_function_defined_line()
|
|
call delete('Xtest.vim')
|
|
endfunc
|
|
|
|
+" Test for missing :endif, :endfor, :endwhile and :endtry {{{1
|
|
+func Test_missing_end()
|
|
+ call writefile(['if 2 > 1', 'echo ">"'], 'Xscript')
|
|
+ call assert_fails('source Xscript', 'E171:')
|
|
+ call writefile(['for i in range(5)', 'echo i'], 'Xscript')
|
|
+ call assert_fails('source Xscript', 'E170:')
|
|
+ call writefile(['while v:true', 'echo "."'], 'Xscript')
|
|
+ call assert_fails('source Xscript', 'E170:')
|
|
+ call writefile(['try', 'echo "."'], 'Xscript')
|
|
+ call assert_fails('source Xscript', 'E600:')
|
|
+ call delete('Xscript')
|
|
+endfunc
|
|
+
|
|
+" Test for deep nesting of if/for/while/try statements {{{1
|
|
+func Test_deep_nest()
|
|
+ if !CanRunVimInTerminal()
|
|
+ throw 'Skipped: cannot run vim in terminal'
|
|
+ endif
|
|
+
|
|
+ let lines =<< trim [SCRIPT]
|
|
+ " Deep nesting of if ... endif
|
|
+ func Test1()
|
|
+ let @a = join(repeat(['if v:true'], 51), "\n")
|
|
+ let @a ..= "\n"
|
|
+ let @a ..= join(repeat(['endif'], 51), "\n")
|
|
+ @a
|
|
+ let @a = ''
|
|
+ endfunc
|
|
+
|
|
+ " Deep nesting of for ... endfor
|
|
+ func Test2()
|
|
+ let @a = join(repeat(['for i in [1]'], 51), "\n")
|
|
+ let @a ..= "\n"
|
|
+ let @a ..= join(repeat(['endfor'], 51), "\n")
|
|
+ @a
|
|
+ let @a = ''
|
|
+ endfunc
|
|
+
|
|
+ " Deep nesting of while ... endwhile
|
|
+ func Test3()
|
|
+ let @a = join(repeat(['while v:true'], 51), "\n")
|
|
+ let @a ..= "\n"
|
|
+ let @a ..= join(repeat(['endwhile'], 51), "\n")
|
|
+ @a
|
|
+ let @a = ''
|
|
+ endfunc
|
|
+
|
|
+ " Deep nesting of try ... endtry
|
|
+ func Test4()
|
|
+ let @a = join(repeat(['try'], 51), "\n")
|
|
+ let @a ..= "\necho v:true\n"
|
|
+ let @a ..= join(repeat(['endtry'], 51), "\n")
|
|
+ @a
|
|
+ let @a = ''
|
|
+ endfunc
|
|
+ [SCRIPT]
|
|
+ call writefile(lines, 'Xscript')
|
|
+
|
|
+ let buf = RunVimInTerminal('-S Xscript', {'rows': 6})
|
|
+
|
|
+ " Deep nesting of if ... endif
|
|
+ call term_sendkeys(buf, ":call Test1()\n")
|
|
+ call WaitForAssert({-> assert_match('^E579:', term_getline(buf, 5))})
|
|
+
|
|
+ " Deep nesting of for ... endfor
|
|
+ call term_sendkeys(buf, ":call Test2()\n")
|
|
+ call WaitForAssert({-> assert_match('^E585:', term_getline(buf, 5))})
|
|
+
|
|
+ " Deep nesting of while ... endwhile
|
|
+ call term_sendkeys(buf, ":call Test3()\n")
|
|
+ call WaitForAssert({-> assert_match('^E585:', term_getline(buf, 5))})
|
|
+
|
|
+ " Deep nesting of try ... endtry
|
|
+ call term_sendkeys(buf, ":call Test4()\n")
|
|
+ call WaitForAssert({-> assert_match('^E601:', term_getline(buf, 5))})
|
|
+
|
|
+ "let l = ''
|
|
+ "for i in range(1, 6)
|
|
+ " let l ..= term_getline(buf, i) . "\n"
|
|
+ "endfor
|
|
+ "call assert_report(l)
|
|
+
|
|
+ call StopVimInTerminal(buf)
|
|
+ call delete('Xscript')
|
|
+endfunc
|
|
+
|
|
"-------------------------------------------------------------------------------
|
|
" Modelines {{{1
|
|
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
|
diff --git a/src/testdir/test_window_cmd.vim b/src/testdir/test_window_cmd.vim
|
|
index d543ef7..2eb415f 100644
|
|
--- a/src/testdir/test_window_cmd.vim
|
|
+++ b/src/testdir/test_window_cmd.vim
|
|
@@ -929,4 +929,18 @@ func Test_win_splitmove()
|
|
call assert_fails('call win_splitmove(winnr(), winnr())', 'E957:')
|
|
endfunc
|
|
|
|
+" Test for errors with :wincmd
|
|
+func Test_wincmd_errors()
|
|
+ call assert_fails('wincmd g', 'E474:')
|
|
+ call assert_fails('wincmd ab', 'E474:')
|
|
+endfunc
|
|
+
|
|
+" Test for errors with :winpos
|
|
+func Test_winpos_errors()
|
|
+ if !has("gui_running") && !has('win32')
|
|
+ call assert_fails('winpos', 'E188:')
|
|
+ endif
|
|
+ call assert_fails('winpos 10', 'E466:')
|
|
+endfunc
|
|
+
|
|
" vim: shiftwidth=2 sts=2 expandtab
|
|
--
|
|
2.33.0
|
|
|