To: vim_dev@googlegroups.com Subject: Patch 8.2.4462 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4462 Problem: Not enough testing for quickfix code. Solution: Add more tests. Fix uncovered problem. (Yegappan Lakshmanan, closes #9839) Files: src/quickfix.c, src/window.c, src/testdir/test_makeencoding.vim, src/testdir/test_quickfix.vim *** ../vim-8.2.4461/src/quickfix.c 2022-02-23 12:05:54.486835944 +0000 --- src/quickfix.c 2022-02-24 12:21:24.010874123 +0000 *************** *** 2086,2092 **** /* * Add an entry to the end of the list of errors. ! * Returns QF_OK or QF_FAIL. */ static int qf_add_entry( --- 2086,2092 ---- /* * Add an entry to the end of the list of errors. ! * Returns QF_OK on success or QF_FAIL on a memory allocation failure. */ static int qf_add_entry( *************** *** 4051,4059 **** { qf_info_T *qi = &ql_info; - if (!bt_quickfix(curbuf)) - return; - if (IS_LL_WINDOW(curwin)) qi = GET_LOC_LIST(curwin); --- 4051,4056 ---- *************** *** 4525,4532 **** --- 4522,4533 ---- win = curwin; else { + // Find the file window (non-quickfix) with this location list win = qf_find_win_with_loclist(qi); if (win == NULL) + // File window is not found. Find the location list window. + win = qf_find_win(qi); + if (win == NULL) return; } qf_winid = win->w_id; *************** *** 8343,8349 **** if (new_qi) ll_free_all(&qi); } ! else if (curwin->w_llist == NULL) curwin->w_llist = qi; } } --- 8344,8352 ---- if (new_qi) ll_free_all(&qi); } ! else if (curwin->w_llist == NULL && new_qi) ! // current window didn't have a location list associated with it ! // before. Associate the new location list now. curwin->w_llist = qi; } } *** ../vim-8.2.4461/src/window.c 2022-02-23 12:23:04.501304722 +0000 --- src/window.c 2022-02-24 12:21:24.010874123 +0000 *************** *** 4959,4965 **** /* * Jump to the first open window in any tab page that contains buffer "buf", ! * if one exists. * Returns a pointer to the window found, otherwise NULL. */ win_T * --- 4959,4965 ---- /* * Jump to the first open window in any tab page that contains buffer "buf", ! * if one exists. First search in the windows present in the current tab page. * Returns a pointer to the window found, otherwise NULL. */ win_T * *** ../vim-8.2.4461/src/testdir/test_makeencoding.vim 2020-08-12 17:50:31.879655802 +0100 --- src/testdir/test_makeencoding.vim 2022-02-24 12:21:24.010874123 +0000 *************** *** 103,106 **** --- 103,120 ---- endfor endfunc + " Test for an error file with a long line that needs an encoding conversion + func Test_longline_conversion() + new + call setline(1, ['Xfile:10:' .. repeat("\xe0", 2000)]) + write ++enc=latin1 Xerr.out + bw! + set errorformat& + set makeencoding=latin1 + cfile Xerr.out + call assert_equal(repeat("\u00e0", 2000), getqflist()[0].text) + call delete('Xerr.out') + set makeencoding& + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.4461/src/testdir/test_quickfix.vim 2022-02-23 12:05:54.486835944 +0000 --- src/testdir/test_quickfix.vim 2022-02-24 12:21:24.010874123 +0000 *************** *** 254,259 **** --- 254,260 ---- " Opening the location list window without any errors should fail if a:cchar == 'l' call assert_fails('lopen', 'E776:') + call assert_fails('lwindow', 'E776:') endif " Create a list with no valid entries *************** *** 739,750 **** silent helpgrep grail assert_equal('aABceFs', &cpo) ! delete(dir, 'rf') &rtp = rtp_save cclose helpclose enddef func Test_helpgrep_restore_cpo_aucmd() let save_cpo = &cpo augroup QF_Test --- 740,753 ---- silent helpgrep grail assert_equal('aABceFs', &cpo) ! delete('Xruntime', 'rf') &rtp = rtp_save cclose helpclose enddef + " When running the :helpgrep command, if an autocmd modifies the 'cpoptions' + " value, then Vim crashes. (issue fixed by 7.2b-004 and 8.2.4453) func Test_helpgrep_restore_cpo_aucmd() let save_cpo = &cpo augroup QF_Test *************** *** 1281,1288 **** --- 1284,1297 ---- set efm= call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:') + " Empty directory name. When there is an error in parsing new entries, make + " sure the previous quickfix list is made the current list. + set efm& + cexpr ["one", "two"] + let qf_id = getqflist(#{id: 0}).id set efm=%DEntering\ dir\ abc,%f:%l:%m call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:') + call assert_equal(qf_id, getqflist(#{id: 0}).id) let &efm = save_efm endfunc *************** *** 1535,1541 **** endfunc endif ! augroup testgroup au! autocmd BufReadCmd test_changed.txt call ReadFunc() augroup END --- 1544,1550 ---- endfunc endif ! augroup QF_Test au! autocmd BufReadCmd test_changed.txt call ReadFunc() augroup END *************** *** 1549,1555 **** endfor call assert_fails('Xrewind', ErrorNr . ':') ! augroup! testgroup endfunc func Test_quickfix_was_changed_by_autocmd() --- 1558,1581 ---- endfor call assert_fails('Xrewind', ErrorNr . ':') ! augroup QF_Test ! au! ! augroup END ! ! if a:cchar == 'c' ! cexpr ["Xtest1:1:Line"] ! cwindow ! only ! augroup QF_Test ! au! ! autocmd WinEnter * call setqflist([], 'f') ! augroup END ! call assert_fails('exe "normal \"', 'E925:') ! augroup QF_Test ! au! ! augroup END ! endif ! %bw! endfunc func Test_quickfix_was_changed_by_autocmd() *************** *** 1688,1693 **** --- 1714,1721 ---- call g:Xsetlist([[1, 2,3]]) call assert_equal(0, len(g:Xgetlist())) call assert_fails('call g:Xsetlist([], [])', 'E928:') + call g:Xsetlist([test_null_dict()]) + call assert_equal([], g:Xgetlist()) endfunc func Test_setqflist() *************** *** 2967,2972 **** --- 2995,3013 ---- call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded) call assert_equal([], getbufinfo('Xtestfile2')) + " Test for opening the dummy buffer used by vimgrep in a window. The new + " window should be closed + %bw! + augroup QF_Test + au! + autocmd BufReadPre * exe "sb " .. expand("") + augroup END + call assert_fails("Xvimgrep /sublime/ Xtestfile1", 'E480:') + call assert_equal(1, winnr('$')) + augroup QF_Test + au! + augroup END + call delete('Xtestfile1') call delete('Xtestfile2') endfunc *************** *** 4133,4146 **** " The following test used to crash Vim func Test_lhelpgrep_autocmd() lhelpgrep quickfix ! autocmd QuickFixCmdPost * call setloclist(0, [], 'f') lhelpgrep buffer call assert_equal('help', &filetype) call assert_equal(0, getloclist(0, {'nr' : '$'}).nr) lhelpgrep tabpage call assert_equal('help', &filetype) call assert_equal(1, getloclist(0, {'nr' : '$'}).nr) ! au! QuickFixCmdPost new | only augroup QF_Test --- 4174,4192 ---- " The following test used to crash Vim func Test_lhelpgrep_autocmd() lhelpgrep quickfix ! augroup QF_Test ! au! ! autocmd QuickFixCmdPost * call setloclist(0, [], 'f') ! augroup END lhelpgrep buffer call assert_equal('help', &filetype) call assert_equal(0, getloclist(0, {'nr' : '$'}).nr) lhelpgrep tabpage call assert_equal('help', &filetype) call assert_equal(1, getloclist(0, {'nr' : '$'}).nr) ! augroup QF_Test ! au! ! augroup END new | only augroup QF_Test *************** *** 4153,4159 **** wincmd w call assert_fails('helpgrep quickfix', 'E925:') augroup QF_Test ! au! BufEnter augroup END new | only --- 4199,4205 ---- wincmd w call assert_fails('helpgrep quickfix', 'E925:') augroup QF_Test ! au! augroup END new | only *************** *** 4163,4169 **** augroup END call assert_fails('helpgrep quickfix', 'E925:') augroup QF_Test ! au! BufEnter augroup END new | only --- 4209,4215 ---- augroup END call assert_fails('helpgrep quickfix', 'E925:') augroup QF_Test ! au! augroup END new | only *************** *** 4173,4182 **** augroup END call assert_fails('lhelpgrep quickfix', 'E926:') augroup QF_Test ! au! BufEnter augroup END new | only endfunc " Test for shortening/simplifying the file name when opening the --- 4219,4261 ---- augroup END call assert_fails('lhelpgrep quickfix', 'E926:') augroup QF_Test ! au! augroup END + " Replace the contents of a help window location list when it is still in + " use. new | only + lhelpgrep quickfix + wincmd w + augroup QF_Test + au! + autocmd WinEnter * call setloclist(0, [], 'r') + augroup END + call assert_fails('lhelpgrep win_getid', 'E926:') + augroup QF_Test + au! + augroup END + + %bw! + endfunc + + " The following test used to crash Vim + func Test_lhelpgrep_autocmd_free_loclist() + %bw! + lhelpgrep quickfix + wincmd w + augroup QF_Test + au! + autocmd WinEnter * call setloclist(0, [], 'f') + augroup END + lhelpgrep win_getid + wincmd w + wincmd w + wincmd w + augroup QF_Test + au! + augroup END + %bw! endfunc " Test for shortening/simplifying the file name when opening the *************** *** 5160,5165 **** --- 5239,5245 ---- call assert_equal('L20', l[0].text) call assert_equal([], g:Xgetlist({'idx' : -1, 'items' : 0}).items) call assert_equal([], g:Xgetlist({'idx' : 3, 'items' : 0}).items) + call assert_equal({}, g:Xgetlist(#{idx: "abc"})) %bwipe! endfunc *************** *** 5217,5222 **** --- 5297,5315 ---- call assert_equal('F1|10 col 2-7| green', getline(1)) call assert_equal('F1|20-25 col 4-8| blue', getline(2)) Xclose + + set efm=%f:%l:%c:%m + set quickfixtextfunc=Tqfexpr + " Update the list with only the cwindow + Xwindow + only + call g:Xsetlist([ + \ { 'filename': 'F2', 'lnum': 20, 'col': 2, + \ 'end_col': 7, 'text': 'red'} + \ ]) + call assert_equal(['F2-L20C2-red'], getline(1, '$')) + new + Xclose set efm& set quickfixtextfunc& *************** *** 5926,5930 **** --- 6019,6080 ---- call delete('Xresult') endfunc + " Test for calling setqflist() function recursively + func Test_recursive_setqflist() + augroup QF_Test + au! + autocmd BufWinEnter quickfix call setqflist([], 'r') + augroup END + + copen + call assert_fails("call setqflist([], 'a')", 'E952:') + + augroup QF_Test + au! + augroup END + %bw! + endfunc + + " Test for failure to create a new window when selecting a file from the + " quickfix window + func Test_cwindow_newwin_fails() + cgetexpr ["Xfile1:10:L10", "Xfile1:20:L20"] + cwindow + only + let qf_wid = win_getid() + " create the maximum number of scratch windows + let hor_win_count = (&lines - 1)/2 + let hor_split_count = hor_win_count - 1 + for s in range(1, hor_split_count) | new | set buftype=nofile | endfor + call win_gotoid(qf_wid) + call assert_fails('exe "normal \"', 'E36:') + %bw! + endfunc + + " Test for updating the location list when only the location list window is + " present and the corresponding file window is closed. + func Test_loclist_update_with_llwin_only() + %bw! + new + wincmd w + lexpr ["Xfile1:1:Line1"] + lopen + wincmd p + close + call setloclist(2, [], 'r', {'lines': ["Xtest2:2:Line2"]}) + call assert_equal(['Xtest2|2| Line2'], getbufline(winbufnr(2), 1, '$')) + %bw! + endfunc + + " Test for getting the quickfix list after a buffer with an error is wiped out + func Test_getqflist_wiped_out_buffer() + %bw! + cexpr ["Xtest1:34:Wiped out"] + let bnum = bufnr('Xtest1') + call assert_equal(bnum, getqflist()[0].bufnr) + bw Xtest1 + call assert_equal(0, getqflist()[0].bufnr) + %bw! + endfunc " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.4461/src/version.c 2022-02-24 11:39:35.964798140 +0000 --- src/version.c 2022-02-24 12:28:22.335188597 +0000 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 4462, /**/ -- I AM THANKFUL... ...for the piles of laundry and ironing because it means I have plenty of clothes to wear. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///