]> granicus.if.org Git - vim/commitdiff
patch 8.2.0615: regexp benchmark stest is old style v8.2.0615
authorBram Moolenaar <Bram@vim.org>
Tue, 21 Apr 2020 20:19:45 +0000 (22:19 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 21 Apr 2020 20:19:45 +0000 (22:19 +0200)
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)

19 files changed:
src/evalbuffer.c
src/testdir/Make_dos.mak
src/testdir/Make_ming.mak
src/testdir/Makefile
src/testdir/bench_re_freeze.in [deleted file]
src/testdir/bench_re_freeze.vim [deleted file]
src/testdir/test_autocmd.vim
src/testdir/test_bench_regexp.vim [new file with mode: 0644]
src/testdir/test_blob.vim
src/testdir/test_bufline.vim
src/testdir/test_channel.vim
src/testdir/test_cmdline.vim
src/testdir/test_functions.vim
src/testdir/test_ins_complete.vim
src/testdir/test_popupwin.vim
src/testdir/test_prompt_buffer.vim
src/testdir/test_tagjump.vim
src/testdir/test_window_cmd.vim
src/version.c

index 2c20939bd4bf71b66f1c3eb7a9d87fa5fbd802d0..f11727c78713a013665e67cc096a7755715771f2 100644 (file)
@@ -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;
index 66839d63bf1b24282c717effdea9134a79094b3f..0e07ed5c5f1508cb44a5986d133186cbd86bd46f 100644 (file)
@@ -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
index 671caa24f323fc99ccfe2d187aa2bd572fcf4c3b..f95f70c88c426490637736f2cda348849882a260 100644 (file)
@@ -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
index b2eaecbf403d1fca404b360bbc27fca1e1aa8c2d..92506e6f416d453989531bc558569542f2e5fb37 100644 (file)
@@ -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_test.vim
 
 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 (file)
index 7b1bfa3..0000000
+++ /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\+\%#\@<!$', '+5')
-:/^" Benchmark/,$w! benchmark.out
-:qa!
-ENDTEST
-
-" Benchmark_results:
diff --git a/src/testdir/bench_re_freeze.vim b/src/testdir/bench_re_freeze.vim
deleted file mode 100644 (file)
index ee84438..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-"Test for benchmarking the RE engine
-
-so small.vim
-if !has("reltime") | finish | endif
-func! Measure(file, pattern, arg)
-       for re in range(3)
-           let sstart=reltime()
-           let cmd=printf("../vim -u NONE -N --cmd ':set re=%d'".
-               \ " -c 'call search(\"%s\", \"\", \"\", 10000)' -c ':q!' %s", re, escape(a:pattern, '\\'), empty(a:arg) ? '' : a:arg)
-           call system(cmd. ' '. a:file)
-           $put =printf('file: %s, re: %d, time: %s', a:file, re, reltimestr(reltime(sstart)))
-       endfor
-endfunc
index a8648f8c49d2f809ee71af4d16a2ee16461d89fa..b7a523e39a3933f6d70c93e3d26ed331f7b1ee1a 100644 (file)
@@ -299,6 +299,8 @@ func Test_augroup_warning()
   redir END
   call assert_true(match(res, "W19:") < 0)
   au! VimEnter
+
+  call assert_fails('augroup!', 'E471:')
 endfunc
 
 func Test_BufReadCmdHelp()
diff --git a/src/testdir/test_bench_regexp.vim b/src/testdir/test_bench_regexp.vim
new file mode 100644 (file)
index 0000000..eb9f5f8
--- /dev/null
@@ -0,0 +1,24 @@
+" Test for benchmarking the RE engine
+
+source check.vim
+CheckFeature reltime
+
+func Measure(file, pattern, arg)
+  for re in range(3)
+    let sstart = reltime()
+    let before = ['set re=' .. re]
+    let after = ['call search("' .. escape(a:pattern, '\\') .. '", "", "", 10000)']
+    let after += ['quit!']
+    let args = empty(a:arg) ? '' : a:arg .. ' ' .. a:file
+    call RunVim(before, after, args)
+    let s = 'file: ' .. a:file .. ', re: ' .. re ..
+          \ ', time: ' .. reltimestr(reltime(sstart))
+    call writefile([s], 'benchmark.out', "a")
+  endfor
+endfunc
+
+func Test_Regex_Benchmark()
+  call Measure('samples/re.freeze.txt', '\s\+\%#\@<!$', '+5')
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index e2c332a8a69566f84729c80c26adcd14d9efa558..a29e2e61d977a61118c11877258d9b5164bdad4b 100644 (file)
@@ -291,6 +291,7 @@ func Test_blob_index()
   call assert_equal(3, index(0z11110111, 0x11, -2))
   call assert_equal(0, index(0z11110111, 0x11, -10))
   call assert_fails("echo index(0z11110111, 0x11, [])", 'E745:')
