mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-24 09:30:04 +08:00
36 lines
904 B
Plaintext
36 lines
904 B
Plaintext
Execute ( SpaceVim api: job ):
|
|
let job = SpaceVim#api#import('job')
|
|
let argv = ['cat']
|
|
let g:stdout = ''
|
|
let stderr = ''
|
|
let exit_data = 1
|
|
function! s:on_stdout(id, data, event) abort
|
|
if a:event ==# 'stdout'
|
|
let g:stdout = join(a:data, "\n")
|
|
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'),
|
|
\ }
|
|
if job.vim_job || job.nvim_job
|
|
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_data, 1
|
|
else
|
|
let jobid = job.start(['echo', 'foo'],opt)
|
|
AssertEqual stdout, 'foo'
|
|
AssertEqual exit_data, 0
|
|
endif
|
|
|
|
|