2017-04-15 12:28:48 +08:00
|
|
|
Execute ( SpaceVim api: job ):
|
|
|
|
let job = SpaceVim#api#import('job')
|
2020-09-01 22:55:28 +08:00
|
|
|
let sys = SpaceVim#api#import('system')
|
|
|
|
let cmp = SpaceVim#api#import('vim#compatible')
|
|
|
|
if sys.isWindows
|
|
|
|
let cat = fnamemodify(v:progpath, ':h') . '\cat.exe'
|
|
|
|
else
|
|
|
|
let cat = 'cat'
|
|
|
|
endif
|
|
|
|
if !executable(cat)
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
for line in cmp.systemlist(shellescape(cat) . ' --version')
|
|
|
|
Log line
|
|
|
|
endfor
|
|
|
|
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'
|
2020-08-30 20:49:56 +08:00
|
|
|
let g:stdout = join(a:data, "\n")
|
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'),
|
|
|
|
\ }
|
2020-08-30 20:49:56 +08:00
|
|
|
if job.vim_job || job.nvim_job
|
|
|
|
let jobid = job.start(argv,opt)
|
2017-04-22 14:44:47 +08:00
|
|
|
call job.send(jobid, 'foo')
|
2020-09-02 01:12:44 +08:00
|
|
|
sleep 2000m
|
2017-04-22 14:44:47 +08:00
|
|
|
AssertEqual stdout, 'foo'
|
2020-08-29 16:46:57 +08:00
|
|
|
AssertEqual job.status(jobid), 'run'
|
2017-04-22 14:44:47 +08:00
|
|
|
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
|
|
|
|
|
|
|
|