1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 14:10:06 +08:00
SpaceVim/test/api/job.vader

34 lines
778 B
Plaintext
Raw Normal View History

2017-04-15 12:28:48 +08:00
Execute ( SpaceVim api: job ):
let job = SpaceVim#api#import('job')
2017-04-15 16:50:33 +08:00
let argv = ['cat']
2017-04-15 14:14:52 +08:00
let g:stdout = ''
2017-04-15 13:56:15 +08:00
let stderr = ''
2017-04-15 12:28:48 +08:00
let exit = 1
function! s:on_stdout(id, data, event) abort
if a:event ==# 'stdout'
2017-04-15 14:06:40 +08:00
for a in a:data
if !empty(a)
let g:stdout = a
endif
endfor
2017-04-15 12:28:48 +08:00
elseif a:event ==# 'exit'
let g:exit = a:data
2017-04-15 13:56:15 +08:00
else
let g:stderr = a:data
2017-04-15 12:28:48 +08:00
endif
endfunction
let opt = {
\ 'on_stdout' : function('s:on_stdout'),
2017-04-15 13:56:15 +08:00
\ 'on_stderr' : function('s:on_stdout'),
2017-04-15 12:28:48 +08:00
\ 'on_exit' : function('s:on_stdout'),
\ }
2017-04-15 16:50:33 +08:00
let jobid = job.start(argv,opt)
call job.send(jobid, 'foo')
sleep 10m
AssertEqual stdout, 'foo'
AssertEqual job.status(jobid), 'run'
call job.stop(jobid)
AssertEqual exit, 1
2017-04-15 12:28:48 +08:00