From 83e48174e61dcda681bfece3220582b7f557ae60 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 20 May 2021 18:05:39 -0400 Subject: vim-patch:8.1.2320: insufficient test coverage for quickfix Problem: Insufficient test coverage for quickfix. Solution: Add more tests. Fix uncovered problem. (Yegappan Lakshmanan, closes vim/vim#5238) https://github.com/vim/vim/commit/f9ae154c512683ea7b933f870b0268232fd7ad38 --- src/nvim/quickfix.c | 17 +++--- src/nvim/testdir/test_quickfix.vim | 122 ++++++++++++++++++++++++++++++++++--- 2 files changed, 119 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index ac27e92932..1a9bbe26f0 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2672,7 +2672,7 @@ static void qf_goto_win_with_qfl_file(int qf_fnum) static int qf_jump_to_usable_window(int qf_fnum, bool newwin, int *opened_window) { - win_T *usable_win_ptr = NULL; + win_T *usable_wp = NULL; bool usable_win = false; // If opening a new window, then don't use the location list referred by @@ -2681,8 +2681,8 @@ static int qf_jump_to_usable_window(int qf_fnum, bool newwin, qf_info_T *ll_ref = newwin ? NULL : curwin->w_llist_ref; if (ll_ref != NULL) { // Find a non-quickfix window with this location list - usable_win_ptr = qf_find_win_with_loclist(ll_ref); - if (usable_win_ptr != NULL) { + usable_wp = qf_find_win_with_loclist(ll_ref); + if (usable_wp != NULL) { usable_win = true; } } @@ -2710,7 +2710,7 @@ static int qf_jump_to_usable_window(int qf_fnum, bool newwin, *opened_window = true; // close it when fail } else { if (curwin->w_llist_ref != NULL) { // In a location window - qf_goto_win_with_ll_file(usable_win_ptr, qf_fnum, ll_ref); + qf_goto_win_with_ll_file(usable_wp, qf_fnum, ll_ref); } else { // In a quickfix window qf_goto_win_with_qfl_file(qf_fnum); } @@ -3038,14 +3038,11 @@ theend: qfl->qf_ptr = qf_ptr; qfl->qf_index = qf_index; } - if (p_swb != old_swb && opened_window) { + if (p_swb != old_swb && p_swb == empty_option && opened_window) { // Restore old 'switchbuf' value, but not when an autocommand or // modeline has changed the value. - if (p_swb == empty_option) { - p_swb = old_swb; - swb_flags = old_swb_flags; - } else - free_string_option(old_swb); + p_swb = old_swb; + swb_flags = old_swb_flags; } } diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 06a0fd5001..676d14387e 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -14,7 +14,7 @@ func s:setup_commands(cchar) command! -nargs=* Xaddexpr caddexpr command! -nargs=* -count Xolder colder command! -nargs=* Xnewer cnewer - command! -nargs=* Xopen copen + command! -nargs=* Xopen copen command! -nargs=* Xwindow cwindow command! -nargs=* Xbottom cbottom command! -nargs=* Xclose cclose @@ -32,8 +32,8 @@ func s:setup_commands(cchar) command! -count -nargs=* -bang Xnfile cnfile command! -nargs=* -bang Xpfile cpfile command! -nargs=* Xexpr cexpr - command! -range -nargs=* Xvimgrep vimgrep - command! -nargs=* Xvimgrepadd vimgrepadd + command! -count -nargs=* Xvimgrep vimgrep + command! -nargs=* Xvimgrepadd vimgrepadd command! -nargs=* Xgrep grep command! -nargs=* Xgrepadd grepadd command! -nargs=* Xhelpgrep helpgrep @@ -51,7 +51,7 @@ func s:setup_commands(cchar) command! -nargs=* Xaddexpr laddexpr command! -nargs=* -count Xolder lolder command! -nargs=* Xnewer lnewer - command! -nargs=* Xopen lopen + command! -nargs=* Xopen lopen command! -nargs=* Xwindow lwindow command! -nargs=* Xbottom lbottom command! -nargs=* Xclose lclose @@ -69,8 +69,8 @@ func s:setup_commands(cchar) command! -count -nargs=* -bang Xnfile lnfile command! -nargs=* -bang Xpfile lpfile command! -nargs=* Xexpr lexpr - command! -range -nargs=* Xvimgrep lvimgrep - command! -nargs=* Xvimgrepadd lvimgrepadd + command! -count -nargs=* Xvimgrep lvimgrep + command! -nargs=* Xvimgrepadd lvimgrepadd command! -nargs=* Xgrep lgrep command! -nargs=* Xgrepadd lgrepadd command! -nargs=* Xhelpgrep lhelpgrep @@ -157,6 +157,12 @@ func XlistTests(cchar) \ ' 2 Data.Text:20 col 10 warning 22: ModuleWarning', \ ' 3 Data/Text.hs:30 col 15 warning 33: FileWarning'], l) + " For help entries in the quickfix list, only the filename without directory + " should be displayed + Xhelpgrep setqflist() + let l = split(execute('Xlist 1', ''), "\n") + call assert_match('^ 1 [^\\/]\{-}:', l[0]) + " Error cases call assert_fails('Xlist abc', 'E488:') endfunc @@ -272,6 +278,14 @@ func XwindowTests(cchar) Xwindow call assert_true(winnr('$') == 1) + " Specifying the width should adjust the width for a vertically split + " quickfix window. + vert Xopen + call assert_equal(10, winwidth(0)) + vert Xopen 12 + call assert_equal(12, winwidth(0)) + Xclose + if a:cchar == 'c' " Opening the quickfix window in multiple tab pages should reuse the " quickfix buffer @@ -475,6 +489,12 @@ func Xtest_browse(cchar) call assert_equal(5, g:Xgetlist({'idx':0}).idx) 2Xcc call assert_equal(2, g:Xgetlist({'idx':0}).idx) + if a:cchar == 'c' + cc + else + ll + endif + call assert_equal(2, g:Xgetlist({'idx':0}).idx) 10Xcc call assert_equal(6, g:Xgetlist({'idx':0}).idx) Xlast @@ -483,6 +503,14 @@ func Xtest_browse(cchar) call assert_equal(11, line('.')) call assert_fails('Xnext', 'E553') call assert_fails('Xnfile', 'E553') + " To process the range using quickfix list entries, directly use the + " quickfix commands (don't use the user defined commands) + if a:cchar == 'c' + $cc + else + $ll + endif + call assert_equal(6, g:Xgetlist({'idx':0}).idx) Xrewind call assert_equal('Xqftestfile1', bufname('%')) call assert_equal(5, line('.')) @@ -1716,9 +1744,11 @@ func Test_switchbuf() call assert_equal(winid, win_getid()) 2cnext call assert_equal(winid, win_getid()) - enew + " Test for 'switchbuf' set to search for files in windows in the current + " tabpage and jump to an existing window (if present) set switchbuf=useopen + enew cfirst | cnext call assert_equal(file1_winid, win_getid()) 2cnext @@ -1726,6 +1756,8 @@ func Test_switchbuf() 2cnext call assert_equal(file2_winid, win_getid()) + " Test for 'switchbuf' set to search for files in tabpages and jump to an + " existing tabpage (if present) enew | only set switchbuf=usetab tabedit Xqftestfile1 @@ -1744,6 +1776,7 @@ func Test_switchbuf() call assert_equal(4, tabpagenr()) tabfirst | tabonly | enew + " Test for 'switchbuf' set to open a new window for every file set switchbuf=split cfirst | cnext call assert_equal(1, winnr('$')) @@ -1751,9 +1784,10 @@ func Test_switchbuf() call assert_equal(2, winnr('$')) cnext | cnext call assert_equal(3, winnr('$')) - enew | only + " Test for 'switchbuf' set to open a new tabpage for every file set switchbuf=newtab + enew | only cfirst | cnext call assert_equal(1, tabpagenr('$')) cnext | cnext @@ -1770,6 +1804,8 @@ func Test_switchbuf() call assert_equal(last_winid, win_getid()) enew | only + " With an empty 'switchbuf', jumping to a quickfix entry should open the + " file in an existing window (if present) set switchbuf= edit Xqftestfile1 let file1_winid = win_getid() @@ -1799,6 +1835,32 @@ func Test_switchbuf() call assert_equal(4, tabpagenr()) tabfirst | tabonly | enew | only + " Jumping to a file that is not present in any of the tabpages and the + " current tabpage doesn't have any usable windows, should open it in a new + " window in the current tabpage. + copen | only + cfirst + call assert_equal(1, tabpagenr()) + call assert_equal('Xqftestfile1', bufname('')) + + " If opening a file changes 'switchbuf', then the new value should be + " retained. + call writefile(["vim: switchbuf=split"], 'Xqftestfile1') + enew | only + set switchbuf&vim + cexpr "Xqftestfile1:1:10" + call assert_equal('split', &switchbuf) + call writefile(["vim: switchbuf=usetab"], 'Xqftestfile1') + enew | only + set switchbuf=useopen + cexpr "Xqftestfile1:1:10" + call assert_equal('usetab', &switchbuf) + call writefile(["vim: switchbuf&vim"], 'Xqftestfile1') + enew | only + set switchbuf=useopen + cexpr "Xqftestfile1:1:10" + call assert_equal('', &switchbuf) + call delete('Xqftestfile1') call delete('Xqftestfile2') call delete('Xqftestfile3') @@ -1825,11 +1887,16 @@ func Xadjust_qflnum(cchar) call append(6, ['Buffer', 'Window']) let l = g:Xgetlist() - call assert_equal(5, l[0].lnum) call assert_equal(6, l[2].lnum) call assert_equal(13, l[3].lnum) + " If a file doesn't have any quickfix entries, then deleting lines in the + " file should not update the quickfix list + call g:Xsetlist([], 'f') + 1,2delete + call assert_equal([], g:Xgetlist()) + enew! call delete(fname) endfunc @@ -2617,7 +2684,7 @@ func XvimgrepTests(cchar) call assert_equal(2, len(l)) call assert_equal('Editor:Notepad NOTEPAD', l[0].text) - Xvimgrep #\cvim#g Xtestfile? + 10Xvimgrep #\cvim#g Xtestfile? let l = g:Xgetlist() call assert_equal(2, len(l)) call assert_equal(8, l[0].col) @@ -3690,6 +3757,41 @@ func Test_vimgrep_autocmd() call setqflist([], 'f') endfunc +" Test for an autocmd changing the current directory when running vimgrep +func Xvimgrep_autocmd_cd(cchar) + call s:setup_commands(a:cchar) + + %bwipe + let save_cwd = getcwd() + + augroup QF_Test + au! + autocmd BufRead * silent cd %:p:h + augroup END + + 10Xvimgrep /vim/ Xdir/** + let l = g:Xgetlist() + call assert_equal('f1.txt', bufname(l[0].bufnr)) + call assert_equal('f2.txt', fnamemodify(bufname(l[2].bufnr), ':t')) + + augroup QF_Test + au! + augroup END + + exe 'cd ' . save_cwd +endfunc + +func Test_vimgrep_autocmd_cd() + call mkdir('Xdir/a', 'p') + call mkdir('Xdir/b', 'p') + call writefile(['a_L1_vim', 'a_L2_vim'], 'Xdir/a/f1.txt') + call writefile(['b_L1_vim', 'b_L2_vim'], 'Xdir/b/f2.txt') + call Xvimgrep_autocmd_cd('c') + call Xvimgrep_autocmd_cd('l') + %bwipe + call delete('Xdir', 'rf') +endfunc + " The following test used to crash Vim func Test_lhelpgrep_autocmd() lhelpgrep quickfix -- cgit