From 4c4bcecc4a1b817be742856ac8600c90d24c42f4 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 3 Jan 2020 20:08:13 -0500 Subject: vim-patch:8.0.1817: a timer may change v:count unexpectedly Problem: A timer may change v:count unexpectedly. Solution: Save and restore v:count and similar variables when a timer callback is invoked. (closes vim/vim#2897) https://github.com/vim/vim/commit/b0f42ba60d9e6d101d103421ba0c351811615c15 --- src/nvim/testdir/test_timers.vim | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index bd63d94729..cadec88af9 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -5,6 +5,7 @@ if !has('timers') endif source shared.vim +source screendump.vim source load.vim func MyHandler(timer) @@ -263,4 +264,35 @@ func Test_ex_mode() call timer_stop(timer) endfunc +func Test_restore_count() + if !CanRunVimInTerminal() + return + endif + " Check that v:count is saved and restored, not changed by a timer. + call writefile([ + \ 'nnoremap L v:count ? v:count . "l" : "l"', + \ 'func Doit(id)', + \ ' normal 3j', + \ 'endfunc', + \ 'call timer_start(100, "Doit")', + \ ], 'Xtrcscript') + call writefile([ + \ '1-1234', + \ '2-1234', + \ '3-1234', + \ ], 'Xtrctext') + let buf = RunVimInTerminal('-S Xtrcscript Xtrctext', {}) + + " Wait for the timer to move the cursor to the third line. + call WaitForAssert({-> assert_equal(3, term_getcursor(buf)[0])}) + call assert_equal(1, term_getcursor(buf)[1]) + " Now check that v:count has not been set to 3 + call term_sendkeys(buf, 'L') + call WaitForAssert({-> assert_equal(2, term_getcursor(buf)[1])}) + + call StopVimInTerminal(buf) + call delete('Xtrcscript') + call delete('Xtrctext') +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From a2554858df533fcfa0ba6074648e21cda50934d9 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 3 Jan 2020 22:43:06 -0500 Subject: vim-patch:8.1.0840: getchar(0) never returns a character in the terminal Problem: getchar(0) never returns a character in the terminal. Solution: Call wait_func() at least once. https://github.com/vim/vim/commit/12dfc9eef14fe74c46145aa9e6cba9666f1bcd40 --- src/nvim/testdir/test_timers.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index cadec88af9..161a89c38c 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -253,6 +253,16 @@ func Test_peek_and_get_char() call timer_stop(intr) endfunc +func Test_getchar_zero() + call timer_start(20, {id -> feedkeys('x', 'L')}) + let c = 0 + while c == 0 + let c = getchar(0) + sleep 10m + endwhile + call assert_equal('x', nr2char(c)) +endfunc + func Test_ex_mode() " Function with an empty line. func Foo(...) -- cgit From 25613fa65bf1c3bbe2b675ff273acb94f47656bc Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 3 Jan 2020 22:47:38 -0500 Subject: vim-patch:8.1.0842: getchar_zero test fails on MS-Windows Problem: getchar_zero test fails on MS-Windows. Solution: Disable the test for now. https://github.com/vim/vim/commit/cb908a813cebf7fb4608ff43fc3d258cf2768809 --- src/nvim/testdir/test_timers.vim | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 161a89c38c..e4d9329ac6 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -254,13 +254,20 @@ func Test_peek_and_get_char() endfunc func Test_getchar_zero() - call timer_start(20, {id -> feedkeys('x', 'L')}) + if has('win32') + " Console: no low-level input + " GUI: somehow doesn't work + return + endif + + let id = timer_start(20, {id -> feedkeys('x', 'L')}) let c = 0 while c == 0 let c = getchar(0) sleep 10m endwhile call assert_equal('x', nr2char(c)) + call timer_stop(id) endfunc func Test_ex_mode() @@ -268,7 +275,7 @@ func Test_ex_mode() func Foo(...) endfunc - let timer = timer_start(40, function('g:Foo'), {'repeat':-1}) + let timer = timer_start(40, function('g:Foo'), {'repeat':-1}) " This used to throw error E749. exe "normal Qsleep 100m\rvi\r" call timer_stop(timer) -- cgit From d139fb5cd08a9bdee30e0735e9e795585036ce7b Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 3 Jan 2020 22:48:53 -0500 Subject: vim-patch:8.1.0844: when timer fails test will hang forever Problem: When timer fails test will hang forever. Solution: Use reltime() to limit waiting time. (Ozaki Kiichi, closes vim/vim#3878) https://github.com/vim/vim/commit/50948e4ac24314d5a70404bbc592ffc28755ad9f --- src/nvim/testdir/test_timers.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index e4d9329ac6..6c336e6fa6 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -260,9 +260,11 @@ func Test_getchar_zero() return endif + " Measure the elapsed time to avoid a hang when it fails. + let start = reltime() let id = timer_start(20, {id -> feedkeys('x', 'L')}) let c = 0 - while c == 0 + while c == 0 && reltimefloat(reltime(start)) < 0.2 let c = getchar(0) sleep 10m endwhile -- cgit