aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2015-04-10 23:19:04 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2015-04-11 08:46:59 -0300
commitccd42e81c806b112b1a5ddf996bd88334dce2d6a (patch)
treeb904bd479e0fc395f1268db34839a9c4b3912934 /test/functional
parent17db7f1e14d4f1f2a70832ab10232ef0cdfb5a6b (diff)
downloadrneovim-ccd42e81c806b112b1a5ddf996bd88334dce2d6a.tar.gz
rneovim-ccd42e81c806b112b1a5ddf996bd88334dce2d6a.tar.bz2
rneovim-ccd42e81c806b112b1a5ddf996bd88334dce2d6a.zip
eval: Fix `jobwait()`
- Properly save job event deferring state for recursive calls - Disable breakcheck while running. Breakcheck can invoke job callbacks in unexpected places.
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/job/job_spec.lua46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/functional/job/job_spec.lua b/test/functional/job/job_spec.lua
index c517ae4c1b..6bcae62ebf 100644
--- a/test/functional/job/job_spec.lua
+++ b/test/functional/job/job_spec.lua
@@ -249,6 +249,52 @@ describe('jobs', function()
eq({'notification', 'wait', {{-2}}}, next_msg())
end)
+ it('can be called recursively', function()
+ source([[
+ let g:opts = {}
+ let g:counter = 0
+ function g:opts.on_stdout(id, msg)
+ if self.state == 0
+ if self.counter < 10
+ call Run()
+ endif
+ let self.state = 1
+ call jobsend(a:id, "line1\n")
+ elseif self.state == 1
+ let self.state = 2
+ call jobsend(a:id, "line2\n")
+ elseif self.state == 2
+ let self.state = 3
+ call jobsend(a:id, "line3\n")
+ else
+ call rpcnotify(g:channel, 'w', printf('job %d closed', self.counter))
+ call jobclose(a:id, 'stdin')
+ endif
+ endfunction
+ function g:opts.on_exit()
+ call rpcnotify(g:channel, 'w', printf('job %d exited', self.counter))
+ endfunction
+ function Run()
+ let g:counter += 1
+ let j = copy(g:opts)
+ let j.state = 0
+ let j.counter = g:counter
+ call jobwait([
+ \ jobstart([&sh, '-c', 'echo ready; cat -'], j),
+ \ ])
+ endfunction
+ ]])
+ execute('call Run()')
+ local r
+ for i = 10, 1, -1 do
+ r = next_msg()
+ eq('job '..i..' closed', r[3][1])
+ r = next_msg()
+ eq('job '..i..' exited', r[3][1])
+ end
+ eq(10, nvim('eval', 'g:counter'))
+ end)
+
describe('with timeout argument', function()
it('will return -1 if the wait timed out', function()
source([[