From 31e2546cc908aa17aa68f7812eec5d4f08fbbc55 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 26 Mar 2021 18:55:10 -0400 Subject: vim-patch:8.2.2659: eval test fails because for loop on string works Problem: Eval test fails because for loop on string works. Solution: Check looping over function reference fails. https://github.com/vim/vim/commit/c61cb8bfe1ec2cc50e6edd195cae2a3cd93d6590 --- src/nvim/testdir/test_eval_stuff.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/testdir/test_eval_stuff.vim b/src/nvim/testdir/test_eval_stuff.vim index ff50d53d86..73b57f302e 100644 --- a/src/nvim/testdir/test_eval_stuff.vim +++ b/src/nvim/testdir/test_eval_stuff.vim @@ -24,7 +24,7 @@ endfunc func Test_for_invalid() call assert_fails("for x in 99", 'E714:') - call assert_fails("for x in 'asdf'", 'E714:') + call assert_fails("for x in function('winnr')", 'E714:') call assert_fails("for x in {'a': 9}", 'E714:') if 0 -- cgit From 618b17f5754e4b15657ef65326f2fba3f9bc73c2 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 26 Mar 2021 19:42:00 -0400 Subject: vim-patch:8.2.2045: highlighting a character too much with incsearch Problem: Highlighting a character too much with incsearch. Solution: Check "search_match_endcol". (Christian Brabandt, closes vim/vim#7360) https://github.com/vim/vim/commit/448465e6872905967c97a56cd45307530795653c --- src/nvim/screen.c | 2 +- src/nvim/testdir/test_search.vim | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 095c020fe4..749627de80 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -2322,7 +2322,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); } // do at least one character; happens when past end of line - if (fromcol == tocol) { + if (fromcol == tocol && search_match_endcol) { tocol = fromcol + 1; } area_highlighting = true; diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 0703a6b141..feca93fef2 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -2,6 +2,7 @@ source shared.vim source screendump.vim +source check.vim func Test_search_cmdline() " See test/functional/legacy/search_spec.lua @@ -1192,4 +1193,40 @@ func Test_search_smartcase_utf8() close! endfunc +func Test_zzzz_incsearch_highlighting_newline() + CheckRunVimInTerminal + CheckOption incsearch + CheckScreendump + new + call test_override("char_avail", 1) + + let commands =<< trim [CODE] + set incsearch nohls + call setline(1, ['test', 'xxx']) + [CODE] + call writefile(commands, 'Xincsearch_nl') + let buf = RunVimInTerminal('-S Xincsearch_nl', {'rows': 5, 'cols': 10}) + " Need to send one key at a time to force a redraw + call term_sendkeys(buf, '/test') + sleep 100m + call VerifyScreenDump(buf, 'Test_incsearch_newline1', {}) + call term_sendkeys(buf, '\n') + sleep 100m + call VerifyScreenDump(buf, 'Test_incsearch_newline2', {}) + call term_sendkeys(buf, 'x') + sleep 100m + call VerifyScreenDump(buf, 'Test_incsearch_newline3', {}) + call term_sendkeys(buf, 'x') + call VerifyScreenDump(buf, 'Test_incsearch_newline4', {}) + call term_sendkeys(buf, "\") + sleep 100m + call VerifyScreenDump(buf, 'Test_incsearch_newline5', {}) + call StopVimInTerminal(buf) + + " clean up + call delete('Xincsearch_nl') + call test_override("char_avail", 0) + bw +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From ecd27296586bdde53ffb37654130ee4d7924498b Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 26 Mar 2021 23:06:39 -0400 Subject: test/old: use CheckFunction, enable more tests Some skipped tests have custom error messages. Use ":CheckFunction" command for standard error message on missing function. --- src/nvim/testdir/test_autocmd.vim | 14 +++++++------- src/nvim/testdir/test_messages.vim | 3 ++- src/nvim/testdir/test_popup.vim | 2 +- src/nvim/testdir/test_quickfix.vim | 2 +- src/nvim/testdir/test_search.vim | 36 ++++++++++++++++-------------------- src/nvim/testdir/test_signs.vim | 7 +++---- src/nvim/testdir/test_system.vim | 4 ++-- src/nvim/testdir/test_timers.vim | 4 ++-- src/nvim/testdir/test_undo.vim | 6 ++++-- 9 files changed, 38 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 3401e791c9..5e99edf233 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -76,7 +76,7 @@ if has('timers') endfunc func Test_OptionSet_modeline() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override call test_override('starting', 1) au! OptionSet augroup set_tabstop @@ -507,7 +507,7 @@ func s:AutoCommandOptionSet(match) endfunc func Test_OptionSet() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override if !has("eval") || !exists("+autochdir") return endif @@ -648,7 +648,7 @@ func Test_OptionSet() endfunc func Test_OptionSet_diffmode() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override call test_override('starting', 1) " 18: Changing an option when entering diff mode new @@ -682,7 +682,7 @@ func Test_OptionSet_diffmode() endfunc func Test_OptionSet_diffmode_close() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override call test_override('starting', 1) " 19: Try to close the current window when entering diff mode " should not segfault @@ -1285,9 +1285,9 @@ func Test_autocommand_all_events() endfunc " Test TextChangedI and TextChangedP +" See test/functional/viml/completion_spec.lua' func Test_ChangedP() - " Nvim does not support test_override(). - throw 'skipped: see test/functional/viml/completion_spec.lua' + CheckFunction test_override new call setline(1, ['foo', 'bar', 'foobar']) call test_override("char_avail", 1) @@ -1350,7 +1350,7 @@ func SetLineOne() endfunc func Test_TextChangedI_with_setline() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override new call test_override('char_avail', 1) autocmd TextChangedI call SetLineOne() diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index 3ebd048f46..08586dffe1 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -1,5 +1,6 @@ " Tests for :messages, :echomsg, :echoerr +source check.vim source shared.vim func Test_messages() @@ -77,7 +78,7 @@ func Test_echomsg() endfunc func Test_echoerr() - throw 'skipped: Nvim does not support test_ignore_error()' + CheckFunction test_ignore_error call test_ignore_error('IgNoRe') call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"')) call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"')) diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index 4ee16558a0..9443958984 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -871,7 +871,7 @@ func Test_popup_complete_backwards_ctrl_p() endfunc fun! Test_complete_o_tab() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override let s:o_char_pressed = 0 fun! s:act_on_text_changed() diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 704fdacdcd..da949f5940 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -2660,7 +2660,7 @@ endfunc " Test for incsearch highlighting of the :vimgrep pattern " This test used to cause "E315: ml_get: invalid lnum" errors. func Test_vimgrep_incsearch() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override enew set incsearch call test_override("char_avail", 1) diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index feca93fef2..d4d529e4b9 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -4,9 +4,9 @@ source shared.vim source screendump.vim source check.vim +" See test/functional/legacy/search_spec.lua func Test_search_cmdline() - " See test/functional/legacy/search_spec.lua - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override if !exists('+incsearch') return endif @@ -203,9 +203,9 @@ func Test_search_cmdline() bw! endfunc +" See test/functional/legacy/search_spec.lua func Test_search_cmdline2() - " See test/functional/legacy/search_spec.lua - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override if !exists('+incsearch') return endif @@ -352,7 +352,7 @@ func Test_searchc() endfunc func Cmdline3_prep() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override " need to disable char_avail, " so that expansion of commandline works call test_override("char_avail", 1) @@ -362,14 +362,13 @@ func Cmdline3_prep() endfunc func Incsearch_cleanup() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override set noincsearch call test_override("char_avail", 0) bw! endfunc func Test_search_cmdline3() - throw 'skipped: Nvim does not support test_override()' if !exists('+incsearch') return endif @@ -383,7 +382,6 @@ func Test_search_cmdline3() endfunc func Test_search_cmdline3s() - throw 'skipped: Nvim does not support test_override()' if !exists('+incsearch') return endif @@ -410,7 +408,6 @@ func Test_search_cmdline3s() endfunc func Test_search_cmdline3g() - throw 'skipped: Nvim does not support test_override()' if !exists('+incsearch') return endif @@ -434,7 +431,6 @@ func Test_search_cmdline3g() endfunc func Test_search_cmdline3v() - throw 'skipped: Nvim does not support test_override()' if !exists('+incsearch') return endif @@ -451,9 +447,9 @@ func Test_search_cmdline3v() call Incsearch_cleanup() endfunc +" See test/functional/legacy/search_spec.lua func Test_search_cmdline4() - " See test/functional/legacy/search_spec.lua - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override if !exists('+incsearch') return endif @@ -508,7 +504,7 @@ func Test_search_cmdline5() endfunc func Test_search_cmdline7() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override " Test that pressing in an empty command line " does not move the cursor if !exists('+incsearch') @@ -799,7 +795,7 @@ func Test_incsearch_vimgrep_dump() endfunc func Test_keep_last_search_pattern() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override if !exists('+incsearch') return endif @@ -821,7 +817,7 @@ func Test_keep_last_search_pattern() endfunc func Test_word_under_cursor_after_match() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override if !exists('+incsearch') return endif @@ -841,7 +837,7 @@ func Test_word_under_cursor_after_match() endfunc func Test_subst_word_under_cursor() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override if !exists('+incsearch') return endif @@ -883,7 +879,7 @@ func Test_incsearch_with_change() endfunc func Test_incsearch_cmdline_modifier() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override if !exists('+incsearch') return endif @@ -961,7 +957,7 @@ func Test_incsearch_search_dump() endfunc func Test_incsearch_substitute() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override if !exists('+incsearch') return endif @@ -983,7 +979,7 @@ func Test_incsearch_substitute() endfunc func Test_incsearch_substitute_long_line() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override new call test_override("char_avail", 1) set incsearch @@ -1105,7 +1101,7 @@ func Test_one_error_msg() endfunc func Test_incsearch_add_char_under_cursor() - throw 'skipped: Nvim does not support test_override()' + CheckFunction test_override if !exists('+incsearch') return endif diff --git a/src/nvim/testdir/test_signs.vim b/src/nvim/testdir/test_signs.vim index 4bbd722fdb..9c3a5636ce 100644 --- a/src/nvim/testdir/test_signs.vim +++ b/src/nvim/testdir/test_signs.vim @@ -1,8 +1,7 @@ " Test for signs -if !has('signs') - finish -endif +source check.vim +CheckFeature signs source screendump.vim @@ -1541,7 +1540,7 @@ endfunc " Tests for memory allocation failures in sign functions func Test_sign_memfailures() - throw 'skipped: Nvim does not support test_alloc_fail()' + CheckFunction test_alloc_fail call writefile(repeat(["Sun is shining"], 30), "Xsign") edit Xsign diff --git a/src/nvim/testdir/test_system.vim b/src/nvim/testdir/test_system.vim index 9cf8690d57..6bbe714d19 100644 --- a/src/nvim/testdir/test_system.vim +++ b/src/nvim/testdir/test_system.vim @@ -93,7 +93,6 @@ function! Test_system_exmode() endfunc func Test_system_with_shell_quote() - throw 'skipped: enable after porting method patches' CheckMSWindows call mkdir('Xdir with spaces', 'p') @@ -122,7 +121,8 @@ func Test_system_with_shell_quote() let msg = printf('shell=%s shellxquote=%s', &shell, &shellxquote) try - let out = 'echo 123'->system() + " let out = 'echo 123'->system() + let out = system('echo 123') catch call assert_report(printf('%s: %s', msg, v:exception)) continue diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 13971a918d..ceaa5de92b 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -317,8 +317,8 @@ endfunc " Test that the garbage collector isn't triggered if a timer callback invokes " vgetc(). func Test_nocatch_garbage_collect() - " skipped: Nvim does not support test_garbagecollect_soon(), test_override() - return + CheckFunction test_garbagecollect_soon + CheckFunction test_override " 'uptimetime. must be bigger than the timer timeout set ut=200 call test_garbagecollect_soon() diff --git a/src/nvim/testdir/test_undo.vim b/src/nvim/testdir/test_undo.vim index 3b66071d6d..54caed3983 100644 --- a/src/nvim/testdir/test_undo.vim +++ b/src/nvim/testdir/test_undo.vim @@ -3,6 +3,8 @@ " undo-able pieces. Do that by setting 'undolevels'. " Also tests :earlier and :later. +source check.vim + func Test_undotree() new @@ -135,7 +137,7 @@ func BackOne(expected) endfunc func Test_undo_del_chars() - throw 'skipped: Nvim does not support test_settime()' + CheckFunction test_settime " Setup a buffer without creating undo entries new @@ -330,7 +332,7 @@ func Test_insert_expr() endfunc func Test_undofile_earlier() - throw 'skipped: Nvim does not support test_settime()' + CheckFunction test_settime let t0 = localtime() - 43200 call test_settime(t0) -- cgit From 4bd919dc51573aa3b4cab5095aa5605bad48f99d Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 27 Mar 2021 00:31:59 -0400 Subject: test/old: do not special-case test_autochdir Use "CheckFunction" for standard error message for missing "test_autochdir()". Sync test_autochdir.vim to the latest Vim commit because porting Vim patches for this file modify other files and are too tedious to port. --- src/nvim/testdir/Makefile | 2 -- src/nvim/testdir/test_autochdir.vim | 8 +++++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index e52fd888bd..518a6d3951 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -36,13 +36,11 @@ NEW_TESTS_IN_ALOT := $(shell sed -n '/^source/ s/^source //; s/\.vim$$//p' $(add NEW_TESTS_IN_ALOT_LATIN := $(shell sed -n '/^source/ s/^source //; s/\.vim$$//p' test_alot_latin.vim) # Ignored tests. # test_alot_latin: Nvim does not allow setting encoding. -# test_autochdir: ported to Lua, but kept for easier merging. # test_eval_func: used as include in old-style test (test_eval.in). # test_listlbr: Nvim does not allow setting encoding. # test_largefile: uses too much resources to run on CI. NEW_TESTS_IGNORE := \ test_alot_latin $(NEW_TESTS_IN_ALOT_LATIN) \ - test_autochdir \ test_eval_func \ test_listlbr \ test_largefile \ diff --git a/src/nvim/testdir/test_autochdir.vim b/src/nvim/testdir/test_autochdir.vim index 67c537b407..d071f4b325 100644 --- a/src/nvim/testdir/test_autochdir.vim +++ b/src/nvim/testdir/test_autochdir.vim @@ -1,10 +1,10 @@ " Test 'autochdir' behavior -if !exists("+autochdir") - throw 'Skipped: autochdir feature missing' -endif +source check.vim +CheckOption autochdir func Test_set_filename() + CheckFunction test_autochdir let cwd = getcwd() call test_autochdir() set acd @@ -17,3 +17,5 @@ func Test_set_filename() exe 'cd ' . cwd call delete('samples/Xtest') endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From 1c49695d122370f15d361667cb6b1793639cb980 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 27 Mar 2021 01:04:10 -0400 Subject: test/old: test_eval_func was removed --- src/nvim/testdir/Makefile | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 518a6d3951..da6e99ab8a 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -36,12 +36,10 @@ NEW_TESTS_IN_ALOT := $(shell sed -n '/^source/ s/^source //; s/\.vim$$//p' $(add NEW_TESTS_IN_ALOT_LATIN := $(shell sed -n '/^source/ s/^source //; s/\.vim$$//p' test_alot_latin.vim) # Ignored tests. # test_alot_latin: Nvim does not allow setting encoding. -# test_eval_func: used as include in old-style test (test_eval.in). # test_listlbr: Nvim does not allow setting encoding. # test_largefile: uses too much resources to run on CI. NEW_TESTS_IGNORE := \ test_alot_latin $(NEW_TESTS_IN_ALOT_LATIN) \ - test_eval_func \ test_listlbr \ test_largefile \ -- cgit From ff870232b868d7c6b1ae094f2c60c624321a53b9 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 27 Mar 2021 01:27:53 -0400 Subject: test/old: run some tests from test_listlbr.vim These tests pass without 'set encoding=latin1'. --- src/nvim/testdir/Makefile | 2 -- src/nvim/testdir/test_listlbr.vim | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index da6e99ab8a..b760828458 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -36,11 +36,9 @@ NEW_TESTS_IN_ALOT := $(shell sed -n '/^source/ s/^source //; s/\.vim$$//p' $(add NEW_TESTS_IN_ALOT_LATIN := $(shell sed -n '/^source/ s/^source //; s/\.vim$$//p' test_alot_latin.vim) # Ignored tests. # test_alot_latin: Nvim does not allow setting encoding. -# test_listlbr: Nvim does not allow setting encoding. # test_largefile: uses too much resources to run on CI. NEW_TESTS_IGNORE := \ test_alot_latin $(NEW_TESTS_IN_ALOT_LATIN) \ - test_listlbr \ test_largefile \ NEW_TESTS := $(sort $(basename $(notdir $(wildcard test_*.vim)))) diff --git a/src/nvim/testdir/test_listlbr.vim b/src/nvim/testdir/test_listlbr.vim index d619ac0eb5..e0518de3c2 100644 --- a/src/nvim/testdir/test_listlbr.vim +++ b/src/nvim/testdir/test_listlbr.vim @@ -1,9 +1,5 @@ " Test for linebreak and list option (non-utf8) -" Nvim does not allow setting 'encoding', so skip this test. -finish - -set encoding=latin1 scriptencoding latin1 if !exists("+linebreak") || !has("conceal") @@ -46,6 +42,7 @@ func Test_set_linebreak() endfunc func Test_linebreak_with_list() + throw 'skipped: Nvim does not support enc=latin1' call s:test_windows('setl ts=4 sbr=+ list listchars=') call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ") let lines = s:screen_lines([1, 4], winwidth(0)) @@ -217,6 +214,7 @@ func Test_norm_after_block_visual() endfunc func Test_block_replace_after_wrapping() + throw 'skipped: Nvim does not support enc=latin1' call s:test_windows() call setline(1, repeat("a", 150)) exe "norm! 0yypk147|\jr0" -- cgit From 6da06bc2492e6dd142b1805664082317bc04974e Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 27 Mar 2021 08:21:24 -0400 Subject: vim-patch:8.2.2662: there is no way to avoid some escape sequences Problem: There is no way to avoid some escape sequences. Solution: Suppress escape sequences when the --not-a-term argument is used. (Gary Johnson) https://github.com/vim/vim/commit/7007e31bde75b6360a1b54c7572e4f855458f37d "Test_not_a_term" passes because Neovim does not support "--not-a-term" flag. --- src/nvim/testdir/test_startup.vim | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index 4d1ad10c23..eb9378194f 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -862,6 +862,34 @@ func Test_x_arg() call delete('Xtest_x_arg') endfunc +" Test for --not-a-term avoiding escape codes. +func Test_not_a_term() + CheckUnix + CheckNotGui + + if &shellredir =~ '%s' + let redir = printf(&shellredir, 'Xvimout') + else + let redir = &shellredir .. ' Xvimout' + endif + + " Without --not-a-term there are a few escape sequences. + " This will take 2 seconds because of the missing --not-a-term + let cmd = GetVimProg() .. ' --cmd quit ' .. redir + exe "silent !" . cmd + " call assert_match("\", readfile('Xvimout')->join()) + call assert_match("\", join(readfile('Xvimout'))) + call delete('Xvimout') + + " With --not-a-term there are no escape sequences. + let cmd = GetVimProg() .. ' --not-a-term --cmd quit ' .. redir + exe "silent !" . cmd + " call assert_notmatch("\", readfile('Xvimout')->join()) + call assert_notmatch("\", join(readfile('Xvimout'))) + call delete('Xvimout') +endfunc + + " Test starting vim with various names: vim, ex, view, evim, etc. func Test_progname() CheckUnix -- cgit From 9118bf191e1657732bdd5cb5fb1f98dc17cf7f41 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 27 Mar 2021 08:45:28 -0400 Subject: vim-patch:8.2.1666: the initial value of 'backupskip' can have duplicate items Problem: The initial value of 'backupskip' can have duplicate items. Solution: Remove duplicates, like when it is set later. (Tom Ryder, closes vim/vim#6940) https://github.com/vim/vim/commit/b00ef0508b22905379953a164bdb4300015d3705 --- src/nvim/option.c | 94 ++++++++++++++++++++++++--------------- src/nvim/testdir/test_options.vim | 30 +++++++++++++ 2 files changed, 89 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/nvim/option.c b/src/nvim/option.c index d04329e104..949558894f 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -379,8 +379,8 @@ void set_init_1(bool clean_arg) # else static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"}; # endif - int len; garray_T ga; + opt_idx = findoption("backupskip"); ga_init(&ga, 1, 100); for (size_t n = 0; n < ARRAY_SIZE(names); n++) { @@ -401,15 +401,23 @@ void set_init_1(bool clean_arg) } if (p != NULL && *p != NUL) { // First time count the NUL, otherwise count the ','. - len = (int)strlen(p) + 3; - ga_grow(&ga, len); - if (!GA_EMPTY(&ga)) { - STRCAT(ga.ga_data, ","); + const size_t len = strlen(p) + 3; + char *item = xmalloc(len); + xstrlcpy(item, p, len); + add_pathsep(item); + xstrlcat(item, "*", len); + if (find_dup_item(ga.ga_data, (char_u *)item, options[opt_idx].flags) + == NULL) { + ga_grow(&ga, (int)len); + if (!GA_EMPTY(&ga)) { + STRCAT(ga.ga_data, ","); + } + STRCAT(ga.ga_data, p); + add_pathsep(ga.ga_data); + STRCAT(ga.ga_data, "*"); + ga.ga_len += (int)len; } - STRCAT(ga.ga_data, p); - add_pathsep(ga.ga_data); - STRCAT(ga.ga_data, "*"); - ga.ga_len += len; + xfree(item); } if(mustfree) { xfree(p); @@ -713,6 +721,38 @@ static void set_string_default(const char *name, char *val, bool allocated) } } +// For an option value that contains comma separated items, find "newval" in +// "origval". Return NULL if not found. +static char_u *find_dup_item(char_u *origval, const char_u *newval, + uint32_t flags) + FUNC_ATTR_NONNULL_ARG(2) +{ + int bs = 0; + + if (origval == NULL) { + return NULL; + } + + const size_t newlen = STRLEN(newval); + for (char_u *s = origval; *s != NUL; s++) { + if ((!(flags & P_COMMA) || s == origval || (s[-1] == ',' && !(bs & 1))) + && STRNCMP(s, newval, newlen) == 0 + && (!(flags & P_COMMA) || s[newlen] == ',' || s[newlen] == NUL)) { + return s; + } + // Count backslashes. Only a comma with an even number of backslashes + // or a single backslash preceded by a comma before it is recognized as + // a separator. + if ((s > origval + 1 && s[-1] == '\\' && s[-2] != ',') + || (s == origval + 1 && s[-1] == '\\')) { + bs++; + } else { + bs = 0; + } + } + return NULL; +} + /// Set the Vi-default value of a number option. /// Used for 'lines' and 'columns'. void set_number_default(char *name, long val) @@ -1285,9 +1325,7 @@ int do_set( char *saved_newval = NULL; unsigned newlen; int comma; - int bs; - int new_value_alloced; /* new string option - was allocated */ + bool new_value_alloced = false; // new string option was allocated /* When using ":set opt=val" for a global option * with a local value the local value will be @@ -1486,34 +1524,20 @@ int do_set( i = 0; // init for GCC if (removing || (flags & P_NODUP)) { i = (int)STRLEN(newval); - bs = 0; - for (s = origval; *s; s++) { - if ((!(flags & P_COMMA) - || s == origval - || (s[-1] == ',' && !(bs & 1))) - && STRNCMP(s, newval, i) == 0 - && (!(flags & P_COMMA) - || s[i] == ',' - || s[i] == NUL)) { - break; - } - // Count backslashes. Only a comma with an even number of - // backslashes or a single backslash preceded by a comma - // before it is recognized as a separator - if ((s > origval + 1 && s[-1] == '\\' && s[-2] != ',') - || (s == origval + 1 && s[-1] == '\\')) { - bs++; - } else { - bs = 0; - } - } + s = find_dup_item(origval, newval, flags); // do not add if already there - if ((adding || prepending) && *s) { + if ((adding || prepending) && s != NULL) { prepending = false; adding = false; STRCPY(newval, origval); } + + // if no duplicate, move pointer to end of + // original value + if (s == NULL) { + s = origval + (int)STRLEN(origval); + } } /* concatenate the two strings; add a ',' if @@ -2310,7 +2334,7 @@ static char_u * did_set_string_option( int opt_idx, // index in options[] table char_u **varp, // pointer to the option variable - int new_value_alloced, // new value was allocated + bool new_value_alloced, // new value was allocated char_u *oldval, // previous value of the option char_u *errbuf, // buffer for errors, or NULL size_t errbuflen, // length of errors buffer diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index 07e2481f95..5aef33cb09 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -448,6 +448,36 @@ func Test_backupskip() endif endfor + " Duplicates from environment variables should be filtered out (option has + " P_NODUP). Run this in a separate instance and write v:errors in a file, + " so that we see what happens on startup. + let after =<< trim [CODE] + let bsklist = split(&backupskip, ',') + call assert_equal(uniq(copy(bsklist)), bsklist) + call writefile(['errors:'] + v:errors, 'Xtestout') + qall + [CODE] + call writefile(after, 'Xafter') + " let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' + let cmd = GetVimProg() . ' -S Xafter --cmd "set enc=utf8"' + + let saveenv = {} + for var in ['TMPDIR', 'TMP', 'TEMP'] + let saveenv[var] = getenv(var) + call setenv(var, '/duplicate/path') + endfor + + exe 'silent !' . cmd + call assert_equal(['errors:'], readfile('Xtestout')) + + " restore environment variables + for var in ['TMPDIR', 'TMP', 'TEMP'] + call setenv(var, saveenv[var]) + endfor + + call delete('Xtestout') + call delete('Xafter') + " Duplicates should be filtered out (option has P_NODUP) let backupskip = &backupskip set backupskip= -- cgit