1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-24 05:20:04 +08:00
SpaceVim/test/api/job.vader

44 lines
1020 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-10-22 22:31:59 +08:00
let os = SpaceVim#api#import('system')
if os.isWindows
finish
endif
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-22 14:44:47 +08:00
let exit_data = 1
2017-04-15 12:28:48 +08:00
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'
2017-04-22 14:44:47 +08:00
let g:exit_data = 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)
2017-04-22 14:44:47 +08:00
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
2017-04-15 12:28:48 +08:00