# HG changeset patch # User Bram Moolenaar # Date 1587501003 -7200 # Node ID 16460964c30431f1e2e6fd4e377aa5a300c1ab03 # Parent 35c4224dc232f30ce3f2412b2b1496f52ad5595b patch 8.2.0615: regexp benchmark stest is old style Commit: https://github.com/vim/vim/commit/ad48e6c1590842ab6d48e6caba3e9250734dae27 Author: Bram Moolenaar Date: Tue Apr 21 22:19:45 2020 +0200 patch 8.2.0615: regexp benchmark stest is old style Problem: Regexp benchmark stest is old style. Solution: Make it a new style test. Fix using a NULL list. Add more tests. (Yegappan Lakshmanan, closes #5963) diff --git a/src/evalbuffer.c b/src/evalbuffer.c --- a/src/evalbuffer.c +++ b/src/evalbuffer.c @@ -176,6 +176,13 @@ set_buffer_lines( if (lines->v_type == VAR_LIST) { l = lines->vval.v_list; + if (l == NULL || list_len(l) == 0) + { + // set proper return code + if (lnum > curbuf->b_ml.ml_line_count) + rettv->vval.v_number = 1; // FAIL + goto done; + } range_list_materialize(l); li = l->lv_first; } @@ -251,6 +258,7 @@ set_buffer_lines( update_topline(); } +done: if (!is_curbuf) { curbuf = curbuf_save; diff --git a/src/testdir/Make_dos.mak b/src/testdir/Make_dos.mak --- a/src/testdir/Make_dos.mak +++ b/src/testdir/Make_dos.mak @@ -107,12 +107,13 @@ nolog: -if exist test_result.log del test_result.log -if exist messages del messages -benchmark: - bench_re_freeze.out +benchmark: test_bench_regexp.res -bench_re_freeze.out: bench_re_freeze.vim +test_bench_regexp.res: test_bench_regexp.vim -if exist benchmark.out del benchmark.out - $(VIMPROG) -u dos.vim $(NO_INITS) $*.in + @echo $(VIMPROG) > vimcmd + $(VIMPROG) -u NONE $(NO_INITS) -S runtest.vim $*.vim + @del vimcmd @IF EXIST benchmark.out ( type benchmark.out ) # New style of tests uses Vim script with assert calls. These are easier diff --git a/src/testdir/Make_ming.mak b/src/testdir/Make_ming.mak --- a/src/testdir/Make_ming.mak +++ b/src/testdir/Make_ming.mak @@ -35,7 +35,7 @@ include Make_all.mak SCRIPTS = $(SCRIPTS_ALL) $(SCRIPTS_MORE1) $(SCRIPTS_MORE4) $(SCRIPTS_WIN32) -SCRIPTS_BENCH = bench_re_freeze.out +SCRIPTS_BENCH = test_bench_regexp.res # Must run test1 first to create small.vim. $(SCRIPTS) $(SCRIPTS_GUI) $(SCRIPTS_WIN32) $(NEW_TESTS_RES): $(SCRIPTS_FIRST) @@ -110,9 +110,11 @@ nolog: -@if exist test.log $(DEL) test.log -@if exist messages $(DEL) messages -bench_re_freeze.out: bench_re_freeze.vim +test_bench_regexp.res: test_bench_regexp.vim -$(DEL) benchmark.out - $(VIMPROG) -u dos.vim $(NO_INITS) $*.in + @echo $(VIMPROG) > vimcmd + $(VIMPROG) -u NONE $(NO_INITS) -S runtest.vim $*.vim + @$(DEL) vimcmd $(CAT) benchmark.out # New style of tests uses Vim script with assert calls. These are easier diff --git a/src/testdir/Makefile b/src/testdir/Makefile --- a/src/testdir/Makefile +++ b/src/testdir/Makefile @@ -38,7 +38,7 @@ test49.out: test49.vim test_options.res test_alot.res: opt_test.vim -SCRIPTS_BENCH = bench_re_freeze.out +SCRIPTS_BENCH = test_bench_regexp.res .SUFFIXES: .in .out .res .vim @@ -146,15 +146,6 @@ test1.out: test1.in fi" -rm -rf X* test.ok viminfo -bench_re_freeze.out: bench_re_freeze.vim - -rm -rf benchmark.out $(RM_ON_RUN) - # Sleep a moment to avoid that the xterm title is messed up. - # 200 msec is sufficient, but only modern sleep supports a fraction of - # a second, fall back to a second if it fails. - @-/bin/sh -c "sleep .2 > /dev/null 2>&1 || sleep 1" - $(RUN_VIM) $*.in $(REDIR_TEST_TO_NULL) - @/bin/sh -c "if test -f benchmark.out; then cat benchmark.out; fi" - nolog: -rm -f test.log messages @@ -193,3 +184,12 @@ opt_test.vim: ../optiondefs.h gen_opt_te test_xxd.res: XXD=$(XXDPROG); export XXD; $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim test_xxd.vim + +test_bench_regexp.res: test_bench_regexp.vim + -rm -rf benchmark.out $(RM_ON_RUN) + # Sleep a moment to avoid that the xterm title is messed up. + # 200 msec is sufficient, but only modern sleep supports a fraction of + # a second, fall back to a second if it fails. + @-/bin/sh -c "sleep .2 > /dev/null 2>&1 || sleep 1" + $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim $*.vim $(REDIR_TEST_TO_NULL) + @/bin/sh -c "if test -f benchmark.out; then cat benchmark.out; fi" diff --git a/src/testdir/bench_re_freeze.in b/src/testdir/bench_re_freeze.in deleted file mode 100644 --- a/src/testdir/bench_re_freeze.in +++ /dev/null @@ -1,13 +0,0 @@ -Test for Benchmarking RE engine - -STARTTEST -:so small.vim -:if !has("reltime") | qa! | endif -:set nocp cpo&vim -:so bench_re_freeze.vim -:call Measure('samples/re.freeze.txt', '\s\+\%#\@setbufline(bufnr('$') + 1, 1)) call assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1)) + call assert_equal(1, []->setbufline(bufnr('$') + 1, 1)) + call assert_equal(1, test_null_list()->setbufline(bufnr('$') + 1, 1)) + + call assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$')) + call assert_equal(0, setbufline(b, 4, ['d', 'e'])) call assert_equal(['c'], b->getbufline(3)) call assert_equal(['d'], getbufline(b, 4)) @@ -83,9 +94,29 @@ func Test_appendbufline() call setline(1, ['a', 'b', 'c']) let b = bufnr('%') wincmd w + + call assert_equal(1, appendbufline(b, -1, 'x')) call assert_equal(1, appendbufline(b, -1, ['x'])) + call assert_equal(1, appendbufline(b, -1, [])) + call assert_equal(1, appendbufline(b, -1, test_null_list())) + + call assert_equal(1, appendbufline(b, 4, 'x')) call assert_equal(1, appendbufline(b, 4, ['x'])) + call assert_equal(1, appendbufline(b, 4, [])) + call assert_equal(1, appendbufline(b, 4, test_null_list())) + + call assert_equal(1, appendbufline(1234, 1, 'x')) call assert_equal(1, appendbufline(1234, 1, ['x'])) + call assert_equal(1, appendbufline(1234, 1, [])) + call assert_equal(1, appendbufline(1234, 1, test_null_list())) + + call assert_equal(0, appendbufline(b, 1, [])) + call assert_equal(0, appendbufline(b, 1, test_null_list())) + call assert_equal(1, appendbufline(b, 3, [])) + call assert_equal(1, appendbufline(b, 3, test_null_list())) + + call assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$')) + call assert_equal(0, appendbufline(b, 3, ['d', 'e'])) call assert_equal(['c'], getbufline(b, 3)) call assert_equal(['d'], getbufline(b, 4)) diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim --- a/src/testdir/test_channel.vim +++ b/src/testdir/test_channel.vim @@ -167,6 +167,8 @@ func Ch_communicate(port) call ch_setoptions(handle, {'drop': 'never'}) call ch_setoptions(handle, {'drop': 'auto'}) call assert_fails("call ch_setoptions(handle, {'drop': 'bad'})", "E475") + call assert_equal(0, ch_setoptions(handle, test_null_dict())) + call assert_equal(0, ch_setoptions(test_null_channel(), {'drop' : 'never'})) " Send an eval request that works. call assert_equal('ok', ch_evalexpr(handle, 'eval-works')) @@ -1682,6 +1684,7 @@ func Test_job_start_fails() call assert_fails('let job = job_start("")', 'E474:') call assert_fails('let job = job_start(" ")', 'E474:') call assert_fails('let job = job_start(["ls", []])', 'E730:') + call assert_fails('call job_setoptions(test_null_job(), {})', 'E916:') %bw! endfunc @@ -2267,6 +2270,7 @@ func Test_invalid_job_chan_options() for opt in invalid_opts call assert_fails("let x = ch_status(ch, opt)", 'E475:') endfor + call assert_equal('fail', ch_status(ch, test_null_dict())) endfunc " Test for passing the command and the arguments as List on MS-Windows diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim --- a/src/testdir/test_cmdline.vim +++ b/src/testdir/test_cmdline.vim @@ -934,6 +934,9 @@ func Test_verbosefile() let log = readfile('Xlog') call assert_match("foo\nbar", join(log, "\n")) call delete('Xlog') + call mkdir('Xdir') + call assert_fails('set verbosefile=Xdir', 'E474:') + call delete('Xdir', 'd') endfunc func Test_verbose_option() diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim --- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -794,18 +794,41 @@ func Test_mode() set complete& endfunc +" Test for append() func Test_append() enew! split call append(0, ["foo"]) + call append(1, []) + call append(1, test_null_list()) + call assert_equal(['foo', ''], getline(1, '$')) split only undo + undo " Using $ instead of '$' must give an error call assert_fails("call append($, 'foobar')", 'E116:') endfunc +" Test for setline() +func Test_setline() + new + call setline(0, ["foo"]) + call setline(0, []) + call setline(0, test_null_list()) + call setline(1, ["bar"]) + call setline(1, []) + call setline(1, test_null_list()) + call setline(2, []) + call setline(2, test_null_list()) + call setline(3, []) + call setline(3, test_null_list()) + call setline(2, ["baz"]) + call assert_equal(['bar', 'baz'], getline(1, '$')) + close! +endfunc + func Test_getbufvar() let bnr = bufnr('%') let b:var_num = '1234' @@ -913,6 +936,7 @@ func Test_match_func() call assert_equal(-1, match(['a', 'b', 'c', 'a'], 'a', 5)) call assert_equal(4, match('testing', 'ing', -1)) call assert_fails("let x=match('testing', 'ing', 0, [])", 'E745:') + call assert_equal(-1, match(test_null_list(), 2)) endfunc func Test_matchend() @@ -1796,6 +1820,7 @@ func Test_call() call assert_equal(3, 'len'->call([123])) call assert_fails("call call('len', 123)", 'E714:') call assert_equal(0, call('', [])) + call assert_equal(0, call('len', test_null_list())) function Mylen() dict return len(self.data) @@ -1962,7 +1987,6 @@ func Test_range() execute "normal! a\=[complete(col('.'), range(10)), ''][1]\" " complete_info() execute "normal! a\=[complete(col('.'), range(10)), ''][1]\\=[complete_info(range(5)), ''][1]\" - call assert_fails('call complete(1, ["a"])', 'E785:') " copy() call assert_equal([1, 2, 3], copy(range(1, 3))) diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim --- a/src/testdir/test_ins_complete.vim +++ b/src/testdir/test_ins_complete.vim @@ -469,6 +469,7 @@ endfunc " Test for 'completefunc' deleting text func Test_completefunc_error() new + " delete text when called for the first time func CompleteFunc(findstart, base) if a:findstart == 1 normal dd @@ -479,9 +480,39 @@ func Test_completefunc_error() set completefunc=CompleteFunc call setline(1, ['', 'abcd', '']) call assert_fails('exe "normal 2G$a\\"', 'E840:') + + " delete text when called for the second time + func CompleteFunc2(findstart, base) + if a:findstart == 1 + return col('.') - 1 + endif + normal dd + return ['a', 'b'] + endfunc + set completefunc=CompleteFunc2 + call setline(1, ['', 'abcd', '']) + call assert_fails('exe "normal 2G$a\\"', 'E565:') + set completefunc& delfunc CompleteFunc + delfunc CompleteFunc2 close! endfunc +" Test for errors in using complete() function +func Test_complete_func_error() + call assert_fails('call complete(1, ["a"])', 'E785:') + func ListColors() + call complete(col('.'), "blue") + endfunc + call assert_fails('exe "normal i\=ListColors()\"', 'E474:') + func ListMonths() + call complete(col('.'), test_null_list()) + endfunc + call assert_fails('exe "normal i\=ListMonths()\"', 'E474:') + delfunc ListColors + delfunc ListMonths + call assert_fails('call complete_info({})', 'E714:') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim --- a/src/testdir/test_popupwin.vim +++ b/src/testdir/test_popupwin.vim @@ -853,6 +853,9 @@ func Test_popup_invalid_arguments() call popup_clear() call assert_fails('call popup_create("text", "none")', 'E715:') call popup_clear() + call assert_fails('call popup_create(test_null_string(), {})', 'E450:') + call assert_fails('call popup_create(test_null_list(), {})', 'E450:') + call popup_clear() call assert_fails('call popup_create("text", #{col: "xxx"})', 'E475:') call popup_clear() @@ -902,6 +905,8 @@ func Test_popup_invalid_arguments() call assert_fails('call popup_create("text", #{mask: test_null_list()})', 'E475:') call assert_fails('call popup_create("text", #{mapping: []})', 'E745:') call popup_clear() + call assert_fails('call popup_create("text", #{tabpage : 4})', 'E997:') + call popup_clear() endfunc func Test_win_execute_closing_curwin() @@ -1113,8 +1118,13 @@ func Test_popup_move() let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') call assert_equal('hworld', line) + call assert_fails('call popup_move(winid, [])', 'E715:') + call assert_fails('call popup_move(winid, test_null_dict())', 'E715:') + call popup_close(winid) + call assert_equal(0, popup_move(-1, {})) + bwipe! endfunc @@ -2176,7 +2186,11 @@ func Test_set_get_options() call assert_equal(1, options.drag) call assert_equal('Another', options.highlight) + call assert_fails('call popup_setoptions(winid, [])', 'E715:') + call assert_fails('call popup_setoptions(winid, test_null_dict())', 'E715:') + call popup_close(winid) + call assert_equal(0, popup_setoptions(winid, options.wrap)) endfunc func Test_popupwin_garbage_collect() diff --git a/src/testdir/test_prompt_buffer.vim b/src/testdir/test_prompt_buffer.vim --- a/src/testdir/test_prompt_buffer.vim +++ b/src/testdir/test_prompt_buffer.vim @@ -148,6 +148,7 @@ func Test_prompt_buffer_edit() call assert_beeps("normal! \") call assert_beeps("normal! \") close! + call assert_equal(0, prompt_setprompt([], '')) endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_tagjump.vim b/src/testdir/test_tagjump.vim --- a/src/testdir/test_tagjump.vim +++ b/src/testdir/test_tagjump.vim @@ -285,6 +285,7 @@ func Test_getsettagstack() call assert_fails("call settagstack(1, {'items' : 10})", 'E714') call assert_fails("call settagstack(1, {'items' : []}, 10)", 'E928') call assert_fails("call settagstack(1, {'items' : []}, 'b')", 'E962') + call assert_equal(-1, settagstack(0, test_null_dict())) set tags=Xtags call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", diff --git a/src/testdir/test_window_cmd.vim b/src/testdir/test_window_cmd.vim --- a/src/testdir/test_window_cmd.vim +++ b/src/testdir/test_window_cmd.vim @@ -1079,4 +1079,16 @@ func Test_split_cmds_with_no_room() call Run_noroom_for_newwindow_test('v') endfunc +" Test for various wincmd failures +func Test_wincmd_fails() + only! + call assert_beeps("normal \w") + call assert_beeps("normal \p") + call assert_beeps("normal \gk") + call assert_beeps("normal \r") + call assert_beeps("normal \K") + call assert_beeps("normal \H") + call assert_beeps("normal \2gt") +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -747,6 +747,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 615, +/**/ 614, /**/ 613,