]> granicus.if.org Git - vim/commitdiff
patch 7.4.2113 v7.4.2113
authorBram Moolenaar <Bram@vim.org>
Fri, 29 Jul 2016 14:15:27 +0000 (16:15 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 29 Jul 2016 14:15:27 +0000 (16:15 +0200)
Problem:    Test for undo is flaky.
Solution:   Turn it into a new style test.  Use test_settime() to avoid
            flakyness.

src/Makefile
src/testdir/Make_all.mak
src/testdir/test61.in [deleted file]
src/testdir/test61.ok [deleted file]
src/testdir/test_alot.vim
src/testdir/test_undo.vim [new file with mode: 0644]
src/testdir/test_undolevels.vim [deleted file]
src/undo.c
src/version.c

index ea28eb715d19cd19a9e704ff98ef7d70ecece1a5..6aa1308015bf53f974f3e9bc455f4477b1963485 100644 (file)
@@ -2044,7 +2044,7 @@ test1 \
        test30 test31 test32 test33 test34 test36 test37 test38 test39 \
        test40 test41 test42 test43 test44 test45 test46 test47 test48 test49 \
        test50 test51 test52 test53 test54 test55 test56 test57 test58 test59 \
-       test60 test61 test62 test63 test64 test65 test66 test67 test68 test69 \
+       test60 test62 test63 test64 test65 test66 test67 test68 test69 \
        test70 test71 test72 test73 test74 test75 test76 test77 test78 test79 \
        test80 test81 test82 test83 test84 test85 test86 test87 test88 test89 \
        test90 test91 test92 test93 test94 test95 test97 test98 test99 \
@@ -2119,9 +2119,9 @@ test_arglist \
        test_textobjects \
        test_timers \
        test_true_false \
-       test_undolevels \
-       test_usercommands \
+       test_undo \
        test_unlet \
+       test_usercommands \
        test_viminfo \
        test_viml \
        test_visual \
index 193679810f6a91a53573d48ff03a9450b91759bf..78f0b0b5039bcba54dd7406d9a14fd18a4063a8f 100644 (file)
@@ -51,7 +51,6 @@ SCRIPTS_ALL = \
        test56.out \
        test57.out \
        test60.out \
-       test61.out \
        test62.out \
        test63.out \
        test64.out \
@@ -188,6 +187,7 @@ NEW_TESTS = test_arglist.res \
            test_stat.res \
            test_syntax.res \
            test_textobjects.res \
+           test_undo.res \
            test_usercommands.res \
            test_viminfo.res \
            test_viml.res \
diff --git a/src/testdir/test61.in b/src/testdir/test61.in
deleted file mode 100644 (file)
index b18bbb5..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-Tests for undo tree.
-Since this script is sourced we need to explicitly break changes up in
-undo-able pieces.  Do that by setting 'undolevels'.
-Also tests :earlier and :later.
-
-STARTTEST
-:echo undotree().entries
-ENDTEST
-
-STARTTEST
-:" Delete three characters and undo
-Gx:set ul=100
-x:set ul=100
-x:.w! test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-:"
-:/^111/w >>test.out
-:" Delete three other characters and go back in time step by step
-$x:set ul=100
-x:set ul=100
-x:.w >>test.out
-:sleep 1
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-10g+:.w >>test.out
-:"
-:/^222/w >>test.out
-:" Delay for three seconds and go some seconds forward and backward
-:sleep 2
-Aa\e:set ul=100
-Ab\e:set ul=100
-Ac\e:set ul=100
-:.w >>test.out
-:ear 1s
-:.w >>test.out
-:ear 3s
-:.w >>test.out
-:later 1s
-:.w >>test.out
-:later 1h
-:.w >>test.out
-:"
-:" test undojoin
-Goaaaa\e:set ul=100
-obbbb\eu:.w >>test.out
-obbbb\e:set ul=100
-:undojoin
-occcc\eu:.w >>test.out
-:e! Xtest
-ione one one\e:set ul=100
-:w!
-otwo\e:set ul=100
-otwo\e:set ul=100
-:w
-othree\e:earlier 1f
-:" expect "one one one\ntwo\ntwo"
-:%yank a
-:earlier 1f
-:" expect "one one one"
-:%yank b
-:earlier 1f
-:" expect empty line
-:%yank c
-:later 1f
-:" expect "one one one"
-:%yank d
-:later 1f
-:" expect "one one one\ntwo\ntwo"
-:%yank e
-:later 1f
-:" expect "one one one\ntwo\ntwo\nthree"
-ggO---\e:0put e
-ggO---\e:0put d
-ggO---\e:0put c
-ggO---\e:0put b
-ggO---\e:0put a
-ggO---\e:w >>test.out
-:so small.vim
-:set nocp viminfo+=nviminfo
-:enew!
-oa\e:
-:set ul=100
-ob\e:
-:set ul=100
-o1\ea2\12=setline('.','1234')
-
-\euu:"
-oc\e:
-:set ul=100
-o1\ea2\12=setline('.','1234')
-
-\eu:"
-od\e:
-:set ul=100
-o1\ea2\12=string(123)
-\eu:"
-:%w >>test.out
-:qa!
-ENDTEST
-
-1111 -----
-2222 -----
-
-123456789
diff --git a/src/testdir/test61.ok b/src/testdir/test61.ok
deleted file mode 100644 (file)
index ea4b473..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-456789
-3456789
-23456789
-123456789
-123456789
-1111 -----
-123456
-1234567
-12345678
-456789
-3456789
-23456789
-123456789
-123456789
-123456789
-123456
-2222 -----
-123456abc
-123456
-123456789
-123456
-123456abc
-aaaa
-aaaa
----
-one one one
-two
-two
----
-one one one
----
-
----
-one one one
----
-one one one
-two
-two
----
-one one one
-two
-two
-three
-
-a
-b
-c
-12
-d
index e9c84398e89ed3e125834287e91e0acaa066a204..c7d651bd96379bad8930c0ea9b2cee6d56718526 100644 (file)
@@ -36,6 +36,5 @@ source test_tabline.vim
 source test_tagjump.vim
 source test_timers.vim
 source test_true_false.vim
-source test_undolevels.vim
 source test_unlet.vim
 source test_window_cmd.vim
diff --git a/src/testdir/test_undo.vim b/src/testdir/test_undo.vim
new file mode 100644 (file)
index 0000000..e521e35
--- /dev/null
@@ -0,0 +1,204 @@
+" Tests for the undo tree.
+" Since this script is sourced we need to explicitly break changes up in
+" undo-able pieces.  Do that by setting 'undolevels'.
+" Also tests :earlier and :later.
+
+func Test_undotree()
+  exe "normal Aabc\<Esc>"
+  set ul=100
+  exe "normal Adef\<Esc>"
+  set ul=100
+  undo
+  let d = undotree()
+  call assert_true(d.seq_last > 0)
+  call assert_true(d.seq_cur > 0)
+  call assert_true(d.seq_cur < d.seq_last)
+  call assert_true(len(d.entries) > 0)
+  " TODO: check more members of d
+
+  w! Xtest
+  call assert_equal(d.save_last + 1, undotree().save_last)
+  call delete('Xtest')
+  bwipe Xtest
+endfunc
+
+func FillBuffer()
+  for i in range(1,13)
+    put=i
+    " Set 'undolevels' to split undo. 
+    exe "setg ul=" . &g:ul
+  endfor
+endfunc
+
+func Test_global_local_undolevels()
+  new one
+  set undolevels=5
+  call FillBuffer()
+  " will only undo the last 5 changes, end up with 13 - (5 + 1) = 7 lines
+  earlier 10
+  call assert_equal(5, &g:undolevels)
+  call assert_equal(-123456, &l:undolevels)
+  call assert_equal('7', getline('$'))
+
+  new two
+  setlocal undolevels=2
+  call FillBuffer()
+  " will only undo the last 2 changes, end up with 13 - (2 + 1) = 10 lines
+  earlier 10
+  call assert_equal(5, &g:undolevels)
+  call assert_equal(2, &l:undolevels)
+  call assert_equal('10', getline('$'))
+
+  setlocal ul=10
+  call assert_equal(5, &g:undolevels)
+  call assert_equal(10, &l:undolevels)
+
+  " Setting local value in "two" must not change local value in "one"
+  wincmd p
+  call assert_equal(5, &g:undolevels)
+  call assert_equal(-123456, &l:undolevels)
+
+  new three
+  setglobal ul=50
+  call assert_equal(50, &g:undolevels)
+  call assert_equal(-123456, &l:undolevels)
+
+  " Drop created windows
+  set ul&
+  new
+  only!
+endfunc
+
+func BackOne(expected)
+  call feedkeys('g-', 'xt')
+  call assert_equal(a:expected, getline(1))
+endfunc
+
+func Test_undo_del_chars()
+  " Setup a buffer without creating undo entries
+  new
+  set ul=-1
+  call setline(1, ['123-456'])
+  set ul=100
+  1
+  call test_settime(100)
+
+  " Delete three characters and undo with g-
+  call feedkeys('x', 'xt')
+  call feedkeys('x', 'xt')
+  call feedkeys('x', 'xt')
+  call assert_equal('-456', getline(1))
+  call BackOne('3-456')
+  call BackOne('23-456')
+  call BackOne('123-456')
+  call assert_fails("BackOne('123-456')")
+
+  :" Delete three other characters and go back in time with g-
+  call feedkeys('$x', 'xt')
+  call feedkeys('x', 'xt')
+  call feedkeys('x', 'xt')
+  call assert_equal('123-', getline(1))
+  call test_settime(101)
+
+  call BackOne('123-4')
+  call BackOne('123-45')
+  " skips '123-456' because it's older
+  call BackOne('-456')
+  call BackOne('3-456')
+  call BackOne('23-456')
+  call BackOne('123-456')
+  call assert_fails("BackOne('123-456')")
+  normal 10g+
+  call assert_equal('123-', getline(1))
+
+  :" Jump two seconds and go some seconds forward and backward
+  call test_settime(103)
+  call feedkeys("Aa\<Esc>", 'xt')
+  call feedkeys("Ab\<Esc>", 'xt')
+  call feedkeys("Ac\<Esc>", 'xt')
+  call assert_equal('123-abc', getline(1))
+  earlier 1s
+  call assert_equal('123-', getline(1))
+  earlier 3s
+  call assert_equal('123-456', getline(1))
+  later 1s
+  call assert_equal('123-', getline(1))
+  later 1h
+  call assert_equal('123-abc', getline(1))
+
+  close!
+endfunc
+
+func Test_undojoin()
+  new
+  call feedkeys("Goaaaa\<Esc>", 'xt')
+  call feedkeys("obbbb\<Esc>", 'xt')
+  call assert_equal(['aaaa', 'bbbb'], getline(2, '$'))
+  call feedkeys("u", 'xt')
+  call assert_equal(['aaaa'], getline(2, '$'))
+  call feedkeys("obbbb\<Esc>", 'xt')
+  undojoin
+  " Note: next change must not be as if typed
+  call feedkeys("occcc\<Esc>", 'x')
+  call assert_equal(['aaaa', 'bbbb', 'cccc'], getline(2, '$'))
+  call feedkeys("u", 'xt')
+  call assert_equal(['aaaa'], getline(2, '$'))
+  close!
+endfunc
+
+func Test_undo_write()
+  split Xtest
+  call feedkeys("ione one one\<Esc>", 'xt')
+  w!
+  call feedkeys("otwo\<Esc>", 'xt')
+  call feedkeys("otwo\<Esc>", 'xt')
+  w
+  call feedkeys("othree\<Esc>", 'xt')
+  call assert_equal(['one one one', 'two', 'two', 'three'], getline(1, '$'))
+  earlier 1f
+  call assert_equal(['one one one', 'two', 'two'], getline(1, '$'))
+  earlier 1f
+  call assert_equal(['one one one'], getline(1, '$'))
+  earlier 1f
+  call assert_equal([''], getline(1, '$'))
+  later 1f
+  call assert_equal(['one one one'], getline(1, '$'))
+  later 1f
+  call assert_equal(['one one one', 'two', 'two'], getline(1, '$'))
+  later 1f
+  call assert_equal(['one one one', 'two', 'two', 'three'], getline(1, '$'))
+
+  close!
+  call delete('Xtest')
+  bwipe! Xtest
+endfunc
+
+func Test_insert_expr()
+  new
+  " calling setline() triggers undo sync
+  call feedkeys("oa\<Esc>", 'xt')
+  call feedkeys("ob\<Esc>", 'xt')
+  set ul=100
+  call feedkeys("o1\<Esc>a2\<C-R>=setline('.','1234')\<CR>\<CR>\<Esc>", 'x')
+  call assert_equal(['a', 'b', '120', '34'], getline(2, '$'))
+  call feedkeys("u", 'x')
+  call assert_equal(['a', 'b', '12'], getline(2, '$'))
+  call feedkeys("u", 'x')
+  call assert_equal(['a', 'b'], getline(2, '$'))
+
+  call feedkeys("oc\<Esc>", 'xt')
+  set ul=100
+  call feedkeys("o1\<Esc>a2\<C-R>=setline('.','1234')\<CR>\<CR>\<Esc>", 'x')
+  call assert_equal(['a', 'b', 'c', '120', '34'], getline(2, '$'))
+  call feedkeys("u", 'x')
+  call assert_equal(['a', 'b', 'c', '12'], getline(2, '$'))
+
+  call feedkeys("od\<Esc>", 'xt')
+  set ul=100
+  call feedkeys("o1\<Esc>a2\<C-R>=string(123)\<CR>\<Esc>", 'x')
+  call assert_equal(['a', 'b', 'c', '12', 'd', '12123'], getline(2, '$'))
+  call feedkeys("u", 'x')
+  call assert_equal(['a', 'b', 'c', '12', 'd'], getline(2, '$'))
+
+  close!
+endfunc
diff --git a/src/testdir/test_undolevels.vim b/src/testdir/test_undolevels.vim
deleted file mode 100644 (file)
index b96b693..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-" Tests for 'undolevels'
-
-func FillBuffer()
-  for i in range(1,13)
-    put=i
-    " Set 'undolevels' to split undo. 
-    exe "setg ul=" . &g:ul
-  endfor
-endfunc
-
-func Test_global_local_undolevels()
-  new one
-  set undolevels=5
-  call FillBuffer()
-  " will only undo the last 5 changes, end up with 13 - (5 + 1) = 7 lines
-  earlier 10
-  call assert_equal(5, &g:undolevels)
-  call assert_equal(-123456, &l:undolevels)
-  call assert_equal('7', getline('$'))
-
-  new two
-  setlocal undolevels=2
-  call FillBuffer()
-  " will only undo the last 2 changes, end up with 13 - (2 + 1) = 10 lines
-  earlier 10
-  call assert_equal(5, &g:undolevels)
-  call assert_equal(2, &l:undolevels)
-  call assert_equal('10', getline('$'))
-
-  setlocal ul=10
-  call assert_equal(5, &g:undolevels)
-  call assert_equal(10, &l:undolevels)
-
-  " Setting local value in "two" must not change local value in "one"
-  wincmd p
-  call assert_equal(5, &g:undolevels)
-  call assert_equal(-123456, &l:undolevels)
-
-  new three
-  setglobal ul=50
-  call assert_equal(50, &g:undolevels)
-  call assert_equal(-123456, &l:undolevels)
-
-  " Drop created windows
-  set ul&
-  new
-  only!
-endfunc
index 71e62a19954762e37285aea513a857fb9ec050f0..bb5c73da2456b31e32b619025a362bf588049b04 100644 (file)
@@ -534,7 +534,7 @@ u_savecommon(
 
        uhp->uh_seq = ++curbuf->b_u_seq_last;
        curbuf->b_u_seq_cur = uhp->uh_seq;
-       uhp->uh_time = time(NULL);
+       uhp->uh_time = vim_time();
        uhp->uh_save_nr = 0;
        curbuf->b_u_time_cur = uhp->uh_time + 1;
 
@@ -2350,7 +2350,7 @@ undo_time(
        else
        {
            if (dosec)
-               closest = (long)(time(NULL) - starttime + 1);
+               closest = (long)(vim_time() - starttime + 1);
            else if (dofile)
                closest = curbuf->b_u_save_nr_last + 2;
            else
@@ -3104,10 +3104,10 @@ u_add_time(char_u *buf, size_t buflen, time_t tt)
 #ifdef HAVE_STRFTIME
     struct tm  *curtime;
 
-    if (time(NULL) - tt >= 100)
+    if (vim_time() - tt >= 100)
     {
        curtime = localtime(&tt);
-       if (time(NULL) - tt < (60L * 60L * 12L))
+       if (vim_time() - tt < (60L * 60L * 12L))
            /* within 12 hours */
            (void)strftime((char *)buf, buflen, "%H:%M:%S", curtime);
        else
@@ -3117,7 +3117,7 @@ u_add_time(char_u *buf, size_t buflen, time_t tt)
     else
 #endif
        vim_snprintf((char *)buf, buflen, _("%ld seconds ago"),
-                                                    (long)(time(NULL) - tt));
+                                                     (long)(vim_time() - tt));
 }
 
 /*
index 53597e9de8dfbd4da526027d7f561e41b14f77fb..76bca7a412f16e024ad7e3beed37215e2ea6061b 100644 (file)
@@ -758,6 +758,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2113,
 /**/
     2112,
 /**/