1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-24 02:20:03 +08:00
SpaceVim/test/api/job.vader
2017-10-22 22:31:59 +08:00

44 lines
1020 B
Plaintext

Execute ( SpaceVim api: job ):
let job = SpaceVim#api#import('job')
let os = SpaceVim#api#import('system')
if os.isWindows
finish
endif
let argv = ['cat']
let g:stdout = ''
let stderr = ''
let exit_data = 1
function! s:on_stdout(id, data, event) abort
if a:event ==# 'stdout'
for a in a:data
if !empty(a)
let g:stdout = a
endif
endfor
elseif a:event ==# 'exit'
let g:exit_data = a:data
else
let g:stderr = a:data
endif
endfunction
let opt = {
\ 'on_stdout' : function('s:on_stdout'),
\ 'on_stderr' : function('s:on_stdout'),
\ 'on_exit' : function('s:on_stdout'),
\ }
let jobid = job.start(argv,opt)
if jobid >= 0
call job.send(jobid, 'foo')
sleep 10m
AssertEqual stdout, 'foo'
AssertEqual job.status(jobid), 'run'
call job.stop(jobid)
AssertEqual exit_data, 1
else
let jobid = job.start(['echo', 'foo'],opt)
AssertEqual stdout, 'foo'
AssertEqual exit_data, 0
endif