2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2016-05-22 12:53:43 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
local feed, eq, eval, ok = helpers.feed, helpers.eq, helpers.eval, helpers.ok
|
2016-04-21 08:06:03 -07:00
|
|
|
local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run
|
2017-04-08 14:12:26 -07:00
|
|
|
local clear, command, funcs = helpers.clear, helpers.command, helpers.funcs
|
2021-11-01 09:21:16 -07:00
|
|
|
local exc_exec = helpers.exc_exec
|
2016-09-25 00:47:23 -07:00
|
|
|
local curbufmeths = helpers.curbufmeths
|
2019-01-16 13:21:10 -07:00
|
|
|
local load_adjust = helpers.load_adjust
|
2019-06-29 08:53:09 -07:00
|
|
|
local retry = helpers.retry
|
2016-04-21 08:06:03 -07:00
|
|
|
|
|
|
|
describe('timers', function()
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
source([[
|
|
|
|
let g:val = 0
|
|
|
|
func MyHandler(timer)
|
|
|
|
let g:val += 1
|
|
|
|
endfunc
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('works one-shot', function()
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
eq(0, eval("[timer_start(10, 'MyHandler'), g:val][1]"))
|
|
|
|
run(nil, nil, nil, load_adjust(100))
|
2016-04-21 08:06:03 -07:00
|
|
|
eq(1,eval("g:val"))
|
|
|
|
end)
|
|
|
|
|
2016-06-05 01:59:40 -07:00
|
|
|
it('works one-shot when repeat=0', function()
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
eq(0, eval("[timer_start(10, 'MyHandler', {'repeat': 0}), g:val][1]"))
|
|
|
|
run(nil, nil, nil, load_adjust(100))
|
|
|
|
eq(1, eval("g:val"))
|
2016-06-05 01:59:40 -07:00
|
|
|
end)
|
|
|
|
|
2016-04-21 08:06:03 -07:00
|
|
|
it('works with repeat two', function()
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
eq(0, eval("[timer_start(10, 'MyHandler', {'repeat': 2}), g:val][1]"))
|
|
|
|
run(nil, nil, nil, load_adjust(20))
|
|
|
|
retry(nil, load_adjust(300), function()
|
|
|
|
eq(2, eval("g:val"))
|
|
|
|
end)
|
2016-04-21 08:06:03 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('are triggered during sleep', function()
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
source([[
|
|
|
|
let g:val = -1
|
|
|
|
func! MyHandler(timer)
|
|
|
|
if g:val >= 0
|
|
|
|
let g:val += 1
|
|
|
|
if g:val == 2
|
|
|
|
call timer_stop(a:timer)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunc
|
|
|
|
]])
|
|
|
|
eval("timer_start(10, 'MyHandler', {'repeat': -1})")
|
2016-04-21 08:06:03 -07:00
|
|
|
nvim_async("command", "sleep 10")
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
eq(-1, eval("g:val")) -- timer did nothing yet.
|
|
|
|
nvim_async("command", "let g:val = 0")
|
|
|
|
run(nil, nil, nil, load_adjust(20))
|
|
|
|
retry(nil, nil, function()
|
|
|
|
eq(2, eval("g:val"))
|
|
|
|
end)
|
2016-04-21 08:06:03 -07:00
|
|
|
end)
|
|
|
|
|
2016-06-05 01:49:33 -07:00
|
|
|
it('works with zero timeout', function()
|
|
|
|
-- timer_start does still not invoke the callback immediately
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
eq(0, eval("[timer_start(0, 'MyHandler', {'repeat': 1000}), g:val][1]"))
|
|
|
|
retry(nil, nil, function()
|
|
|
|
eq(1000, eval("g:val"))
|
|
|
|
end)
|
2016-06-05 01:49:33 -07:00
|
|
|
end)
|
|
|
|
|
2016-04-21 08:06:03 -07:00
|
|
|
it('can be started during sleep', function()
|
|
|
|
nvim_async("command", "sleep 10")
|
|
|
|
-- this also tests that remote requests works during sleep
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
eq(0, eval("[timer_start(10, 'MyHandler', {'repeat': 2}), g:val][1]"))
|
|
|
|
run(nil, nil, nil, load_adjust(20))
|
|
|
|
retry(nil, load_adjust(300), function() eq(2,eval("g:val")) end)
|
2016-04-21 08:06:03 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('are paused when event processing is disabled', function()
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
command("call timer_start(5, 'MyHandler', {'repeat': -1})")
|
|
|
|
run(nil, nil, nil, load_adjust(10))
|
2016-04-21 08:06:03 -07:00
|
|
|
local count = eval("g:val")
|
2016-09-25 00:47:23 -07:00
|
|
|
-- shows two line error message and thus invokes the return prompt.
|
|
|
|
-- if we start to allow event processing here, we need to change this test.
|
2017-04-08 14:12:26 -07:00
|
|
|
feed(':throw "fatal error"<CR>')
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
run(nil, nil, nil, load_adjust(30))
|
2016-09-25 00:47:23 -07:00
|
|
|
feed("<cr>")
|
|
|
|
local diff = eval("g:val") - count
|
2018-10-07 23:56:13 -07:00
|
|
|
assert(0 <= diff and diff <= 4,
|
|
|
|
'expected (0 <= diff <= 4), got: '..tostring(diff))
|
2016-09-25 00:47:23 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('are triggered in blocking getchar() call', function()
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
command("call timer_start(5, 'MyHandler', {'repeat': -1})")
|
|
|
|
nvim_async("command", "let g:val = 0 | let g:c = getchar()")
|
|
|
|
retry(nil, nil, function()
|
2019-08-20 17:32:20 -07:00
|
|
|
local val = eval("g:val")
|
2022-06-30 04:16:46 -07:00
|
|
|
ok(val >= 2, '>= 2', tostring(val))
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
eq(0, eval("getchar(1)"))
|
|
|
|
end)
|
2016-04-21 08:06:03 -07:00
|
|
|
feed("c")
|
|
|
|
eq(99, eval("g:c"))
|
|
|
|
end)
|
|
|
|
|
2016-09-25 00:47:23 -07:00
|
|
|
it('can invoke redraw in blocking getchar() call', function()
|
|
|
|
local screen = Screen.new(40, 6)
|
|
|
|
screen:attach()
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
[1] = {bold=true, foreground=Screen.colors.Blue},
|
|
|
|
})
|
|
|
|
|
|
|
|
curbufmeths.set_lines(0, -1, true, {"ITEM 1", "ITEM 2"})
|
|
|
|
source([[
|
2019-09-23 23:55:27 -07:00
|
|
|
let g:cont = 0
|
2016-09-25 00:47:23 -07:00
|
|
|
func! AddItem(timer)
|
2019-09-23 23:55:27 -07:00
|
|
|
if !g:cont
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
call timer_stop(a:timer)
|
|
|
|
|
2016-09-25 00:47:23 -07:00
|
|
|
call nvim_buf_set_lines(0, 2, 2, v:true, ['ITEM 3'])
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
|
|
|
|
" Meant to test for what Vim tests in Test_peek_and_get_char.
|
2018-09-04 06:59:27 -07:00
|
|
|
call getchar(1)
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
|
2016-09-25 00:47:23 -07:00
|
|
|
redraw
|
|
|
|
endfunc
|
|
|
|
]])
|
|
|
|
nvim_async("command", "let g:c2 = getchar()")
|
2019-09-23 23:55:27 -07:00
|
|
|
nvim_async("command", "call timer_start("..load_adjust(100)..", 'AddItem', {'repeat': -1})")
|
2016-09-25 00:47:23 -07:00
|
|
|
|
|
|
|
screen:expect([[
|
2022-09-13 03:56:30 -07:00
|
|
|
^ITEM 1 |
|
2016-09-25 00:47:23 -07:00
|
|
|
ITEM 2 |
|
|
|
|
{1:~ }|
|
|
|
|
{1:~ }|
|
|
|
|
{1:~ }|
|
2022-09-13 03:56:30 -07:00
|
|
|
|
|
2016-09-25 00:47:23 -07:00
|
|
|
]])
|
2019-09-23 23:55:27 -07:00
|
|
|
nvim_async("command", "let g:cont = 1")
|
2016-09-25 00:47:23 -07:00
|
|
|
|
|
|
|
screen:expect([[
|
2022-09-13 03:56:30 -07:00
|
|
|
^ITEM 1 |
|
2016-09-25 00:47:23 -07:00
|
|
|
ITEM 2 |
|
|
|
|
ITEM 3 |
|
|
|
|
{1:~ }|
|
|
|
|
{1:~ }|
|
2022-09-13 03:56:30 -07:00
|
|
|
|
|
2016-09-25 00:47:23 -07:00
|
|
|
]])
|
|
|
|
|
|
|
|
feed("3")
|
|
|
|
eq(51, eval("g:c2"))
|
2022-09-13 03:56:30 -07:00
|
|
|
screen:expect{grid=[[
|
2016-09-25 00:47:23 -07:00
|
|
|
^ITEM 1 |
|
|
|
|
ITEM 2 |
|
|
|
|
ITEM 3 |
|
|
|
|
{1:~ }|
|
|
|
|
{1:~ }|
|
|
|
|
|
|
2022-09-13 03:56:30 -07:00
|
|
|
]], unchanged=true}
|
2016-09-25 00:47:23 -07:00
|
|
|
end)
|
|
|
|
|
2016-04-21 08:06:03 -07:00
|
|
|
it('can be stopped', function()
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
local t_init_val = eval("[timer_start(5, 'MyHandler', {'repeat': -1}), g:val]")
|
|
|
|
eq(0, t_init_val[2])
|
|
|
|
run(nil, nil, nil, load_adjust(30))
|
|
|
|
funcs.timer_stop(t_init_val[1])
|
2016-04-21 08:06:03 -07:00
|
|
|
local count = eval("g:val")
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
run(nil, load_adjust(300), nil, load_adjust(30))
|
2016-04-21 08:06:03 -07:00
|
|
|
local count2 = eval("g:val")
|
|
|
|
-- when count is eval:ed after timer_stop this should be non-racy
|
|
|
|
eq(count, count2)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('can be stopped from the handler', function()
|
|
|
|
source([[
|
|
|
|
func! MyHandler(timer)
|
|
|
|
let g:val += 1
|
|
|
|
if g:val == 3
|
|
|
|
call timer_stop(a:timer)
|
|
|
|
" check double stop is ignored
|
|
|
|
call timer_stop(a:timer)
|
|
|
|
endif
|
|
|
|
endfunc
|
|
|
|
]])
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
eq(0, eval("g:val"))
|
2019-06-29 08:53:09 -07:00
|
|
|
command("call timer_start(10, 'MyHandler', {'repeat': -1})")
|
2019-08-13 15:44:32 -07:00
|
|
|
retry(nil, nil, function()
|
2019-06-29 08:53:09 -07:00
|
|
|
eq(3, eval("g:val"))
|
|
|
|
end)
|
2016-04-21 08:06:03 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('can have two timers', function()
|
|
|
|
source([[
|
|
|
|
let g:val2 = 0
|
|
|
|
func! MyHandler2(timer)
|
|
|
|
let g:val2 += 1
|
|
|
|
endfunc
|
|
|
|
]])
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
command("call timer_start(2, 'MyHandler', {'repeat': 3})")
|
|
|
|
command("call timer_start(4, 'MyHandler2', {'repeat': 2})")
|
2019-09-01 15:37:38 -07:00
|
|
|
retry(nil, nil, function()
|
|
|
|
eq(3, eval("g:val"))
|
|
|
|
eq(2, eval("g:val2"))
|
|
|
|
end)
|
2016-04-21 08:06:03 -07:00
|
|
|
end)
|
|
|
|
|
2016-08-08 08:51:57 -07:00
|
|
|
it('do not crash when processing events in the handler', function()
|
|
|
|
source([[
|
|
|
|
let g:val = 0
|
|
|
|
func! MyHandler(timer)
|
|
|
|
call timer_stop(a:timer)
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
sleep 10m
|
2016-08-08 08:51:57 -07:00
|
|
|
let g:val += 1
|
|
|
|
endfunc
|
|
|
|
]])
|
2017-04-08 14:12:26 -07:00
|
|
|
command("call timer_start(5, 'MyHandler', {'repeat': 1})")
|
2020-11-30 23:59:28 -07:00
|
|
|
run(nil, nil, nil, load_adjust(20))
|
|
|
|
retry(nil, load_adjust(150), function()
|
tests: timer_spec: lower timeout, avoids flakiness
Inspired by quickbuild failure, where `g:val` was increased already:
20:07:04,227 INFO - not ok 1164 - timers works with repeat two
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua @ 36
20:07:04,227 INFO - # Failure message: test/functional/eval/timer_spec.lua:38: Expected objects to be the same.
20:07:04,227 INFO - # Passed in:
20:07:04,227 INFO - # (number) 1
20:07:04,227 INFO - # Expected:
20:07:04,227 INFO - # (number) 0
20:07:04,227 INFO - # stack traceback:
20:07:04,227 INFO - # test/functional/eval/timer_spec.lua:38: in function <test/functional/eval/timer_spec.lua:36>
Uses a pattern of `eq()`ing `timer_start` and `g:val` in the same `eval`
call, and decreases timeouts in general.
Improves runtime from ~5s to <2s.
2019-08-13 17:30:29 -07:00
|
|
|
eq(1, eval("g:val"))
|
|
|
|
end)
|
2016-08-08 08:51:57 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
2016-05-22 12:53:43 -07:00
|
|
|
it("doesn't mess up the cmdline", function()
|
|
|
|
local screen = Screen.new(40, 6)
|
|
|
|
screen:attach()
|
2016-08-09 06:11:04 -07:00
|
|
|
screen:set_default_attr_ids( {[0] = {bold=true, foreground=255}} )
|
2016-05-22 12:53:43 -07:00
|
|
|
source([[
|
2017-06-26 05:49:15 -07:00
|
|
|
let g:val = 0
|
2016-05-22 12:53:43 -07:00
|
|
|
func! MyHandler(timer)
|
2019-09-23 23:55:27 -07:00
|
|
|
while !g:val
|
|
|
|
return
|
|
|
|
endwhile
|
|
|
|
call timer_stop(a:timer)
|
|
|
|
|
2016-05-22 12:53:43 -07:00
|
|
|
echo "evil"
|
2019-09-01 02:25:00 -07:00
|
|
|
redraw
|
2019-09-23 23:55:27 -07:00
|
|
|
let g:val = 2
|
2016-05-22 12:53:43 -07:00
|
|
|
endfunc
|
|
|
|
]])
|
2019-09-23 23:55:27 -07:00
|
|
|
command("call timer_start(100, 'MyHandler', {'repeat': -1})")
|
2016-05-22 12:53:43 -07:00
|
|
|
feed(":good")
|
|
|
|
screen:expect([[
|
|
|
|
|
|
2016-08-09 06:11:04 -07:00
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
2016-05-22 12:53:43 -07:00
|
|
|
:good^ |
|
|
|
|
]])
|
2019-09-23 23:55:27 -07:00
|
|
|
command('let g:val = 1')
|
2023-02-14 16:26:55 -07:00
|
|
|
screen:expect_unchanged(true, load_adjust(200))
|
2017-06-26 05:49:15 -07:00
|
|
|
|
2019-09-23 23:55:27 -07:00
|
|
|
eq(2, eval('g:val'))
|
2016-05-22 12:53:43 -07:00
|
|
|
end)
|
2021-11-01 09:21:16 -07:00
|
|
|
|
|
|
|
it("timer_start can't be used in the sandbox", function()
|
|
|
|
source [[
|
|
|
|
function! Scary(timer) abort
|
|
|
|
call execute('echo ''execute() should be disallowed''', '')
|
|
|
|
endfunction
|
|
|
|
]]
|
|
|
|
eq("Vim(call):E48: Not allowed in sandbox", exc_exec("sandbox call timer_start(0, 'Scary')"))
|
|
|
|
end)
|
2022-02-02 22:43:48 -07:00
|
|
|
|
2022-03-29 14:25:00 -07:00
|
|
|
it('can be triggered after an empty string <expr> mapping #17257', function()
|
2022-02-02 22:43:48 -07:00
|
|
|
local screen = Screen.new(40, 6)
|
|
|
|
screen:attach()
|
|
|
|
command([=[imap <expr> <F2> [timer_start(0, { _ -> execute("throw 'x'", "") }), ''][-1]]=])
|
|
|
|
feed('i<F2>')
|
|
|
|
screen:expect({any='E605: Exception not caught: x'})
|
|
|
|
end)
|
2016-04-21 08:06:03 -07:00
|
|
|
end)
|