+  call assert_equal(-1, index(test_null_blob(), 1))
 
   call assert_fails('call index("asdf", 0)', 'E897:')
 endfunc
index a863ba5d3a61b58589242e867e877c6b0708302a..d359f205d5d86f422819abbc8cad9702afd26313 100644 (file)
@@ -19,8 +19,19 @@ func Test_setbufline_getbufline()
   call setline(1, ['a', 'b', 'c'])
   let b = bufnr('%')
   wincmd w
+
+  call assert_equal(1, setbufline(b, 5, 'x'))
   call assert_equal(1, setbufline(b, 5, ['x']))
+  call assert_equal(1, setbufline(b, 5, []))
+  call assert_equal(1, setbufline(b, 5, test_null_list()))
+
+  call assert_equal(1, 'x'->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))
index af809eceb4c5bc0ccfdc7759302ab44e3c5d473c..cf51a536b524655f333b8f9f7982b52d390d495f 100644 (file)
@@ -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
index 8aabaa859d3e08d2dc689a30a7551b91612e7aa4..7d3c0c87d09680e0a2d3cab96a3174fac4493c4a 100644 (file)
@@ -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()
index f7a438af72af39f1fc47233bbff1267971368c97..dbd08041f3fccd2ce969f9e0b6cdb4539424e406 100644 (file)
@@ -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\<C-r>=[complete(col('.'), range(10)), ''][1]\<CR>"
   " complete_info()
   execute "normal! a\<C-r>=[complete(col('.'), range(10)), ''][1]\<CR>\<C-r>=[complete_info(range(5)), ''][1]\<CR>"
-  call assert_fails('call complete(1, ["a"])', 'E785:')
 
   " copy()
   call assert_equal([1, 2, 3], copy(range(1, 3)))
index a1c7b98f185ccb27188f0896c351f43c844c4de6..7ae263909cf77366a3f280a88f52bf55168b7ee3 100644 (file)
@@ -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\<C-X>\<C-U>"', '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\<C-X>\<C-U>"', '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\<C-R>=ListColors()\<CR>"', 'E474:')
+  func ListMonths()
+    call complete(col('.'), test_null_list())
+  endfunc
+  call assert_fails('exe "normal i\<C-R>=ListMonths()\<CR>"', 'E474:')
+  delfunc ListColors
+  delfunc ListMonths
+  call assert_fails('call complete_info({})', 'E714:')
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 03285f935c5063a3d7d404cfc6466999de049dbb..99b4458250d1fea69a01ca9ca6c223ef9e029c20 100644 (file)
@@ -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()
index 39cce247de1e5639e36d3786fcd2069f3e944fd9..760e1d9798cdb7d1aa79719bb3cab6c3f7553f33 100644 (file)
@@ -148,6 +148,7 @@ func Test_prompt_buffer_edit()
   call assert_beeps("normal! \<C-A>")
   call assert_beeps("normal! \<C-X>")
   close!
+  call assert_equal(0, prompt_setprompt([], ''))
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index 99526005e652fd4c2fed1a8aa0a72e85877cf7b3..fa825c7dc0302e536483b97477d416bddb13095c 100644 (file)
@@ -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//",
index a28c00a4bd86967f3fe82d559b72e7fcbd69af62..49278424545427c547ffbfe5c4921f6d453cbba8 100644 (file)
@@ -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 \<C-W>w")
+  call assert_beeps("normal \<C-W>p")
+  call assert_beeps("normal \<C-W>gk")
+  call assert_beeps("normal \<C-W>r")
+  call assert_beeps("normal \<C-W>K")
+  call assert_beeps("normal \<C-W>H")
+  call assert_beeps("normal \<C-W>2gt")
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index cb846f08d6ef2daf0cdff3b16e097678c5567d3e..4662de61063f8ea2a947a60cef9b0f9a4d150052 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    615,
 /**/
     614,
 /**/