From 2e790e9ad10bca3a64b20be75672a3c6a6f3d97c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 19 Jul 2022 20:55:13 +0800 Subject: vim-patch:8.2.0509: various code is not properly tested. Problem: various code is not properly tested. Solution: Add more tests. (Yegappan Lakshmanan, closes vim/vim#5871) https://github.com/vim/vim/commit/cde0ff39da2459b16007fef701ebaa449fb6fe9d Cherry-pick test_clientserver.vim change from patch 8.1.1826. Cherry-pick a comment from patch 8.2.0301. Omit test_viminfo.vim. --- src/nvim/testdir/test_startup.vim | 229 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) (limited to 'src/nvim/testdir/test_startup.vim') diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index d830f5216d..846838b25d 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -12,6 +12,9 @@ func Test_startup_script() source $VIMRUNTIME/defaults.vim call assert_equal(0, &compatible) + " Restore some options, so that the following tests doesn't break + set nomore + set noshowmode endfunc " Verify the order in which plugins are loaded: @@ -814,6 +817,25 @@ func Test_v_argv() call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:]) endfunc +" Test for the "-r" recovery mode option +func Test_r_arg() + throw 'Skipped: Nvim has different directories' + " Can't catch the output of gvim. + CheckNotGui + CheckUnix + CheckEnglish + let cmd = GetVimCommand() + " There can be swap files anywhere, only check for the headers. + let expected =<< trim END + Swap files found:.* + In current directory:.* + In directory \~/tmp:.* + In directory /var/tmp:.* + In directory /tmp:.* + END + call assert_match(join(expected, ""), system(cmd .. " -r")->substitute("[\r\n]\\+", '', '')) +endfunc + " Test for the '-t' option to jump to a tag func Test_t_arg() let before =<< trim [CODE] @@ -824,6 +846,7 @@ func Test_t_arg() call writefile([s], "Xtestout") qall [CODE] + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", \ "first\tXfile1\t/^ \\zsfirst$/", \ "second\tXfile1\t/^ \\zssecond$/", @@ -890,6 +913,138 @@ func Test_x_arg() call delete('Xtest_x_arg') endfunc +" Test for entering the insert mode on startup +func Test_start_insertmode() + throw "Skipped: Nvim does not support setting 'insertmode'" + let before =<< trim [CODE] + set insertmode + [CODE] + let after =<< trim [CODE] + call writefile(['insertmode=' .. &insertmode], 'Xtestout') + qall + [CODE] + if RunVim(before, after, '') + call assert_equal(['insertmode=1'], readfile('Xtestout')) + call delete('Xtestout') + endif +endfunc + +" Test for enabling the binary mode on startup +func Test_b_arg() + let after =<< trim [CODE] + call writefile(['binary=' .. &binary], 'Xtestout') + qall + [CODE] + if RunVim([], after, '-b') + call assert_equal(['binary=1'], readfile('Xtestout')) + call delete('Xtestout') + endif +endfunc + +" Test for enabling the lisp mode on startup +func Test_l_arg() + let after =<< trim [CODE] + let s = 'lisp=' .. &lisp .. ', showmatch=' .. &showmatch + call writefile([s], 'Xtestout') + qall + [CODE] + if RunVim([], after, '-l') + call assert_equal(['lisp=1, showmatch=1'], readfile('Xtestout')) + call delete('Xtestout') + endif +endfunc + +" Test for specifying a non-existing vimrc file using "-u" +func Test_missing_vimrc() + if !CanRunVimInTerminal() + throw 'Skipped: cannot run vim in terminal' + endif + let after =<< trim [CODE] + call assert_match('^E282:', v:errmsg) + call writefile(v:errors, 'Xtestout') + [CODE] + call writefile(after, 'Xafter') + + let cmd = GetVimCommandCleanTerm() . ' -u Xvimrc_missing -S Xafter' + let buf = term_start(cmd, {'term_rows' : 10}) + call WaitForAssert({-> assert_equal("running", term_getstatus(buf))}) + call term_wait(buf) + call term_sendkeys(buf, "\n:") + call term_wait(buf) + call WaitForAssert({-> assert_match(':', term_getline(buf, 10))}) + call StopVimInTerminal(buf) + call assert_equal([], readfile('Xtestout')) + call delete('Xafter') + call delete('Xtestout') +endfunc + +" Test for using the $VIMINIT environment variable +func Test_VIMINIT() + let after =<< trim [CODE] + call assert_equal(1, exists('viminit_found')) + call assert_equal('yes', viminit_found) + call writefile(v:errors, 'Xtestout') + qall + [CODE] + call writefile(after, 'Xafter') + " let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' + let cmd = GetVimProg() . ' -S Xafter --cmd "set enc=utf8"' + call setenv('VIMINIT', 'let viminit_found="yes"') + exe "silent !" . cmd + call assert_equal([], readfile('Xtestout')) + call delete('Xtestout') + call delete('Xafter') +endfunc + +" Test for using the $EXINIT environment variable +func Test_EXINIT() + let after =<< trim [CODE] + call assert_equal(1, exists('exinit_found')) + call assert_equal('yes', exinit_found) + call writefile(v:errors, 'Xtestout') + qall + [CODE] + call writefile(after, 'Xafter') + " let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' + let cmd = GetVimProg() . ' -S Xafter --cmd "set enc=utf8"' + call setenv('EXINIT', 'let exinit_found="yes"') + exe "silent !" . cmd + call assert_equal([], readfile('Xtestout')) + call delete('Xtestout') + call delete('Xafter') +endfunc + +" Test for using the 'exrc' option +func Test_exrc() + let after =<< trim [CODE] + call assert_equal(1, &exrc) + call assert_equal(1, &secure) + call assert_equal(37, exrc_found) + call writefile(v:errors, 'Xtestout') + qall + [CODE] + call mkdir('Xdir') + call writefile(['let exrc_found=37'], 'Xdir/.exrc') + call writefile(after, 'Xdir/Xafter') + " let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"' + let cmd = GetVimProg() . ' -S Xafter --cmd "cd Xdir" --cmd "set enc=utf8 exrc secure"' + exe "silent !" . cmd + call assert_equal([], readfile('Xdir/Xtestout')) + call delete('Xdir', 'rf') +endfunc + +" Test for starting Vim with a non-terminal as input/output +func Test_io_not_a_terminal() + throw 'Skipped: Nvim does not support --ttyfail' + " Can't catch the output of gvim. + CheckNotGui + CheckUnix + CheckEnglish + let l = systemlist(GetVimProg() .. ' --ttyfail') + call assert_equal(['Vim: Warning: Output is not to a terminal', + \ 'Vim: Warning: Input is not from a terminal'], l) +endfunc + " Test for --not-a-term avoiding escape codes. func Test_not_a_term() CheckUnix @@ -948,6 +1103,80 @@ func Test_w_arg() call delete('Xscriptin') endfunc +" Test for the "-s scriptin" argument +func Test_s_arg() + " Can't catch the output of gvim. + CheckNotGui + CheckEnglish + " Test for failing to open the script input file. + let m = system(GetVimCommand() .. " -s abcxyz") + " call assert_equal("Cannot open for reading: \"abcxyz\"\n", m) + call assert_equal("Cannot open for reading: \"abcxyz\": no such file or directory\n", m) + + call writefile([], 'Xinput') + let m = system(GetVimCommand() .. " -s Xinput -s Xinput") + call assert_equal("Attempt to open script file again: \"-s Xinput\"\n", m) + call delete('Xinput') +endfunc + +" Test for the "-n" (no swap file) argument +func Test_n_arg() + let after =<< trim [CODE] + call assert_equal(0, &updatecount) + call writefile(v:errors, 'Xtestout') + qall + [CODE] + if RunVim([], after, '-n') + call assert_equal([], readfile('Xtestout')) + call delete('Xtestout') + endif + call delete('Xafter') +endfunc + +" Test for the "-h" (help) argument +func Test_h_arg() + throw 'Skipped: Nvim has different output for "-h" argument' + " Can't catch the output of gvim. + CheckNotGui + let l = systemlist(GetVimProg() .. ' -h') + call assert_match('^VIM - Vi IMproved', l[0]) + let l = systemlist(GetVimProg() .. ' -?') + call assert_match('^VIM - Vi IMproved', l[0]) +endfunc + +" Test for the "-F" (farsi) argument +func Test_F_arg() + throw 'Skipped: Nvim does not recognize "-F" argument' + " Can't catch the output of gvim. + CheckNotGui + let l = systemlist(GetVimProg() .. ' -F') + call assert_match('^E27:', l[0]) +endfunc + +" Test for the "-E" (improved Ex mode) argument +func Test_E_arg() + let after =<< trim [CODE] + call assert_equal('cv', mode(1)) + call writefile(v:errors, 'Xtestout') + qall + [CODE] + if RunVim([], after, '-E') + call assert_equal([], readfile('Xtestout')) + call delete('Xtestout') + endif + call delete('Xafter') +endfunc + +" Test for too many edit argument errors +func Test_too_many_edit_args() + throw 'Skipped: N/A' + " Can't catch the output of gvim. + CheckNotGui + CheckEnglish + let l = systemlist(GetVimProg() .. ' - -') + call assert_match('^Too many edit arguments: "-"', l[1]) +endfunc + " Test starting vim with various names: vim, ex, view, evim, etc. func Test_progname() CheckUnix -- cgit From 358f9b776b48e854fdb714c76b24c5929bbd8544 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 19 Jul 2022 21:36:53 +0800 Subject: vim-patch:8.2.2632: not all command line arguments are tested MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Not all command line arguments are tested. Solution: Add tests for -D and -serverlist. (Dominique Pellé, closes vim/vim#7992) https://github.com/vim/vim/commit/c5cf369e9543ff065e2e1da91da3218c223840e2 Cherry-pick two deletions from patch 8.2.1799. --- src/nvim/testdir/test_startup.vim | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir/test_startup.vim') diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index 846838b25d..39fafbf7b4 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -1130,7 +1130,6 @@ func Test_n_arg() call assert_equal([], readfile('Xtestout')) call delete('Xtestout') endif - call delete('Xafter') endfunc " Test for the "-h" (help) argument @@ -1164,7 +1163,21 @@ func Test_E_arg() call assert_equal([], readfile('Xtestout')) call delete('Xtestout') endif - call delete('Xafter') +endfunc + +" Test for the "-D" (debugger) argument +func Test_D_arg() + CheckRunVimInTerminal + + let cmd = GetVimCommandCleanTerm() .. ' -D' + let buf = term_start(cmd, {'term_rows' : 10}) + call WaitForAssert({-> assert_equal("running", term_getstatus(buf))}) + + call WaitForAssert({-> assert_equal('Entering Debug mode. Type "cont" to continue.', + \ term_getline(buf, 7))}) + call WaitForAssert({-> assert_equal('>', term_getline(buf, 10))}) + + call StopVimInTerminal(buf) endfunc " Test for too many edit argument errors -- cgit