diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ex_docmd.c | 9 | ||||
-rw-r--r-- | src/nvim/testdir/runtest.vim | 6 | ||||
-rw-r--r-- | src/nvim/testdir/setup.vim | 61 | ||||
-rw-r--r-- | src/nvim/testdir/test_arglist.vim | 17 | ||||
-rw-r--r-- | src/nvim/testdir/test_ex_mode.vim | 23 | ||||
-rw-r--r-- | src/nvim/testdir/test_excmd.vim | 33 | ||||
-rw-r--r-- | src/nvim/testdir/test_mapping.vim | 7 | ||||
-rw-r--r-- | src/nvim/testdir/test_quickfix.vim | 15 | ||||
-rw-r--r-- | src/nvim/testdir/test_search.vim | 59 | ||||
-rw-r--r-- | src/nvim/testdir/test_sort.vim | 16 | ||||
-rw-r--r-- | src/nvim/testdir/test_source.vim | 10 | ||||
-rw-r--r-- | src/nvim/testdir/test_substitute.vim | 33 | ||||
-rw-r--r-- | src/nvim/testdir/test_undo.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_vimscript.vim | 86 | ||||
-rw-r--r-- | src/nvim/testdir/test_window_cmd.vim | 24 | ||||
-rw-r--r-- | src/nvim/testdir/test_writefile.vim | 4 |
16 files changed, 371 insertions, 34 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 2899e17039..0b40715857 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -908,6 +908,15 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) msg_list = saved_msg_list; + // Cleanup if "cs_emsg_silent_list" remains. + if (cstack.cs_emsg_silent_list != NULL) { + eslist_T *elem, *temp; + for (elem = cstack.cs_emsg_silent_list; elem != NULL; elem = temp) { + temp = elem->next; + xfree(elem); + } + } + /* * If there was too much output to fit on the command line, ask the user to * hit return before redrawing the screen. With the ":global" command we do diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index d0a666a049..7060cab2e5 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -153,6 +153,9 @@ func RunTheTest(test) " directory after executing the test. let save_cwd = getcwd() + " Align Nvim defaults to Vim. + source setup.vim + if exists("*SetUp") try call SetUp() @@ -191,9 +194,6 @@ func RunTheTest(test) endtry endif - " Align Nvim defaults to Vim. - source setup.vim - " Clear any autocommands and put back the catch-all for SwapExists. au! au SwapExists * call HandleSwapExists() diff --git a/src/nvim/testdir/setup.vim b/src/nvim/testdir/setup.vim index f8db2ea120..e6c0762729 100644 --- a/src/nvim/testdir/setup.vim +++ b/src/nvim/testdir/setup.vim @@ -1,33 +1,34 @@ -" Align Nvim defaults to Vim. -set backspace= -set complete=.,w,b,u,t,i -set directory& -set directory^=. -set fillchars=vert:\|,fold:- -set formatoptions=tcq -set fsync -set laststatus=1 -set listchars=eol:$ -set joinspaces -set nohidden nosmarttab noautoindent noautoread noruler noshowcmd -set nohlsearch noincsearch -set nrformats=bin,octal,hex -set shortmess=filnxtToOS -set sidescroll=0 -set tags=./tags,tags -set undodir& -set undodir^=. -set wildoptions= -set startofline -set sessionoptions& -set sessionoptions+=options -set viewoptions& -set viewoptions+=options -set switchbuf= - -" Make "Q" switch to Ex mode. -" This does not work for all tests. -nnoremap Q gQ +if exists('s:did_load') + " Align Nvim defaults to Vim. + set backspace= + set complete=.,w,b,u,t,i + set directory& + set directory^=. + set fillchars=vert:\|,fold:- + set formatoptions=tcq + set fsync + set laststatus=1 + set listchars=eol:$ + set joinspaces + set nohidden nosmarttab noautoindent noautoread noruler noshowcmd + set nohlsearch noincsearch + set nrformats=bin,octal,hex + set shortmess=filnxtToOS + set sidescroll=0 + set tags=./tags,tags + set undodir& + set undodir^=. + set wildoptions= + set startofline + set sessionoptions& + set sessionoptions+=options + set viewoptions& + set viewoptions+=options + set switchbuf= + " Make "Q" switch to Ex mode. + " This does not work for all tests. + nnoremap Q gQ +endif " Common preparations for running tests. diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim index 164149476f..5caceeb958 100644 --- a/src/nvim/testdir/test_arglist.vim +++ b/src/nvim/testdir/test_arglist.vim @@ -1,5 +1,8 @@ " Test argument list commands +source shared.vim +source term_util.vim + func Reset_arglist() args a | %argd endfunc @@ -510,3 +513,17 @@ func Test_argdo() call assert_equal(['Xa.c', 'Xb.c', 'Xc.c'], l) bwipe Xa.c Xb.c Xc.c 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/nvim/testdir/test_ex_mode.vim b/src/nvim/testdir/test_ex_mode.vim index cff78620d1..169a6cdabf 100644 --- a/src/nvim/testdir/test_ex_mode.vim +++ b/src/nvim/testdir/test_ex_mode.vim @@ -64,6 +64,29 @@ func Test_ex_mode() 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() + throw 'Skipped: Nvim does not have :open' + 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 + " 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() diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index df2cf97633..9b59792696 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -22,6 +22,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() @@ -391,6 +392,11 @@ func Test_confirm_write_partial_file() call delete('Xscript') 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:') @@ -399,6 +405,33 @@ func Test_winsize_cmd() " Actually changing the window size would be flaky. 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 + " Test for running Ex commands when text is locked. " <C-\>e in the command line is used to lock the text func Test_run_excmd_with_text_locked() diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index e2b7554797..a34a950526 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -643,6 +643,13 @@ func Test_map_error() map <expr> ,f abc call assert_fails('normal ,f', 'E121:') unmap <expr> ,f + + " Recursive use of :normal in a map + set maxmapdepth=100 + map gq :normal gq<CR> + call assert_fails('normal gq', 'E192:') + unmap gq + set maxmapdepth& endfunc " Test for <special> key mapping diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 4f83c45770..9881deaa45 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -2891,6 +2891,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 + " Test vimgrep without swap file func Test_vimgrep_without_swap_file() let lines =<< trim [SCRIPT] diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 454c956996..b4ed811626 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -1541,6 +1541,65 @@ func Test_search_special() exe "norm /\x80PS" endfunc +" Test for command failures when the last search pattern is not set. +" Need to run this in a new vim instance where last search pattern is not set. +func Test_search_with_no_last_pat() + let lines =<< trim [SCRIPT] + call assert_fails("normal i\<C-R>/\e", 'E35:') + call assert_fails("exe '/'", 'E35:') + call assert_fails("exe '?'", 'E35:') + call assert_fails("/", 'E35:') + call assert_fails("?", 'E35:') + call assert_fails("normal n", 'E35:') + call assert_fails("normal N", 'E35:') + call assert_fails("normal gn", 'E35:') + call assert_fails("normal gN", 'E35:') + call assert_fails("normal cgn", 'E35:') + call assert_fails("normal cgN", 'E35:') + let p = [] + let p = @/ + call assert_equal('', p) + call assert_fails("normal :\<C-R>/", 'E35:') + call assert_fails("//p", 'E35:') + call assert_fails(";//p", 'E35:') + call assert_fails("??p", 'E35:') + call assert_fails(";??p", 'E35:') + call assert_fails('g//p', 'E476:') + call assert_fails('v//p', 'E476:') + 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 + +" Test for using tilde (~) atom in search. This should use the last used +" substitute pattern +func Test_search_tilde_pat() + let lines =<< trim [SCRIPT] + set regexpengine=1 + call assert_fails('exe "normal /~\<CR>"', 'E33:') + call assert_fails('exe "normal ?~\<CR>"', 'E33:') + set regexpengine=2 + call assert_fails('exe "normal /~\<CR>"', 'E383:') + call assert_fails('exe "normal ?~\<CR>"', 'E383:') + set regexpengine& + 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 + " Test 'smartcase' with utf-8. func Test_search_smartcase_utf8() new diff --git a/src/nvim/testdir/test_sort.vim b/src/nvim/testdir/test_sort.vim index 540c73a772..9895ad754c 100644 --- a/src/nvim/testdir/test_sort.vim +++ b/src/nvim/testdir/test_sort.vim @@ -1489,6 +1489,22 @@ func Test_sort_last_search_pat() close! 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 + " Test for retaining marks across a :sort func Test_sort_with_marks() new diff --git a/src/nvim/testdir/test_source.vim b/src/nvim/testdir/test_source.vim index b8fe8422b3..e7f3fb1884 100644 --- a/src/nvim/testdir/test_source.vim +++ b/src/nvim/testdir/test_source.vim @@ -57,3 +57,13 @@ func Test_different_script() call assert_fails('source XtwoScript', 'E121:') call delete('XtwoScript') 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/nvim/testdir/test_substitute.vim b/src/nvim/testdir/test_substitute.vim index 619b63202a..9a1144b8e4 100644 --- a/src/nvim/testdir/test_substitute.vim +++ b/src/nvim/testdir/test_substitute.vim @@ -294,7 +294,7 @@ endfunc " Test for *:s%* on :substitute. func Test_sub_cmd_6() - throw "skipped: Nvim removed POSIX-related 'cpoptions' flags" + throw 'Skipped: Nvim does not support cpoptions flag "/"' set magic& set cpo+=/ @@ -808,6 +808,37 @@ func Test_sub_expand_text() close! endfunc +" Test for command failures when the last substitute pattern is not set. +func Test_sub_with_no_last_pat() + let lines =<< trim [SCRIPT] + call assert_fails('~', 'E33:') + call assert_fails('s//abc/g', 'E476:') + call assert_fails('s\/bar', 'E476:') + call assert_fails('s\&bar&', 'E476:') + call writefile(v:errors, 'Xresult') + qall! + [SCRIPT] + call writefile(lines, 'Xscript') + if RunVim([], [], '--clean -S Xscript') + call assert_equal([], readfile('Xresult')) + endif + + " Nvim does not support cpoptions flag "/"' + " let lines =<< trim [SCRIPT] + " set cpo+=/ + " call assert_fails('s/abc/%/', 'E33:') + " 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_submatch_list_concatenate() let pat = 'A\(.\)' let Rep = {-> string([submatch(0, 1)] + [[submatch(1)]])} diff --git a/src/nvim/testdir/test_undo.vim b/src/nvim/testdir/test_undo.vim index af92328387..da8bf12318 100644 --- a/src/nvim/testdir/test_undo.vim +++ b/src/nvim/testdir/test_undo.vim @@ -299,6 +299,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/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index f93eb6e274..c933f2443e 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1771,6 +1771,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 + func Test_for_over_string() let res = '' for c in 'aéc̀d' diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index d295e520c7..21387111a3 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -886,6 +886,30 @@ func Test_floatwin_splitmove() bwipe endfunc +" Test for the :only command +func Test_window_only() + new + set modified + new + call assert_fails('only', 'E445:') + only! +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() + throw 'Skipped: Nvim does not have :winpos' + if !has("gui_running") && !has('win32') + call assert_fails('winpos', 'E188:') + endif + call assert_fails('winpos 10', 'E466:') +endfunc + func Test_window_resize() throw 'Skipped: Nvim supports cmdheight=0' " Vertical :resize (absolute, relative, min and max size). diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index b42665c9b5..d598bfeac8 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -206,6 +206,10 @@ func Test_write_errors() call assert_fails('1,2write', 'E140:') close! + call assert_fails('w > Xtest', 'E494:') + + call assert_fails('w > Xtest', 'E494:') + " Try to overwrite a directory if has('unix') call mkdir('Xdir1') |