Mercurial > vim
comparison src/testdir/test_quickfix.vim @ 27873:d1af65b322d0 v8.2.4462
patch 8.2.4462: not enough testing for quickfix code
Commit: https://github.com/vim/vim/commit/9c9be05b17ececb1515a2f41a4dedbf848d3d8b6
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Feb 24 12:33:17 2022 +0000
patch 8.2.4462: not enough testing for quickfix code
Problem: Not enough testing for quickfix code.
Solution: Add more tests. Fix uncovered problem. (Yegappan Lakshmanan,
closes #9839)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 24 Feb 2022 13:45:03 +0100 |
parents | 44a552776007 |
children | 2a2c0958a913 |
comparison
equal
deleted
inserted
replaced
27872:7f09baac337b | 27873:d1af65b322d0 |
---|---|
252 call s:setup_commands(a:cchar) | 252 call s:setup_commands(a:cchar) |
253 | 253 |
254 " Opening the location list window without any errors should fail | 254 " Opening the location list window without any errors should fail |
255 if a:cchar == 'l' | 255 if a:cchar == 'l' |
256 call assert_fails('lopen', 'E776:') | 256 call assert_fails('lopen', 'E776:') |
257 call assert_fails('lwindow', 'E776:') | |
257 endif | 258 endif |
258 | 259 |
259 " Create a list with no valid entries | 260 " Create a list with no valid entries |
260 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3'] | 261 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3'] |
261 | 262 |
737 silent helpgrep grail | 738 silent helpgrep grail |
738 cwindow | 739 cwindow |
739 silent helpgrep grail | 740 silent helpgrep grail |
740 | 741 |
741 assert_equal('aABceFs', &cpo) | 742 assert_equal('aABceFs', &cpo) |
742 delete(dir, 'rf') | 743 delete('Xruntime', 'rf') |
743 &rtp = rtp_save | 744 &rtp = rtp_save |
744 cclose | 745 cclose |
745 helpclose | 746 helpclose |
746 enddef | 747 enddef |
747 | 748 |
749 " When running the :helpgrep command, if an autocmd modifies the 'cpoptions' | |
750 " value, then Vim crashes. (issue fixed by 7.2b-004 and 8.2.4453) | |
748 func Test_helpgrep_restore_cpo_aucmd() | 751 func Test_helpgrep_restore_cpo_aucmd() |
749 let save_cpo = &cpo | 752 let save_cpo = &cpo |
750 augroup QF_Test | 753 augroup QF_Test |
751 au! | 754 au! |
752 autocmd BufNew * set cpo=acd | 755 autocmd BufNew * set cpo=acd |
1279 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E867:') | 1282 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E867:') |
1280 | 1283 |
1281 set efm= | 1284 set efm= |
1282 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:') | 1285 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:') |
1283 | 1286 |
1287 " Empty directory name. When there is an error in parsing new entries, make | |
1288 " sure the previous quickfix list is made the current list. | |
1289 set efm& | |
1290 cexpr ["one", "two"] | |
1291 let qf_id = getqflist(#{id: 0}).id | |
1284 set efm=%DEntering\ dir\ abc,%f:%l:%m | 1292 set efm=%DEntering\ dir\ abc,%f:%l:%m |
1285 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:') | 1293 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:') |
1294 call assert_equal(qf_id, getqflist(#{id: 0}).id) | |
1286 | 1295 |
1287 let &efm = save_efm | 1296 let &efm = save_efm |
1288 endfunc | 1297 endfunc |
1289 | 1298 |
1290 func Test_invalid_efm() | 1299 func Test_invalid_efm() |
1533 lolder | 1542 lolder |
1534 lgetexpr [] | 1543 lgetexpr [] |
1535 endfunc | 1544 endfunc |
1536 endif | 1545 endif |
1537 | 1546 |
1538 augroup testgroup | 1547 augroup QF_Test |
1539 au! | 1548 au! |
1540 autocmd BufReadCmd test_changed.txt call ReadFunc() | 1549 autocmd BufReadCmd test_changed.txt call ReadFunc() |
1541 augroup END | 1550 augroup END |
1542 | 1551 |
1543 new | only | 1552 new | only |
1547 call add(qflist, {'filename': 'test_changed.txt'}) | 1556 call add(qflist, {'filename': 'test_changed.txt'}) |
1548 call g:Xsetlist(qflist, ' ') | 1557 call g:Xsetlist(qflist, ' ') |
1549 endfor | 1558 endfor |
1550 call assert_fails('Xrewind', ErrorNr . ':') | 1559 call assert_fails('Xrewind', ErrorNr . ':') |
1551 | 1560 |
1552 augroup! testgroup | 1561 augroup QF_Test |
1562 au! | |
1563 augroup END | |
1564 | |
1565 if a:cchar == 'c' | |
1566 cexpr ["Xtest1:1:Line"] | |
1567 cwindow | |
1568 only | |
1569 augroup QF_Test | |
1570 au! | |
1571 autocmd WinEnter * call setqflist([], 'f') | |
1572 augroup END | |
1573 call assert_fails('exe "normal \<CR>"', 'E925:') | |
1574 augroup QF_Test | |
1575 au! | |
1576 augroup END | |
1577 endif | |
1578 %bw! | |
1553 endfunc | 1579 endfunc |
1554 | 1580 |
1555 func Test_quickfix_was_changed_by_autocmd() | 1581 func Test_quickfix_was_changed_by_autocmd() |
1556 call XquickfixChangedByAutocmd('c') | 1582 call XquickfixChangedByAutocmd('c') |
1557 call XquickfixChangedByAutocmd('l') | 1583 call XquickfixChangedByAutocmd('l') |
1686 call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," . | 1712 call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," . |
1687 \ " {'bufnr':999, 'lnum':5}])", 'E92:') | 1713 \ " {'bufnr':999, 'lnum':5}])", 'E92:') |
1688 call g:Xsetlist([[1, 2,3]]) | 1714 call g:Xsetlist([[1, 2,3]]) |
1689 call assert_equal(0, len(g:Xgetlist())) | 1715 call assert_equal(0, len(g:Xgetlist())) |
1690 call assert_fails('call g:Xsetlist([], [])', 'E928:') | 1716 call assert_fails('call g:Xsetlist([], [])', 'E928:') |
1717 call g:Xsetlist([test_null_dict()]) | |
1718 call assert_equal([], g:Xgetlist()) | |
1691 endfunc | 1719 endfunc |
1692 | 1720 |
1693 func Test_setqflist() | 1721 func Test_setqflist() |
1694 new Xtestfile | only | 1722 new Xtestfile | only |
1695 let bnum = bufnr('%') | 1723 let bnum = bufnr('%') |
2965 %bwipe | 2993 %bwipe |
2966 Xvimgrep /Editor/j Xtestfile* | 2994 Xvimgrep /Editor/j Xtestfile* |
2967 call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded) | 2995 call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded) |
2968 call assert_equal([], getbufinfo('Xtestfile2')) | 2996 call assert_equal([], getbufinfo('Xtestfile2')) |
2969 | 2997 |
2998 " Test for opening the dummy buffer used by vimgrep in a window. The new | |
2999 " window should be closed | |
3000 %bw! | |
3001 augroup QF_Test | |
3002 au! | |
3003 autocmd BufReadPre * exe "sb " .. expand("<abuf>") | |
3004 augroup END | |
3005 call assert_fails("Xvimgrep /sublime/ Xtestfile1", 'E480:') | |
3006 call assert_equal(1, winnr('$')) | |
3007 augroup QF_Test | |
3008 au! | |
3009 augroup END | |
3010 | |
2970 call delete('Xtestfile1') | 3011 call delete('Xtestfile1') |
2971 call delete('Xtestfile2') | 3012 call delete('Xtestfile2') |
2972 endfunc | 3013 endfunc |
2973 | 3014 |
2974 " Tests for the :vimgrep command | 3015 " Tests for the :vimgrep command |
4131 endfunc | 4172 endfunc |
4132 | 4173 |
4133 " The following test used to crash Vim | 4174 " The following test used to crash Vim |
4134 func Test_lhelpgrep_autocmd() | 4175 func Test_lhelpgrep_autocmd() |
4135 lhelpgrep quickfix | 4176 lhelpgrep quickfix |
4136 autocmd QuickFixCmdPost * call setloclist(0, [], 'f') | 4177 augroup QF_Test |
4178 au! | |
4179 autocmd QuickFixCmdPost * call setloclist(0, [], 'f') | |
4180 augroup END | |
4137 lhelpgrep buffer | 4181 lhelpgrep buffer |
4138 call assert_equal('help', &filetype) | 4182 call assert_equal('help', &filetype) |
4139 call assert_equal(0, getloclist(0, {'nr' : '$'}).nr) | 4183 call assert_equal(0, getloclist(0, {'nr' : '$'}).nr) |
4140 lhelpgrep tabpage | 4184 lhelpgrep tabpage |
4141 call assert_equal('help', &filetype) | 4185 call assert_equal('help', &filetype) |
4142 call assert_equal(1, getloclist(0, {'nr' : '$'}).nr) | 4186 call assert_equal(1, getloclist(0, {'nr' : '$'}).nr) |
4143 au! QuickFixCmdPost | 4187 augroup QF_Test |
4188 au! | |
4189 augroup END | |
4144 | 4190 |
4145 new | only | 4191 new | only |
4146 augroup QF_Test | 4192 augroup QF_Test |
4147 au! | 4193 au! |
4148 au BufEnter * call setqflist([], 'f') | 4194 au BufEnter * call setqflist([], 'f') |
4151 " run the test with a help window already open | 4197 " run the test with a help window already open |
4152 help | 4198 help |
4153 wincmd w | 4199 wincmd w |
4154 call assert_fails('helpgrep quickfix', 'E925:') | 4200 call assert_fails('helpgrep quickfix', 'E925:') |
4155 augroup QF_Test | 4201 augroup QF_Test |
4156 au! BufEnter | 4202 au! |
4157 augroup END | 4203 augroup END |
4158 | 4204 |
4159 new | only | 4205 new | only |
4160 augroup QF_Test | 4206 augroup QF_Test |
4161 au! | 4207 au! |
4162 au BufEnter * call setqflist([], 'r') | 4208 au BufEnter * call setqflist([], 'r') |
4163 augroup END | 4209 augroup END |
4164 call assert_fails('helpgrep quickfix', 'E925:') | 4210 call assert_fails('helpgrep quickfix', 'E925:') |
4165 augroup QF_Test | 4211 augroup QF_Test |
4166 au! BufEnter | 4212 au! |
4167 augroup END | 4213 augroup END |
4168 | 4214 |
4169 new | only | 4215 new | only |
4170 augroup QF_Test | 4216 augroup QF_Test |
4171 au! | 4217 au! |
4172 au BufEnter * call setloclist(0, [], 'r') | 4218 au BufEnter * call setloclist(0, [], 'r') |
4173 augroup END | 4219 augroup END |
4174 call assert_fails('lhelpgrep quickfix', 'E926:') | 4220 call assert_fails('lhelpgrep quickfix', 'E926:') |
4175 augroup QF_Test | 4221 augroup QF_Test |
4176 au! BufEnter | 4222 au! |
4177 augroup END | 4223 augroup END |
4178 | 4224 |
4225 " Replace the contents of a help window location list when it is still in | |
4226 " use. | |
4179 new | only | 4227 new | only |
4228 lhelpgrep quickfix | |
4229 wincmd w | |
4230 augroup QF_Test | |
4231 au! | |
4232 autocmd WinEnter * call setloclist(0, [], 'r') | |
4233 augroup END | |
4234 call assert_fails('lhelpgrep win_getid', 'E926:') | |
4235 augroup QF_Test | |
4236 au! | |
4237 augroup END | |
4238 | |
4239 %bw! | |
4240 endfunc | |
4241 | |
4242 " The following test used to crash Vim | |
4243 func Test_lhelpgrep_autocmd_free_loclist() | |
4244 %bw! | |
4245 lhelpgrep quickfix | |
4246 wincmd w | |
4247 augroup QF_Test | |
4248 au! | |
4249 autocmd WinEnter * call setloclist(0, [], 'f') | |
4250 augroup END | |
4251 lhelpgrep win_getid | |
4252 wincmd w | |
4253 wincmd w | |
4254 wincmd w | |
4255 augroup QF_Test | |
4256 au! | |
4257 augroup END | |
4258 %bw! | |
4180 endfunc | 4259 endfunc |
4181 | 4260 |
4182 " Test for shortening/simplifying the file name when opening the | 4261 " Test for shortening/simplifying the file name when opening the |
4183 " quickfix window or when displaying the quickfix list | 4262 " quickfix window or when displaying the quickfix list |
4184 func Test_shorten_fname() | 4263 func Test_shorten_fname() |
5158 call assert_equal(bufnr('F1'), l[0].bufnr) | 5237 call assert_equal(bufnr('F1'), l[0].bufnr) |
5159 call assert_equal(20, l[0].lnum) | 5238 call assert_equal(20, l[0].lnum) |
5160 call assert_equal('L20', l[0].text) | 5239 call assert_equal('L20', l[0].text) |
5161 call assert_equal([], g:Xgetlist({'idx' : -1, 'items' : 0}).items) | 5240 call assert_equal([], g:Xgetlist({'idx' : -1, 'items' : 0}).items) |
5162 call assert_equal([], g:Xgetlist({'idx' : 3, 'items' : 0}).items) | 5241 call assert_equal([], g:Xgetlist({'idx' : 3, 'items' : 0}).items) |
5242 call assert_equal({}, g:Xgetlist(#{idx: "abc"})) | |
5163 %bwipe! | 5243 %bwipe! |
5164 endfunc | 5244 endfunc |
5165 | 5245 |
5166 func Test_getqflist_by_idx() | 5246 func Test_getqflist_by_idx() |
5167 call Xtest_getqflist_by_idx('c') | 5247 call Xtest_getqflist_by_idx('c') |
5214 Xclose | 5294 Xclose |
5215 set quickfixtextfunc&vim | 5295 set quickfixtextfunc&vim |
5216 Xwindow | 5296 Xwindow |
5217 call assert_equal('F1|10 col 2-7| green', getline(1)) | 5297 call assert_equal('F1|10 col 2-7| green', getline(1)) |
5218 call assert_equal('F1|20-25 col 4-8| blue', getline(2)) | 5298 call assert_equal('F1|20-25 col 4-8| blue', getline(2)) |
5299 Xclose | |
5300 | |
5301 set efm=%f:%l:%c:%m | |
5302 set quickfixtextfunc=Tqfexpr | |
5303 " Update the list with only the cwindow | |
5304 Xwindow | |
5305 only | |
5306 call g:Xsetlist([ | |
5307 \ { 'filename': 'F2', 'lnum': 20, 'col': 2, | |
5308 \ 'end_col': 7, 'text': 'red'} | |
5309 \ ]) | |
5310 call assert_equal(['F2-L20C2-red'], getline(1, '$')) | |
5311 new | |
5219 Xclose | 5312 Xclose |
5220 set efm& | 5313 set efm& |
5221 set quickfixtextfunc& | 5314 set quickfixtextfunc& |
5222 | 5315 |
5223 " Test for per list 'quickfixtextfunc' setting | 5316 " Test for per list 'quickfixtextfunc' setting |
5924 | 6017 |
5925 call delete('Xscript') | 6018 call delete('Xscript') |
5926 call delete('Xresult') | 6019 call delete('Xresult') |
5927 endfunc | 6020 endfunc |
5928 | 6021 |
6022 " Test for calling setqflist() function recursively | |
6023 func Test_recursive_setqflist() | |
6024 augroup QF_Test | |
6025 au! | |
6026 autocmd BufWinEnter quickfix call setqflist([], 'r') | |
6027 augroup END | |
6028 | |
6029 copen | |
6030 call assert_fails("call setqflist([], 'a')", 'E952:') | |
6031 | |
6032 augroup QF_Test | |
6033 au! | |
6034 augroup END | |
6035 %bw! | |
6036 endfunc | |
6037 | |
6038 " Test for failure to create a new window when selecting a file from the | |
6039 " quickfix window | |
6040 func Test_cwindow_newwin_fails() | |
6041 cgetexpr ["Xfile1:10:L10", "Xfile1:20:L20"] | |
6042 cwindow | |
6043 only | |
6044 let qf_wid = win_getid() | |
6045 " create the maximum number of scratch windows | |
6046 let hor_win_count = (&lines - 1)/2 | |
6047 let hor_split_count = hor_win_count - 1 | |
6048 for s in range(1, hor_split_count) | new | set buftype=nofile | endfor | |
6049 call win_gotoid(qf_wid) | |
6050 call assert_fails('exe "normal \<CR>"', 'E36:') | |
6051 %bw! | |
6052 endfunc | |
6053 | |
6054 " Test for updating the location list when only the location list window is | |
6055 " present and the corresponding file window is closed. | |
6056 func Test_loclist_update_with_llwin_only() | |
6057 %bw! | |
6058 new | |
6059 wincmd w | |
6060 lexpr ["Xfile1:1:Line1"] | |
6061 lopen | |
6062 wincmd p | |
6063 close | |
6064 call setloclist(2, [], 'r', {'lines': ["Xtest2:2:Line2"]}) | |
6065 call assert_equal(['Xtest2|2| Line2'], getbufline(winbufnr(2), 1, '$')) | |
6066 %bw! | |
6067 endfunc | |
6068 | |
6069 " Test for getting the quickfix list after a buffer with an error is wiped out | |
6070 func Test_getqflist_wiped_out_buffer() | |
6071 %bw! | |
6072 cexpr ["Xtest1:34:Wiped out"] | |
6073 let bnum = bufnr('Xtest1') | |
6074 call assert_equal(bnum, getqflist()[0].bufnr) | |
6075 bw Xtest1 | |
6076 call assert_equal(0, getqflist()[0].bufnr) | |
6077 %bw! | |
6078 endfunc | |
5929 | 6079 |
5930 " vim: shiftwidth=2 sts=2 expandtab | 6080 " vim: shiftwidth=2 sts=2 expandtab |