From 9ef371fd545034519e4259da001a52e9f7838ffe Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 13 Dec 2016 14:15:10 -0500 Subject: test: quickfix: Move upstream vim quickfix test to src/nvim/testdir Massaging the upstream patches for this test into the lua tests are too cumbersome and slow down patching. --- src/nvim/testdir/Makefile | 5 +- src/nvim/testdir/test_quickfix.vim | 681 ++++++++++++++++++++++++++++++ test/functional/legacy/quickfix_spec.lua | 683 ------------------------------- 3 files changed, 684 insertions(+), 685 deletions(-) create mode 100644 src/nvim/testdir/test_quickfix.vim delete mode 100644 test/functional/legacy/quickfix_spec.lua diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 0118597eb8..7cd1921ce1 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -30,15 +30,16 @@ SCRIPTS := \ # Tests using runtest.vim.vim. # Keep test_alot*.res as the last one, sort the others. NEW_TESTS = \ + test_cmdline.res \ test_cscope.res \ - test_cmdline.res \ test_diffmode.res \ test_hardcopy.res \ test_help_tagjump.res \ test_history.res \ test_langmap.res \ - test_match.res \ + test_match.res \ test_matchadd_conceal.res \ + test_quickfix.res \ test_syntax.res \ test_usercommands.res \ test_timers.res \ diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim new file mode 100644 index 0000000000..9dbd00b001 --- /dev/null +++ b/src/nvim/testdir/test_quickfix.vim @@ -0,0 +1,681 @@ +" Test for the quickfix commands. + +if !has('quickfix') + finish +endif + +set encoding=utf-8 + +" Tests for the :clist and :llist commands +function XlistTests(cchar) + let Xlist = a:cchar . 'list' + let Xgetexpr = a:cchar . 'getexpr' + + " With an empty list, command should return error + exe Xgetexpr . ' []' + exe 'silent! ' . Xlist + call assert_true(v:errmsg ==# 'E42: No Errors') + + " Populate the list and then try + exe Xgetexpr . " ['non-error 1', 'Xtestfile1:1:3:Line1', + \ 'non-error 2', 'Xtestfile2:2:2:Line2', + \ 'non-error 3', 'Xtestfile3:3:1:Line3']" + + " List only valid entries + redir => result + exe Xlist + redir END + let l = split(result, "\n") + call assert_equal([' 2 Xtestfile1:1 col 3: Line1', + \ ' 4 Xtestfile2:2 col 2: Line2', + \ ' 6 Xtestfile3:3 col 1: Line3'], l) + + " List all the entries + redir => result + exe Xlist . "!" + redir END + let l = split(result, "\n") + call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1', + \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2', + \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l) + + " List a range of errors + redir => result + exe Xlist . " 3,6" + redir END + let l = split(result, "\n") + call assert_equal([' 4 Xtestfile2:2 col 2: Line2', + \ ' 6 Xtestfile3:3 col 1: Line3'], l) + + redir => result + exe Xlist . "! 3,4" + redir END + let l = split(result, "\n") + call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) + + redir => result + exe Xlist . " -6,-4" + redir END + let l = split(result, "\n") + call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l) + + redir => result + exe Xlist . "! -5,-3" + redir END + let l = split(result, "\n") + call assert_equal([' 2 Xtestfile1:1 col 3: Line1', + \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) +endfunction + +function Test_clist() + call XlistTests('c') + call XlistTests('l') +endfunction + +" Tests for the :colder, :cnewer, :lolder and :lnewer commands +" Note that this test assumes that a quickfix/location list is +" already set by the caller. +function XageTests(cchar) + let Xolder = a:cchar . 'older' + let Xnewer = a:cchar . 'newer' + let Xgetexpr = a:cchar . 'getexpr' + if a:cchar == 'c' + let Xgetlist = 'getqflist()' + else + let Xgetlist = 'getloclist(0)' + endif + + " Jumping to a non existent list should return error + exe 'silent! ' . Xolder . ' 99' + call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack') + + exe 'silent! ' . Xnewer . ' 99' + call assert_true(v:errmsg ==# 'E381: At top of quickfix stack') + + " Add three quickfix/location lists + exe Xgetexpr . " ['Xtestfile1:1:3:Line1']" + exe Xgetexpr . " ['Xtestfile2:2:2:Line2']" + exe Xgetexpr . " ['Xtestfile3:3:1:Line3']" + + " Go back two lists + exe Xolder + exe 'let l = ' . Xgetlist + call assert_equal('Line2', l[0].text) + + " Go forward two lists + exe Xnewer + exe 'let l = ' . Xgetlist + call assert_equal('Line3', l[0].text) + + " Test for the optional count argument + exe Xolder . ' 2' + exe 'let l = ' . Xgetlist + call assert_equal('Line1', l[0].text) + + exe Xnewer . ' 2' + exe 'let l = ' . Xgetlist + call assert_equal('Line3', l[0].text) +endfunction + +function Test_cage() + let list = [{'bufnr': 1, 'lnum': 1}] + call setqflist(list) + call XageTests('c') + + call setloclist(0, list) + call XageTests('l') +endfunction + +" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen +" commands +function XwindowTests(cchar) + let Xwindow = a:cchar . 'window' + let Xclose = a:cchar . 'close' + let Xopen = a:cchar . 'open' + let Xgetexpr = a:cchar . 'getexpr' + + " Create a list with no valid entries + exe Xgetexpr . " ['non-error 1', 'non-error 2', 'non-error 3']" + + " Quickfix/Location window should not open with no valid errors + exe Xwindow + call assert_true(winnr('$') == 1) + + " Create a list with valid entries + exe Xgetexpr . " ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2', + \ 'Xtestfile3:3:1:Line3']" + + " Open the window + exe Xwindow + call assert_true(winnr('$') == 2 && winnr() == 2 && + \ getline('.') ==# 'Xtestfile1|1 col 3| Line1') + + " Close the window + exe Xclose + call assert_true(winnr('$') == 1) + + " Create a list with no valid entries + exe Xgetexpr . " ['non-error 1', 'non-error 2', 'non-error 3']" + + " Open the window + exe Xopen . ' 5' + call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1' + \ && winheight('.') == 5) + + " Opening the window again, should move the cursor to that window + wincmd t + exe Xopen . ' 7' + call assert_true(winnr('$') == 2 && winnr() == 2 && + \ winheight('.') == 7 && + \ getline('.') ==# '|| non-error 1') + + + " Calling cwindow should close the quickfix window with no valid errors + exe Xwindow + call assert_true(winnr('$') == 1) +endfunction + +function Test_cwindow() + call XwindowTests('c') + call XwindowTests('l') +endfunction + +" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile +" commands. +function XfileTests(cchar) + let Xfile = a:cchar . 'file' + let Xgetfile = a:cchar . 'getfile' + let Xaddfile = a:cchar . 'addfile' + if a:cchar == 'c' + let Xgetlist = 'getqflist()' + else + let Xgetlist = 'getloclist(0)' + endif + + call writefile(['Xtestfile1:700:10:Line 700', + \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1') + + enew! + exe Xfile . ' Xqftestfile1' + exe 'let l = ' . Xgetlist + call assert_true(len(l) == 2 && + \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && + \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') + + " Run cfile/lfile from a modified buffer + enew! + silent! put ='Quickfix' + exe 'silent! ' . Xfile . ' Xqftestfile1' + call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)') + + call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1') + exe Xaddfile . ' Xqftestfile1' + exe 'let l = ' . Xgetlist + call assert_true(len(l) == 3 && + \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900') + + call writefile(['Xtestfile1:222:77:Line 222', + \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1') + + enew! + exe Xgetfile . ' Xqftestfile1' + exe 'let l = ' . Xgetlist + call assert_true(len(l) == 2 && + \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' && + \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333') + + call delete('Xqftestfile1') +endfunction + +function Test_cfile() + call XfileTests('c') + call XfileTests('l') +endfunction + +" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and +" :lgetbuffer commands. +function XbufferTests(cchar) + let Xbuffer = a:cchar . 'buffer' + let Xgetbuffer = a:cchar . 'getbuffer' + let Xaddbuffer = a:cchar . 'addbuffer' + if a:cchar == 'c' + let Xgetlist = 'getqflist()' + else + let Xgetlist = 'getloclist(0)' + endif + + enew! + silent! call setline(1, ['Xtestfile7:700:10:Line 700', + \ 'Xtestfile8:800:15:Line 800']) + exe Xbuffer . "!" + exe 'let l = ' . Xgetlist + call assert_true(len(l) == 2 && + \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && + \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') + + enew! + silent! call setline(1, ['Xtestfile9:900:55:Line 900', + \ 'Xtestfile10:950:66:Line 950']) + exe Xgetbuffer + exe 'let l = ' . Xgetlist + call assert_true(len(l) == 2 && + \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' && + \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950') + + enew! + silent! call setline(1, ['Xtestfile11:700:20:Line 700', + \ 'Xtestfile12:750:25:Line 750']) + exe Xaddbuffer + exe 'let l = ' . Xgetlist + call assert_true(len(l) == 4 && + \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' && + \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' && + \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750') + +endfunction + +function Test_cbuffer() + call XbufferTests('c') + call XbufferTests('l') +endfunction + +function Test_helpgrep() + helpgrep quickfix + copen + " This wipes out the buffer, make sure that doesn't cause trouble. + cclose +endfunc + +func Test_errortitle() + augroup QfBufWinEnter + au! + au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE') + augroup END + copen + let a=[{'lnum': 308, 'bufnr': bufnr(''), 'col': 58, 'valid': 1, 'vcol': 0, 'nr': 0, 'type': '', 'pattern': '', 'text': ' au BufWinEnter * :let g:a=get(w:, ''quickfix_title'', ''NONE'')'}] + call setqflist(a) + call assert_equal(':setqflist()', g:a) + augroup QfBufWinEnter + au! + augroup END + augroup! QfBufWinEnter +endfunc + +func Test_vimgreptitle() + augroup QfBufWinEnter + au! + au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE') + augroup END + try + vimgrep /pattern/j file + catch /E480/ + endtry + copen + call assert_equal(': vimgrep /pattern/j file', g:a) + augroup QfBufWinEnter + au! + augroup END + augroup! QfBufWinEnter +endfunc + +function XqfTitleTests(cchar) + let Xgetexpr = a:cchar . 'getexpr' + if a:cchar == 'c' + let Xgetlist = 'getqflist()' + else + let Xgetlist = 'getloclist(0)' + endif + let Xopen = a:cchar . 'open' + let Xclose = a:cchar . 'close' + + exe Xgetexpr . " ['file:1:1:message']" + exe 'let l = ' . Xgetlist + if a:cchar == 'c' + call setqflist(l, 'r') + else + call setloclist(0, l, 'r') + endif + + exe Xopen + if a:cchar == 'c' + let title = ':setqflist()' + else + let title = ':setloclist()' + endif + call assert_equal(title, w:quickfix_title) + exe Xclose +endfunction + +" Tests for quickfix window's title +function Test_qf_title() + call XqfTitleTests('c') + call XqfTitleTests('l') +endfunction + +" Tests for 'errorformat' +function Test_efm() + let save_efm = &efm + set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%# + cgetexpr ['WWWW', 'EEEE', 'CCCC'] + let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) + call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l) + cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC'] + let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) + call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l) + cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY'] + let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) + call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l) + let &efm = save_efm +endfunction + +" This will test for problems in quickfix: +" A. incorrectly copying location lists which caused the location list to show +" a different name than the file that was actually being displayed. +" B. not reusing the window for which the location list window is opened but +" instead creating new windows. +" C. make sure that the location list window is not reused instead of the +" window it belongs to. +" +" Set up the test environment: +function! ReadTestProtocol(name) + let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '') + let word = substitute(base, '\v(.*)\..*', '\1', '') + + setl modifiable + setl noreadonly + setl noswapfile + setl bufhidden=delete + %del _ + " For problem 2: + " 'buftype' has to be set to reproduce the constant opening of new windows + setl buftype=nofile + + call setline(1, word) + + setl nomodified + setl nomodifiable + setl readonly + exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '') +endfunction + +function Test_locationlist() + enew + + augroup testgroup + au! + autocmd BufReadCmd test://* call ReadTestProtocol(expand("")) + augroup END + + let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ] + + let qflist = [] + for word in words + call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', }) + " NOTE: problem 1: + " intentionally not setting 'lnum' so that the quickfix entries are not + " valid + call setloclist(0, qflist, ' ') + endfor + + " Test A + lrewind + enew + lopen + lnext + lnext + lnext + lnext + vert split + wincmd L + lopen + wincmd p + lnext + let fileName = expand("%") + wincmd p + let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '') + let fileName = substitute(fileName, '\\', '/', 'g') + let locationListFileName = substitute(locationListFileName, '\\', '/', 'g') + call assert_equal("test://bar.txt", fileName) + call assert_equal("test://bar.txt", locationListFileName) + + wincmd n | only + + " Test B: + lrewind + lopen + 2 + exe "normal \" + wincmd p + 3 + exe "normal \" + wincmd p + 4 + exe "normal \" + call assert_equal(2, winnr('$')) + wincmd n | only + + " Test C: + lrewind + lopen + " Let's move the location list window to the top to check whether it (the + " first window found) will be reused when we try to open new windows: + wincmd K + 2 + exe "normal \" + wincmd p + 3 + exe "normal \" + wincmd p + 4 + exe "normal \" + 1wincmd w + call assert_equal('quickfix', &buftype) + 2wincmd w + let bufferName = expand("%") + let bufferName = substitute(bufferName, '\\', '/', 'g') + call assert_equal('test://quux.txt', bufferName) + + wincmd n | only + + augroup! testgroup +endfunction + +function Test_locationlist_curwin_was_closed() + augroup testgroup + au! + autocmd BufReadCmd t call R(expand("")) + augroup END + + function! R(n) + quit + endfunc + + new + let q = [] + call add(q, {'filename': 't' }) + call setloclist(0, q) + call assert_fails('lrewind', 'E924:') + + augroup! testgroup +endfunction + +" More tests for 'errorformat' +function! Test_efm1() + if !has('unix') + " The 'errorformat' setting is different on non-Unix systems. + " This test works only on Unix-like systems. + return + endif + + let l = [ + \ '"Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.', + \ '"Xtestfile", line 6 col 19; this is an error', + \ 'gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c', + \ 'Xtestfile:9: parse error before `asd''', + \ 'make: *** [vim] Error 1', + \ 'in file "Xtestfile" linenr 10: there is an error', + \ '', + \ '2 returned', + \ '"Xtestfile", line 11 col 1; this is an error', + \ '"Xtestfile", line 12 col 2; this is another error', + \ '"Xtestfile", line 14:10; this is an error in column 10', + \ '=Xtestfile=, line 15:10; this is another error, but in vcol 10 this time', + \ '"Xtestfile", linenr 16: yet another problem', + \ 'Error in "Xtestfile" at line 17:', + \ 'x should be a dot', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17', + \ ' ^', + \ 'Error in "Xtestfile" at line 18:', + \ 'x should be a dot', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18', + \ '.............^', + \ 'Error in "Xtestfile" at line 19:', + \ 'x should be a dot', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19', + \ '--------------^', + \ 'Error in "Xtestfile" at line 20:', + \ 'x should be a dot', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20', + \ ' ^', + \ '', + \ 'Does anyone know what is the problem and how to correction it?', + \ '"Xtestfile", line 21 col 9: What is the title of the quickfix window?', + \ '"Xtestfile", line 22 col 9: What is the title of the quickfix window?' + \ ] + + call writefile(l, 'Xerrorfile1') + call writefile(l[:-2], 'Xerrorfile2') + + let m = [ + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22' + \ ] + call writefile(m, 'Xtestfile') + + let save_efm = &efm + set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m + set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m + + exe 'cf Xerrorfile2' + clast + copen + call assert_equal(':cf Xerrorfile2', w:quickfix_title) + wincmd p + + exe 'cf Xerrorfile1' + call assert_equal([4, 12], [line('.'), col('.')]) + cn + call assert_equal([6, 19], [line('.'), col('.')]) + cn + call assert_equal([9, 2], [line('.'), col('.')]) + cn + call assert_equal([10, 2], [line('.'), col('.')]) + cn + call assert_equal([11, 1], [line('.'), col('.')]) + cn + call assert_equal([12, 2], [line('.'), col('.')]) + cn + call assert_equal([14, 10], [line('.'), col('.')]) + cn + call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')]) + cn + call assert_equal([16, 2], [line('.'), col('.')]) + cn + call assert_equal([17, 6], [line('.'), col('.')]) + cn + call assert_equal([18, 7], [line('.'), col('.')]) + cn + call assert_equal([19, 8], [line('.'), col('.')]) + cn + call assert_equal([20, 9], [line('.'), col('.')]) + clast + cprev + cprev + wincmd w + call assert_equal(':cf Xerrorfile1', w:quickfix_title) + wincmd p + + let &efm = save_efm + call delete('Xerrorfile1') + call delete('Xerrorfile2') + call delete('Xtestfile') +endfunction + +function XquickfixChangedByAutocmd(cchar) + let Xolder = a:cchar . 'older' + let Xgetexpr = a:cchar . 'getexpr' + let Xrewind = a:cchar . 'rewind' + if a:cchar == 'c' + let Xsetlist = 'setqflist(' + let ErrorNr = 'E925' + function! ReadFunc() + colder + cgetexpr [] + endfunc + else + let Xsetlist = 'setloclist(0,' + let ErrorNr = 'E926' + function! ReadFunc() + lolder + lgetexpr [] + endfunc + endif + + augroup testgroup + au! + autocmd BufReadCmd t call ReadFunc() + augroup END + + bwipe! + let words = [ "a", "b" ] + let qflist = [] + for word in words + call add(qflist, {'filename': 't'}) + exec "call " . Xsetlist . "qflist, '')" + endfor + exec "call assert_fails('" . Xrewind . "', '" . ErrorNr . ":')" + + augroup! testgroup +endfunc + +function Test_quickfix_was_changed_by_autocmd() + call XquickfixChangedByAutocmd('c') + call XquickfixChangedByAutocmd('l') +endfunction + +func Test_caddbuffer_to_empty() + helpgr quickfix + call setqflist([], 'r') + cad + try + cn + catch + " number of matches is unknown + call assert_true(v:exception =~ 'E553:') + endtry + quit! +endfunc + +func Test_cgetexpr_works() + " this must not crash Vim + cgetexpr [$x] +endfunc diff --git a/test/functional/legacy/quickfix_spec.lua b/test/functional/legacy/quickfix_spec.lua deleted file mode 100644 index 5787ff8ff3..0000000000 --- a/test/functional/legacy/quickfix_spec.lua +++ /dev/null @@ -1,683 +0,0 @@ --- Test for the quickfix commands. - -local helpers = require('test.functional.helpers')(after_each) -local source, clear = helpers.source, helpers.clear -local eq, nvim, call = helpers.eq, helpers.meths, helpers.call -local eval = helpers.eval -local execute = helpers.execute - -local function expected_empty() - eq({}, nvim.get_vvar('errors')) -end - -describe('helpgrep', function() - before_each(function() - clear() - - source([[ - " Tests for the :clist and :llist commands - function XlistTests(cchar) - let Xlist = a:cchar . 'list' - let Xgetexpr = a:cchar . 'getexpr' - - " With an empty list, command should return error - exe Xgetexpr . ' []' - exe 'silent! ' . Xlist - call assert_true(v:errmsg ==# 'E42: No Errors') - - " Populate the list and then try - exe Xgetexpr . " ['non-error 1', 'Xtestfile1:1:3:Line1', - \ 'non-error 2', 'Xtestfile2:2:2:Line2', - \ 'non-error 3', 'Xtestfile3:3:1:Line3']" - - " List only valid entries - redir => result - exe 'silent ' . Xlist - redir END - let l = split(result, "\n") - call assert_equal([' 2 Xtestfile1:1 col 3: Line1', - \ ' 4 Xtestfile2:2 col 2: Line2', - \ ' 6 Xtestfile3:3 col 1: Line3'], l) - - " List all the entries - redir => result - exe 'silent ' . Xlist . "!" - redir END - let l = split(result, "\n") - call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1', - \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2', - \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l) - - " List a range of errors - redir => result - exe 'silent '. Xlist . " 3,6" - redir END - let l = split(result, "\n") - call assert_equal([' 4 Xtestfile2:2 col 2: Line2', - \ ' 6 Xtestfile3:3 col 1: Line3'], l) - - redir => result - exe 'silent ' . Xlist . "! 3,4" - redir END - let l = split(result, "\n") - call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) - - redir => result - exe 'silent ' . Xlist . " -6,-4" - redir END - let l = split(result, "\n") - call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l) - - redir => result - exe 'silent ' . Xlist . "! -5,-3" - redir END - let l = split(result, "\n") - call assert_equal([' 2 Xtestfile1:1 col 3: Line1', - \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) - endfunction - - " Tests for the :colder, :cnewer, :lolder and :lnewer commands - " Note that this test assumes that a quickfix/location list is - " already set by the caller - function XageTests(cchar) - let Xolder = a:cchar . 'older' - let Xnewer = a:cchar . 'newer' - let Xgetexpr = a:cchar . 'getexpr' - if a:cchar == 'c' - let Xgetlist = 'getqflist()' - else - let Xgetlist = 'getloclist(0)' - endif - - " Jumping to a non existent list should return error - exe 'silent! ' . Xolder . ' 99' - call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack') - - exe 'silent! ' . Xnewer . ' 99' - call assert_true(v:errmsg ==# 'E381: At top of quickfix stack') - - " Add three quickfix/location lists - exe Xgetexpr . " ['Xtestfile1:1:3:Line1']" - exe Xgetexpr . " ['Xtestfile2:2:2:Line2']" - exe Xgetexpr . " ['Xtestfile3:3:1:Line3']" - - " Go back two lists - exe Xolder - exe 'let l = ' . Xgetlist - call assert_equal('Line2', l[0].text) - - " Go forward two lists - exe Xnewer - exe 'let l = ' . Xgetlist - call assert_equal('Line3', l[0].text) - - " Test for the optional count argument - exe Xolder . ' 2' - exe 'let l = ' . Xgetlist - call assert_equal('Line1', l[0].text) - - exe Xnewer . ' 2' - exe 'let l = ' . Xgetlist - call assert_equal('Line3', l[0].text) - endfunction - - " Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen - " commands - function XwindowTests(cchar) - let Xwindow = a:cchar . 'window' - let Xclose = a:cchar . 'close' - let Xopen = a:cchar . 'open' - let Xgetexpr = a:cchar . 'getexpr' - - " Create a list with no valid entries - exe Xgetexpr . " ['non-error 1', 'non-error 2', 'non-error 3']" - - " Quickfix/Location window should not open with no valid errors - exe Xwindow - call assert_true(winnr('$') == 1) - - " Create a list with valid entries - exe Xgetexpr . " ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2', - \ 'Xtestfile3:3:1:Line3']" - - " Open the window - exe Xwindow - call assert_true(winnr('$') == 2 && winnr() == 2 && - \ getline('.') ==# 'Xtestfile1|1 col 3| Line1') - - " Close the window - exe Xclose - call assert_true(winnr('$') == 1) - - " Create a list with no valid entries - exe Xgetexpr . " ['non-error 1', 'non-error 2', 'non-error 3']" - - " Open the window - exe Xopen . ' 5' - call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1' - \ && winheight('.') == 5) - - " Opening the window again, should move the cursor to that window - wincmd t - exe Xopen . ' 7' - call assert_true(winnr('$') == 2 && winnr() == 2 && - \ winheight('.') == 7 && - \ getline('.') ==# '|| non-error 1') - - - " Calling cwindow should close the quickfix window with no valid errors - exe Xwindow - call assert_true(winnr('$') == 1) - endfunction - - " Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile - " commands. - function XfileTests(cchar) - let Xfile = a:cchar . 'file' - let Xgetfile = a:cchar . 'getfile' - let Xaddfile = a:cchar . 'addfile' - if a:cchar == 'c' - let Xgetlist = 'getqflist()' - else - let Xgetlist = 'getloclist(0)' - endif - - call writefile(['Xtestfile1:700:10:Line 700', - \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1') - - enew! - exe Xfile . ' Xqftestfile1' - exe 'let l = ' . Xgetlist - call assert_true(len(l) == 2 && - \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && - \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') - - " Run cfile/lfile from a modified buffer - enew! - silent! put ='Quickfix' - exe 'silent! ' . Xfile . ' Xqftestfile1' - call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)') - - call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1') - exe Xaddfile . ' Xqftestfile1' - exe 'let l = ' . Xgetlist - call assert_true(len(l) == 3 && - \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900') - - call writefile(['Xtestfile1:222:77:Line 222', - \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1') - - enew! - exe Xgetfile . ' Xqftestfile1' - exe 'let l = ' . Xgetlist - call assert_true(len(l) == 2 && - \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' && - \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333') - - call delete('Xqftestfile1') - endfunction - - " Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and - " :lgetbuffer commands. - function XbufferTests(cchar) - let Xbuffer = a:cchar . 'buffer' - let Xgetbuffer = a:cchar . 'getbuffer' - let Xaddbuffer = a:cchar . 'addbuffer' - if a:cchar == 'c' - let Xgetlist = 'getqflist()' - else - let Xgetlist = 'getloclist(0)' - endif - - enew! - silent! call setline(1, ['Xtestfile7:700:10:Line 700', - \ 'Xtestfile8:800:15:Line 800']) - exe Xbuffer . "!" - exe 'let l = ' . Xgetlist - call assert_true(len(l) == 2 && - \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && - \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') - - enew! - silent! call setline(1, ['Xtestfile9:900:55:Line 900', - \ 'Xtestfile10:950:66:Line 950']) - exe Xgetbuffer - exe 'let l = ' . Xgetlist - call assert_true(len(l) == 2 && - \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' && - \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950') - - enew! - silent! call setline(1, ['Xtestfile11:700:20:Line 700', - \ 'Xtestfile12:750:25:Line 750']) - exe Xaddbuffer - exe 'let l = ' . Xgetlist - call assert_true(len(l) == 4 && - \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' && - \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' && - \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750') - - endfunction - - function Test_locationlist_curwin_was_closed() - augroup testgroup - au! - autocmd BufReadCmd t call R(expand("")) - augroup END - - function! R(n) - quit - endfunc - - new - let q = [] - call add(q, {'filename': 't' }) - call setloclist(0, q) - call assert_fails('lrewind', 'E924:') - - augroup! testgroup - endfunction - - " This will test for problems in quickfix: - " A. incorrectly copying location lists which caused the location list to show - " a different name than the file that was actually being displayed. - " B. not reusing the window for which the location list window is opened but - " instead creating new windows. - " C. make sure that the location list window is not reused instead of the - " window it belongs to. - " - " Set up the test environment: - function! ReadTestProtocol(name) - let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '') - let word = substitute(base, '\v(.*)\..*', '\1', '') - - setl modifiable - setl noreadonly - setl noswapfile - setl bufhidden=delete - %del _ - " For problem 2: - " 'buftype' has to be set to reproduce the constant opening of new windows - setl buftype=nofile - - call setline(1, word) - - setl nomodified - setl nomodifiable - setl readonly - exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '') - endfunction - - function Test_locationlist() - enew - - augroup testgroup - au! - autocmd BufReadCmd test://* call ReadTestProtocol(expand("")) - augroup END - - let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ] - - let qflist = [] - for word in words - call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', }) - " NOTE: problem 1: - " intentionally not setting 'lnum' so that the quickfix entries are not - " valid - call setloclist(0, qflist, ' ') - endfor - - " Test A - lrewind - enew - lopen - lnext - lnext - lnext - lnext - vert split - wincmd L - lopen - wincmd p - lnext - let fileName = expand("%") - wincmd p - let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '') - let fileName = substitute(fileName, '\\', '/', 'g') - let locationListFileName = substitute(locationListFileName, '\\', '/', 'g') - call assert_equal("test://bar.txt", fileName) - call assert_equal("test://bar.txt", locationListFileName) - - wincmd n | only - - " Test B: - lrewind - lopen - 2 - exe "normal \" - wincmd p - 3 - exe "normal \" - wincmd p - 4 - exe "normal \" - call assert_equal(2, winnr('$')) - wincmd n | only - - " Test C: - lrewind - lopen - " Let's move the location list window to the top to check whether it (the - " first window found) will be reused when we try to open new windows: - wincmd K - 2 - exe "normal \" - wincmd p - 3 - exe "normal \" - wincmd p - 4 - exe "normal \" - 1wincmd w - call assert_equal('quickfix', &buftype) - 2wincmd w - let bufferName = expand("%") - let bufferName = substitute(bufferName, '\\', '/', 'g') - call assert_equal('test://quux.txt', bufferName) - - wincmd n | only - - augroup! testgroup - endfunction - - func Test_vimgreptitle() - augroup QfBufWinEnter - au! - au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE') - augroup END - try - vimgrep /pattern/j file - catch /E480/ - endtry - copen - call assert_equal(': vimgrep /pattern/j file', g:a) - augroup QfBufWinEnter - au! - augroup END - augroup! QfBufWinEnter - endfunc - - function XquickfixChangedByAutocmd(cchar) - let Xolder = a:cchar . 'older' - let Xgetexpr = a:cchar . 'getexpr' - let Xrewind = a:cchar . 'rewind' - if a:cchar == 'c' - let Xsetlist = 'setqflist(' - let ErrorNr = 'E925' - function! ReadFunc() - colder - cgetexpr [] - endfunc - else - let Xsetlist = 'setloclist(0,' - let ErrorNr = 'E926' - function! ReadFunc() - lolder - lgetexpr [] - endfunc - endif - - augroup testgroup - au! - autocmd BufReadCmd t call ReadFunc() - augroup END - - bwipe! - let words = [ "a", "b" ] - let qflist = [] - for word in words - call add(qflist, {'filename': 't'}) - exec "call " . Xsetlist . "qflist, '')" - endfor - exec "call assert_fails('" . Xrewind . "', '" . ErrorNr . ":')" - - augroup! testgroup - endfunc - - func Test_caddbuffer_to_empty() - helpgr quickfix - call setqflist([], 'r') - cad - try - silent cn - catch - " number of matches is unknown - call assert_true(v:exception =~ 'E553:') - endtry - quit! - endfunc - ]]) - end) - - it('copen/cclose work', function() - source([[ - helpgrep quickfix - copen - " This wipes out the buffer, make sure that doesn't cause trouble. - cclose - ]]) - end) - - it('clist/llist work', function() - call('XlistTests', 'c') - expected_empty() - call('XlistTests', 'l') - expected_empty() - end) - - it('colder/cnewer and lolder/lnewer work', function() - local list = {{bufnr = 1, lnum = 1}} - call('setqflist', list) - call('XageTests', 'c') - expected_empty() - - call('setloclist', 0, list) - call('XageTests', 'l') - expected_empty() - end) - - it('quickfix/location list window commands work', function() - call('XwindowTests', 'c') - expected_empty() - call('XwindowTests', 'l') - expected_empty() - end) - - it('quickfix/location list file commands work', function() - call('XfileTests', 'c') - expected_empty() - call('XfileTests', 'l') - expected_empty() - end) - - it('quickfix/location list buffer commands work', function() - call('XbufferTests', 'c') - expected_empty() - call('XbufferTests', 'l') - expected_empty() - end) - - it('autocommands triggered by quickfix can get title', function() - execute('au FileType qf let g:foo = get(w:, "quickfix_title", "NONE")') - execute('call setqflist([])') - execute('copen') - eq(':setqflist()', eval('g:foo')) - end) - - it('does not truncate quickfix title', function() - call('Test_vimgreptitle') - expected_empty() - end) - - it('errors when an autocommand closes the location list\'s window', function() - call('Test_locationlist_curwin_was_closed') - expected_empty() - end) - - it('checks locationlist protocol read', function() - call('Test_locationlist') - expected_empty() - end) - - it('is changed by autocmd', function() - call('XquickfixChangedByAutocmd', 'c') - expected_empty() - call('XquickfixChangedByAutocmd', 'l') - expected_empty() - end) - - it('does not crash after using caddbuffer with an empty qf list', function() - call('Test_caddbuffer_to_empty') - expected_empty() - end) - - it('cgetexpr does not crash with a NULL element in a list', function() - execute('cgetexpr [$x]') - -- Still alive? - eq(2, eval('1+1')) - end) -end) - -describe('errorformat', function() - before_each(function() - clear() - - source([[ - " More tests for 'errorformat' - function! Test_efm1() - if !has('unix') - " The 'errorformat' setting is different on non-Unix systems. - " This test works only on Unix-like systems. - return - endif - - let l = [ - \ '"Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.', - \ '"Xtestfile", line 6 col 19; this is an error', - \ 'gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c', - \ 'Xtestfile:9: parse error before `asd''', - \ 'make: *** [vim] Error 1', - \ 'in file "Xtestfile" linenr 10: there is an error', - \ '', - \ '2 returned', - \ '"Xtestfile", line 11 col 1; this is an error', - \ '"Xtestfile", line 12 col 2; this is another error', - \ '"Xtestfile", line 14:10; this is an error in column 10', - \ '=Xtestfile=, line 15:10; this is another error, but in vcol 10 this time', - \ '"Xtestfile", linenr 16: yet another problem', - \ 'Error in "Xtestfile" at line 17:', - \ 'x should be a dot', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17', - \ ' ^', - \ 'Error in "Xtestfile" at line 18:', - \ 'x should be a dot', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18', - \ '.............^', - \ 'Error in "Xtestfile" at line 19:', - \ 'x should be a dot', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19', - \ '--------------^', - \ 'Error in "Xtestfile" at line 20:', - \ 'x should be a dot', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20', - \ ' ^', - \ '', - \ 'Does anyone know what is the problem and how to correction it?', - \ '"Xtestfile", line 21 col 9: What is the title of the quickfix window?', - \ '"Xtestfile", line 22 col 9: What is the title of the quickfix window?' - \ ] - - call writefile(l, 'Xerrorfile1') - call writefile(l[:-2], 'Xerrorfile2') - - let m = [ - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21', - \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22' - \ ] - call writefile(m, 'Xtestfile') - - let save_efm = &efm - set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m - set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m - - exe 'cf Xerrorfile2' - clast - copen - call assert_equal(':cf Xerrorfile2', w:quickfix_title) - wincmd p - - exe 'cf Xerrorfile1' - call assert_equal([4, 12], [line('.'), col('.')]) - cn - call assert_equal([6, 19], [line('.'), col('.')]) - cn - call assert_equal([9, 2], [line('.'), col('.')]) - cn - call assert_equal([10, 2], [line('.'), col('.')]) - cn - call assert_equal([11, 1], [line('.'), col('.')]) - cn - call assert_equal([12, 2], [line('.'), col('.')]) - cn - call assert_equal([14, 10], [line('.'), col('.')]) - cn - call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')]) - cn - call assert_equal([16, 2], [line('.'), col('.')]) - cn - call assert_equal([17, 6], [line('.'), col('.')]) - cn - call assert_equal([18, 7], [line('.'), col('.')]) - cn - call assert_equal([19, 8], [line('.'), col('.')]) - cn - call assert_equal([20, 9], [line('.'), col('.')]) - clast - cprev - cprev - wincmd w - call assert_equal(':cf Xerrorfile1', w:quickfix_title) - wincmd p - - let &efm = save_efm - call delete('Xerrorfile1') - call delete('Xerrorfile2') - call delete('Xtestfile') - endfunction - ]]) - end) - - it('works', function() - call('Test_efm1') - expected_empty() - end) -end) -- cgit From e89efe75f9fd872e2c7323ea525b35af90e8afa0 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 12 Dec 2016 10:56:00 -0500 Subject: vim-patch:7.4.1752 Problem: When adding to the quickfix list the current position is reset. Solution: Do not reset the position when not needed. (Yegappan Lakshmanan) https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28 --- src/nvim/quickfix.c | 26 ++++++++++++--------- src/nvim/testdir/test_quickfix.vim | 48 ++++++++++++++++++++++++++++++++++++++ src/nvim/version.c | 2 +- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index f0d77f9e2b..b97530b700 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -786,7 +786,7 @@ qf_init_end: xfree(pattern); xfree(fmtstr); - qf_update_buffer(qi); + qf_update_buffer(qi, true); return retval; } @@ -1927,7 +1927,7 @@ static void qf_msg(qf_info_T *qi) smsg(_("error list %d of %d; %d errors"), qi->qf_curlist + 1, qi->qf_listcount, qi->qf_lists[qi->qf_curlist].qf_count); - qf_update_buffer(qi); + qf_update_buffer(qi, true); } /* @@ -2314,7 +2314,7 @@ static buf_T *qf_find_buf(qf_info_T *qi) /* * Find the quickfix buffer. If it exists, update the contents. */ -static void qf_update_buffer(qf_info_T *qi) +static void qf_update_buffer(qf_info_T *qi, bool update_cursor) { buf_T *buf; win_T *win; @@ -2337,8 +2337,9 @@ static void qf_update_buffer(qf_info_T *qi) /* restore curwin/curbuf and a few other things */ aucmd_restbuf(&aco); - - (void)qf_win_pos_update(qi, 0); + if (update_cursor) { + (void)qf_win_pos_update(qi, 0); + } } } @@ -3240,7 +3241,7 @@ void ex_vimgrep(exarg_T *eap) qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start; qi->qf_lists[qi->qf_curlist].qf_index = 1; - qf_update_buffer(qi); + qf_update_buffer(qi, true); if (au_name != NULL) apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, @@ -3624,12 +3625,15 @@ int set_errorlist(win_T *wp, list_T *list, int action, char_u *title) qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE; else qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; - qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start; - if (qi->qf_lists[qi->qf_curlist].qf_count > 0) { - qi->qf_lists[qi->qf_curlist].qf_index = 1; + if (action != 'a') { + qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start; + if (qi->qf_lists[qi->qf_curlist].qf_count > 0) { + qi->qf_lists[qi->qf_curlist].qf_index = 1; + } } - qf_update_buffer(qi); + // Don't update the cursor in quickfix window when appending entries + qf_update_buffer(qi, (action != 'a')); return retval; } @@ -3885,7 +3889,7 @@ void ex_helpgrep(exarg_T *eap) /* Darn, some plugin changed the value. */ free_string_option(save_cpo); - qf_update_buffer(qi); + qf_update_buffer(qi, true); if (au_name != NULL) { apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 9dbd00b001..9955b4f775 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -679,3 +679,51 @@ func Test_cgetexpr_works() " this must not crash Vim cgetexpr [$x] endfunc + +" Tests for the setqflist() and setloclist() functions +function SetXlistTests(cchar, bnum) + if a:cchar == 'c' + let Xsetlist = function('setqflist') + let Xgetlist = function('getqflist') + let Xnext = 'cnext' + else + let Xsetlist = function('setloclist', [0]) + let Xgetlist = function('getloclist', [0]) + let Xnext = 'lnext' + endif + + call Xsetlist([{'bufnr': a:bnum, 'lnum': 1}, + \ {'bufnr': a:bnum, 'lnum': 2}]) + let l = Xgetlist() + call assert_equal(2, len(l)) + call assert_equal(2, l[1].lnum) + + exe Xnext + call Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a') + let l = Xgetlist() + call assert_equal(3, len(l)) + exe Xnext + call assert_equal(3, line('.')) + + call Xsetlist([{'bufnr': a:bnum, 'lnum': 3}, + \ {'bufnr': a:bnum, 'lnum': 4}, + \ {'bufnr': a:bnum, 'lnum': 5}], 'r') + let l = Xgetlist() + call assert_equal(3, len(l)) + call assert_equal(5, l[2].lnum) + + call Xsetlist([]) + let l = Xgetlist() + call assert_equal(0, len(l)) +endfunction + +function Test_setqflist() + new Xtestfile | only + let bnum = bufnr('%') + call setline(1, range(1,5)) + + call SetXlistTests('c', bnum) + call SetXlistTests('l', bnum) + + call delete('Xtestfile') +endfunction diff --git a/src/nvim/version.c b/src/nvim/version.c index ed1d7448ea..d10d5cf75b 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -689,7 +689,7 @@ static int included_patches[] = { 1754, 1753, // 1753, - // 1752, + 1752, 1751, // 1750 NA // 1749 NA -- cgit From 29d7a597115b692a7e2e39d213b87ac566444a5c Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 12 Dec 2016 11:33:51 -0500 Subject: vim-patch:7.4.1768 Problem: Arguments of setqflist() are not checked properly. Solution: Add better checks, add a test. (Nikolai Pavlov, Hirohito Higashi, closes vim/vim#661) https://github.com/vim/vim/commit/d106e5ba7f10f0d2a14eaefe5d78405044416cb9 --- src/nvim/eval.c | 11 +++- src/nvim/po/uk.po | 4 +- src/nvim/testdir/test_quickfix.vim | 102 +++++++++++++++++++++++++++++--- src/nvim/version.c | 2 +- test/functional/viml/errorlist_spec.lua | 12 ++-- 5 files changed, 111 insertions(+), 20 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 39e121eb53..45364a1666 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -158,7 +158,7 @@ static char *e_listdictarg = N_( static char *e_emptykey = N_("E713: Cannot use empty key for Dictionary"); static char *e_listreq = N_("E714: List required"); static char *e_dictreq = N_("E715: Dictionary required"); -static char *e_strreq = N_("E114: String required"); +static char *e_stringreq = N_("E928: String required"); static char *e_toomanyarg = N_("E118: Too many arguments for function: %s"); static char *e_dictkey = N_("E716: Key not present in Dictionary: %s"); static char *e_funcexts = N_( @@ -14996,6 +14996,7 @@ static void f_setline(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void set_qf_ll_list(win_T *wp, typval_T *args, typval_T *rettv) FUNC_ATTR_NONNULL_ARG(2, 3) { + static char *e_invact = N_("E927: Invalid action: '%s'"); char_u *title = NULL; int action = ' '; rettv->vval.v_number = -1; @@ -15011,13 +15012,17 @@ static void set_qf_ll_list(win_T *wp, typval_T *args, typval_T *rettv) // Option argument was not given. goto skip_args; } else if (action_arg->v_type != VAR_STRING) { - EMSG(_(e_strreq)); + EMSG(_(e_stringreq)); return; } char_u *act = get_tv_string_chk(action_arg); - if (*act == 'a' || *act == 'r') { + if ((*act == 'a' || *act == 'r' || *act == ' ') && act[1] == NUL) { action = *act; } + else { + EMSG2(_(e_invact), act); + return; + } typval_T *title_arg = &args[2]; if (title_arg->v_type == VAR_UNKNOWN) { diff --git a/src/nvim/po/uk.po b/src/nvim/po/uk.po index bbbb462292..3145931bfe 100644 --- a/src/nvim/po/uk.po +++ b/src/nvim/po/uk.po @@ -564,8 +564,8 @@ msgstr "E714: Потрібен список" msgid "E715: Dictionary required" msgstr "E715: Потрібен словник" -msgid "E114: String required" -msgstr "E114: Потрібен String" +msgid "E928: String required" +msgstr "E928: Потрібен String" #, c-format msgid "E118: Too many arguments for function: %s" diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 9955b4f775..2c6f3c922a 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -483,7 +483,7 @@ endfunction function Test_locationlist_curwin_was_closed() augroup testgroup au! - autocmd BufReadCmd t call R(expand("")) + autocmd BufReadCmd test_curwin.txt call R(expand("")) augroup END function! R(n) @@ -492,7 +492,7 @@ function Test_locationlist_curwin_was_closed() new let q = [] - call add(q, {'filename': 't' }) + call add(q, {'filename': 'test_curwin.txt' }) call setloclist(0, q) call assert_fails('lrewind', 'E924:') @@ -625,14 +625,14 @@ function XquickfixChangedByAutocmd(cchar) let Xgetexpr = a:cchar . 'getexpr' let Xrewind = a:cchar . 'rewind' if a:cchar == 'c' - let Xsetlist = 'setqflist(' + let Xsetlist = function('setqflist') let ErrorNr = 'E925' function! ReadFunc() colder cgetexpr [] endfunc else - let Xsetlist = 'setloclist(0,' + let Xsetlist = function('setloclist', [0]) let ErrorNr = 'E926' function! ReadFunc() lolder @@ -642,15 +642,15 @@ function XquickfixChangedByAutocmd(cchar) augroup testgroup au! - autocmd BufReadCmd t call ReadFunc() + autocmd BufReadCmd test_changed.txt call ReadFunc() augroup END - bwipe! + new | only let words = [ "a", "b" ] let qflist = [] for word in words - call add(qflist, {'filename': 't'}) - exec "call " . Xsetlist . "qflist, '')" + call add(qflist, {'filename': 'test_changed.txt'}) + call Xsetlist(qflist, ' ') endfor exec "call assert_fails('" . Xrewind . "', '" . ErrorNr . ":')" @@ -727,3 +727,89 @@ function Test_setqflist() call delete('Xtestfile') endfunction + +function! XquickfixSetListWithAct(cchar) + let Xolder = a:cchar . 'older' + let Xnewer = a:cchar . 'newer' + if a:cchar == 'c' + let Xsetlist = function('setqflist') + let Xgetlist = function('getqflist') + else + let Xsetlist = function('setloclist', [0]) + let Xgetlist = function('getloclist', [0]) + endif + let list1 = [{'filename': 'fnameA', 'text': 'A'}, + \ {'filename': 'fnameB', 'text': 'B'}] + let list2 = [{'filename': 'fnameC', 'text': 'C'}, + \ {'filename': 'fnameD', 'text': 'D'}, + \ {'filename': 'fnameE', 'text': 'E'}] + + " {action} is unspecified. Same as specifing ' '. + new | only + exec "silent! " . Xnewer . "99" + call Xsetlist(list1) + call Xsetlist(list2) + let li = Xgetlist() + call assert_equal(3, len(li)) + call assert_equal('C', li[0]['text']) + call assert_equal('D', li[1]['text']) + call assert_equal('E', li[2]['text']) + exec "silent! " . Xolder + let li = Xgetlist() + call assert_equal(2, len(li)) + call assert_equal('A', li[0]['text']) + call assert_equal('B', li[1]['text']) + + " {action} is specified ' '. + new | only + exec "silent! " . Xnewer . "99" + call Xsetlist(list1) + call Xsetlist(list2, ' ') + let li = Xgetlist() + call assert_equal(3, len(li)) + call assert_equal('C', li[0]['text']) + call assert_equal('D', li[1]['text']) + call assert_equal('E', li[2]['text']) + exec "silent! " . Xolder + let li = Xgetlist() + call assert_equal(2, len(li)) + call assert_equal('A', li[0]['text']) + call assert_equal('B', li[1]['text']) + + " {action} is specified 'a'. + new | only + exec "silent! " . Xnewer . "99" + call Xsetlist(list1) + call Xsetlist(list2, 'a') + let li = Xgetlist() + call assert_equal(5, len(li)) + call assert_equal('A', li[0]['text']) + call assert_equal('B', li[1]['text']) + call assert_equal('C', li[2]['text']) + call assert_equal('D', li[3]['text']) + call assert_equal('E', li[4]['text']) + + " {action} is specified 'r'. + new | only + exec "silent! " . Xnewer . "99" + call Xsetlist(list1) + call Xsetlist(list2, 'r') + let li = Xgetlist() + call assert_equal(3, len(li)) + call assert_equal('C', li[0]['text']) + call assert_equal('D', li[1]['text']) + call assert_equal('E', li[2]['text']) + + " Test for wrong value. + new | only + call assert_fails("call Xsetlist(0)", 'E714:') + call assert_fails("call Xsetlist(list1, '')", 'E927:') + call assert_fails("call Xsetlist(list1, 'aa')", 'E927:') + call assert_fails("call Xsetlist(list1, ' a')", 'E927:') + call assert_fails("call Xsetlist(list1, 0)", 'E928:') +endfunc + +function Test_quickfix_set_list_with_act() + call XquickfixSetListWithAct('c') + call XquickfixSetListWithAct('l') +endfunction diff --git a/src/nvim/version.c b/src/nvim/version.c index d10d5cf75b..a5addaf819 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -672,7 +672,7 @@ static int included_patches[] = { // 1771 NA // 1770 NA // 1769, - // 1768, + 1768, // 1767 NA // 1766 NA 1765, diff --git a/test/functional/viml/errorlist_spec.lua b/test/functional/viml/errorlist_spec.lua index 56d08771b7..f889ca9adc 100644 --- a/test/functional/viml/errorlist_spec.lua +++ b/test/functional/viml/errorlist_spec.lua @@ -18,9 +18,9 @@ describe('setqflist()', function() end) it('requires a string for {action}', function() - eq('Vim(call):E114: String required', exc_exec('call setqflist([], 5)')) - eq('Vim(call):E114: String required', exc_exec('call setqflist([], [])')) - eq('Vim(call):E114: String required', exc_exec('call setqflist([], {})')) + eq('Vim(call):E928: String required', exc_exec('call setqflist([], 5)')) + eq('Vim(call):E928: String required', exc_exec('call setqflist([], [])')) + eq('Vim(call):E928: String required', exc_exec('call setqflist([], {})')) end) it('sets w:quickfix_title', function() @@ -56,9 +56,9 @@ describe('setloclist()', function() end) it('requires a string for {action}', function() - eq('Vim(call):E114: String required', exc_exec('call setloclist(0, [], 5)')) - eq('Vim(call):E114: String required', exc_exec('call setloclist(0, [], [])')) - eq('Vim(call):E114: String required', exc_exec('call setloclist(0, [], {})')) + eq('Vim(call):E928: String required', exc_exec('call setloclist(0, [], 5)')) + eq('Vim(call):E928: String required', exc_exec('call setloclist(0, [], [])')) + eq('Vim(call):E928: String required', exc_exec('call setloclist(0, [], {})')) end) it('sets w:quickfix_title for the correct window', function() -- cgit From 39faa56bce66796f731ec339301acc3d303c08e9 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 12 Dec 2016 15:04:44 -0500 Subject: vim-patch:7.4.1802 Problem: Quickfix doesn't handle long lines well, they are split. Solution: Drop characters after a limit. (Anton Lindqvist) https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e --- src/nvim/quickfix.c | 210 ++++++++++++++++++++++++++++------ src/nvim/testdir/samples/quickfix.txt | 3 + src/nvim/testdir/test_quickfix.vim | 37 ++++++ src/nvim/version.c | 2 +- 4 files changed, 216 insertions(+), 36 deletions(-) create mode 100644 src/nvim/testdir/samples/quickfix.txt diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index b97530b700..3c59fcef03 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -168,6 +168,9 @@ qf_init ( qf_title); } +// Maximum number of bytes allowed per line while reading an errorfile. +static const size_t LINE_MAXLEN = 4096; + /* * Read the errorfile "efile" into memory, line by line, building the error * list. @@ -192,8 +195,15 @@ qf_init_ext ( { char_u *namebuf; char_u *errmsg; + size_t errmsglen; char_u *pattern; char_u *fmtstr = NULL; + char_u *growbuf = NULL; + size_t growbuflen; + size_t growbufsiz; + char_u *linebuf; + size_t linelen; + bool discard; int col = 0; bool use_viscol = false; char_u type = 0; @@ -210,7 +220,7 @@ qf_init_ext ( char_u *efm; char_u *ptr; char_u *srcptr; - int len; + size_t len; int i; int round; int idx = 0; @@ -221,6 +231,7 @@ qf_init_ext ( char_u *directory = NULL; char_u *currfile = NULL; char_u *tail = NULL; + char_u *p_buf = NULL; char_u *p_str = NULL; listitem_T *p_li = NULL; struct dir_stack_T *file_stack = NULL; @@ -243,7 +254,8 @@ qf_init_ext ( }; namebuf = xmalloc(CMDBUFFSIZE + 1); - errmsg = xmalloc(CMDBUFFSIZE + 1); + errmsglen = CMDBUFFSIZE + 1; + errmsg = xmalloc(errmsglen); pattern = xmalloc(CMDBUFFSIZE + 1); if (efile != NULL && (fd = mch_fopen((char *)efile, "r")) == NULL) { @@ -466,36 +478,66 @@ qf_init_ext ( /* Get the next line from the supplied string */ char_u *p; - if (!*p_str) /* Reached the end of the string */ + if (*p_str == NUL) // Reached the end of the string break; p = vim_strchr(p_str, '\n'); - if (p) - len = (int)(p - p_str + 1); - else - len = (int)STRLEN(p_str); - - if (len > CMDBUFFSIZE - 2) - STRLCPY(IObuff, p_str, CMDBUFFSIZE - 1); + if (p != NULL) + len = (size_t)(p - p_str) + 1; else - STRLCPY(IObuff, p_str, len + 1); + len = STRLEN(p_str); + + if (len > IOSIZE - 2) { + // If the line exceeds LINE_MAXLEN exclude the last byte since it's + // not a NL character. + linelen = len > LINE_MAXLEN ? LINE_MAXLEN - 1 : len; + if (growbuf == NULL) { + growbuf = xmalloc(linelen); + } else if (linelen > growbufsiz) { + growbuf = xrealloc(growbuf, linelen); + } + growbufsiz = linelen; + linebuf = growbuf; + } else { + linebuf = IObuff; + linelen = len; + } + STRLCPY(linebuf, p_str, linelen + 1); + // Increment using len in order to discard the rest of the line if it + // exceeds LINE_MAXLEN. p_str += len; } else if (tv->v_type == VAR_LIST) { // Get the next line from the supplied list - while (p_li && (p_li->li_tv.v_type != VAR_STRING - || p_li->li_tv.vval.v_string == NULL)) { + while (p_li != NULL + && (p_li->li_tv.v_type != VAR_STRING + || p_li->li_tv.vval.v_string == NULL)) { p_li = p_li->li_next; // Skip non-string items } - if (!p_li) /* End of the list */ + if (p_li == NULL) // End of the list break; - len = (int)STRLEN(p_li->li_tv.vval.v_string); - if (len > CMDBUFFSIZE - 2) - len = CMDBUFFSIZE - 2; + len = STRLEN(p_li->li_tv.vval.v_string); + if (len > IOSIZE - 2) { + linelen = len; + if (linelen > LINE_MAXLEN) { + linelen = LINE_MAXLEN - 1; + } + if (growbuf == NULL) { + growbuf = xmalloc(linelen); + growbufsiz = linelen; + } else if (linelen > growbufsiz) { + growbuf = xrealloc(growbuf, linelen); + growbufsiz = linelen; + } + linebuf = growbuf; + } else { + linebuf = IObuff; + linelen = len; + } - STRLCPY(IObuff, p_li->li_tv.vval.v_string, len + 1); + STRLCPY(linebuf, p_li->li_tv.vval.v_string, linelen + 1); p_li = p_li->li_next; /* next item */ } @@ -503,21 +545,103 @@ qf_init_ext ( /* Get the next line from the supplied buffer */ if (buflnum > lnumlast) break; - STRLCPY(IObuff, ml_get_buf(buf, buflnum++, FALSE), - CMDBUFFSIZE - 1); + p_buf = ml_get_buf(buf, buflnum++, false); + linelen = STRLEN(p_buf); + if (linelen > IOSIZE - 2) { + if (growbuf == NULL) { + growbuf = xmalloc(linelen); + growbufsiz = linelen; + } else if (linelen > growbufsiz) { + if (linelen > LINE_MAXLEN) { + linelen = LINE_MAXLEN - 1; + } + growbuf = xrealloc(growbuf, linelen); + growbufsiz = linelen; + } + linebuf = growbuf; + } else { + linebuf = IObuff; + } + STRLCPY(linebuf, p_buf, linelen + 1); } - } else if (fgets((char *)IObuff, CMDBUFFSIZE - 2, fd) == NULL) - break; + } else { + if (fgets((char *)IObuff, IOSIZE, fd) == NULL) { + break; + } + + discard = false; + linelen = STRLEN(IObuff); + if (linelen == IOSIZE - 1 && (IObuff[linelen - 1] != '\n' +#ifdef USE_CRNL + || IObuff[linelen - 1] != '\r' +#endif + )) { + // The current line exceeds IObuff, continue reading using growbuf + // until EOL or LINE_MAXLEN bytes is read. + if (growbuf == NULL) { + growbufsiz = 2 * (IOSIZE - 1); + growbuf = xmalloc(growbufsiz)