summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-07-29 23:03:03 +0200
committerBram Moolenaar <Bram@vim.org>2019-07-29 23:03:03 +0200
commitf386f08ccbd88e28479a4131a1b919bd3c0913ea (patch)
treea7b33711ac9ac0510983503a6178d95a50cc4741
parent4641a122f2ffb820ec6d05526532ab38930c5286 (diff)
patch 8.1.1777: useless checks for job feature in channel testv8.1.1777
Problem: Useless checks for job feature in channel test. Solution: Remove the checks. Remove ch_log() calls.
-rw-r--r--src/testdir/test_channel.vim320
-rw-r--r--src/version.c2
2 files changed, 90 insertions, 232 deletions
diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim
index 62eaa2089c..5a4234cec9 100644
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -1,5 +1,6 @@
-" Test for channel functions.
+" Test for channel and job functions.
+" When +channel is supported then +job is too, so we don't check for that.
source check.vim
CheckFeature channel
@@ -14,6 +15,7 @@ endif
" Uncomment the next line to see what happens. Output is in
" src/testdir/channellog.
+" Add ch_log() calls where you want to see what happens.
" call ch_logfile('channellog', 'w')
let s:chopt = {}
@@ -56,10 +58,10 @@ func Ch_communicate(port)
call assert_report("Can't open channel")
return
endif
- if has('job')
- " check that getjob without a job is handled correctly
- call assert_equal('no process', string(ch_getjob(handle)))
- endif
+
+ " check that getjob without a job is handled correctly
+ call assert_equal('no process', string(ch_getjob(handle)))
+
let dict = ch_info(handle)
call assert_true(dict.id != 0)
call assert_equal('open', dict.status)
@@ -445,10 +447,6 @@ endfunc
"""""""""
func Test_raw_pipe()
- if !has('job')
- return
- endif
- call ch_log('Test_raw_pipe()')
" Add a dummy close callback to avoid that messages are dropped when calling
" ch_canread().
" Also test the non-blocking option.
@@ -514,10 +512,6 @@ func Test_raw_pipe()
endfunc
func Test_raw_pipe_blob()
- if !has('job')
- return
- endif
- call ch_log('Test_raw_pipe_blob()')
" Add a dummy close callback to avoid that messages are dropped when calling
" ch_canread().
" Also test the non-blocking option.
@@ -559,10 +553,6 @@ func Test_raw_pipe_blob()
endfunc
func Test_nl_pipe()
- if !has('job')
- return
- endif
- call ch_log('Test_nl_pipe()')
let job = job_start([s:python, "test_channel_pipe.py"])
call assert_equal("run", job_status(job))
try
@@ -587,54 +577,6 @@ func Test_nl_pipe()
endtry
endfunc
-func Test_nl_err_to_out_pipe()
- if !has('job')
- return
- endif
- call ch_logfile('Xlog')
- call ch_log('Test_nl_err_to_out_pipe()')
- let job = job_start(s:python . " test_channel_pipe.py", {'err_io': 'out'})
- call assert_equal("run", job_status(job))
- try
- let handle = job_getchannel(job)
- call ch_sendraw(handle, "echo something\n")
- call assert_equal("something", ch_readraw(handle))
-
- call ch_sendraw(handle, "echoerr wrong\n")
- call assert_equal("wrong", ch_readraw(handle))
- finally
- call job_stop(job)
- call ch_logfile('')
- let loglines = readfile('Xlog')
- call assert_true(len(loglines) > 10)
- let found_test = 0
- let found_send = 0
- let found_recv = 0
- let found_stop = 0
- for l in loglines
- if l =~ 'Test_nl_err_to_out_pipe'
- let found_test = 1
- endif
- if l =~ 'SEND on.*echo something'
- let found_send = 1
- endif
- if l =~ 'RECV on.*something'
- let found_recv = 1
- endif
- if l =~ 'Stopping job with'
- let found_stop = 1
- endif
- endfor
- call assert_equal(1, found_test)
- call assert_equal(1, found_send)
- call assert_equal(1, found_recv)
- call assert_equal(1, found_stop)
- " On MS-Windows need to sleep for a moment to be able to delete the file.
- sleep 10m
- call delete('Xlog')
- endtry
-endfunc
-
func Stop_g_job()
call job_stop(g:job)
if has('win32')
@@ -646,10 +588,6 @@ func Stop_g_job()
endfunc
func Test_nl_read_file()
- if !has('job')
- return
- endif
- call ch_log('Test_nl_read_file()')
call writefile(['echo something', 'echoerr wrong', 'double this'], 'Xinput')
let g:job = job_start(s:python . " test_channel_pipe.py",
\ {'in_io': 'file', 'in_name': 'Xinput'})
@@ -667,10 +605,6 @@ func Test_nl_read_file()
endfunc
func Test_nl_write_out_file()
- if !has('job')
- return
- endif
- call ch_log('Test_nl_write_out_file()')
let g:job = job_start(s:python . " test_channel_pipe.py",
\ {'out_io': 'file', 'out_name': 'Xoutput'})
call assert_equal("run", job_status(g:job))
@@ -688,10 +622,6 @@ func Test_nl_write_out_file()
endfunc
func Test_nl_write_err_file()
- if !has('job')
- return
- endif
- call ch_log('Test_nl_write_err_file()')
let g:job = job_start(s:python . " test_channel_pipe.py",
\ {'err_io': 'file', 'err_name': 'Xoutput'})
call assert_equal("run", job_status(g:job))
@@ -708,10 +638,6 @@ func Test_nl_write_err_file()
endfunc
func Test_nl_write_both_file()
- if !has('job')
- return
- endif
- call ch_log('Test_nl_write_both_file()')
let g:job = job_start(s:python . " test_channel_pipe.py",
\ {'out_io': 'file', 'out_name': 'Xoutput', 'err_io': 'out'})
call assert_equal("run", job_status(g:job))
@@ -734,10 +660,6 @@ func BufCloseCb(ch)
endfunc
func Run_test_pipe_to_buffer(use_name, nomod, do_msg)
- if !has('job')
- return
- endif
- call ch_log('Test_pipe_to_buffer()')
let g:Ch_bufClosed = 'no'
let options = {'out_io': 'buffer', 'close_cb': 'BufCloseCb'}
let expected = ['', 'line one', 'line two', 'this', 'AND this', 'Goodbye!']
@@ -798,9 +720,6 @@ func Test_pipe_to_buffer_name_nomsg()
endfunc
func Test_close_output_buffer()
- if !has('job')
- return
- endif
enew!
let test_lines = ['one', 'two']
call setline(1, test_lines)
@@ -829,10 +748,6 @@ func Test_close_output_buffer()
endfunc
func Run_test_pipe_err_to_buffer(use_name, nomod, do_msg)
- if !has('job')
- return
- endif
- call ch_log('Test_pipe_err_to_buffer()')
let options = {'err_io': 'buffer'}
let expected = ['', 'line one', 'line two', 'this', 'AND this']
if a:use_name
@@ -890,10 +805,6 @@ func Test_pipe_err_to_buffer_name_nomsg()
endfunc
func Test_pipe_both_to_buffer()
- if !has('job')
- return
- endif
- call ch_log('Test_pipe_both_to_buffer()')
let job = job_start(s:python . " test_channel_pipe.py",
\ {'out_io': 'buffer', 'out_name': 'pipe-err', 'err_io': 'out'})
call assert_equal("run", job_status(job))
@@ -913,11 +824,6 @@ func Test_pipe_both_to_buffer()
endfunc
func Run_test_pipe_from_buffer(use_name)
- if !has('job')
- return
- endif
- call ch_log('Test_pipe_from_buffer()')
-
sp pipe-input
call setline(1, ['echo one', 'echo two', 'echo three'])
let options = {'in_io': 'buffer', 'block_write': 1}
@@ -949,8 +855,8 @@ func Test_pipe_from_buffer_nr()
endfunc
func Run_pipe_through_sort(all, use_buffer)
- if !executable('sort') || !has('job')
- return
+ if !executable('sort')
+ throw 'Skipped: sort program not found'
endif
let options = {'out_io': 'buffer', 'out_name': 'sortout'}
if a:use_buffer
@@ -1005,10 +911,6 @@ func Test_pipe_through_sort_feed()
endfunc
func Test_pipe_to_nameless_buffer()
- if !has('job')
- return
- endif
- call ch_log('Test_pipe_to_nameless_buffer()')
let job = job_start(s:python . " test_channel_pipe.py",
\ {'out_io': 'buffer'})
call assert_equal("run", job_status(job))
@@ -1026,10 +928,6 @@ func Test_pipe_to_nameless_buffer()
endfunc
func Test_pipe_to_buffer_json()
- if !has('job')
- return
- endif
- call ch_log('Test_pipe_to_buffer_json()')
let job = job_start(s:python . " test_channel_pipe.py",
\ {'out_io': 'buffer', 'out_mode': 'json'})
call assert_equal("run", job_status(job))
@@ -1057,11 +955,6 @@ func s:wait_for_last_line(line, offset)
endfunc
func Test_pipe_io_two_buffers()
- if !has('job')
- return
- endif
- call ch_log('Test_pipe_io_two_buffers()')
-
" Create two buffers, one to read from and one to write to.
split pipe-output
set buftype=nofile
@@ -1095,11 +988,6 @@ func Test_pipe_io_two_buffers()
endfunc
func Test_pipe_io_one_buffer()
- if !has('job')
- return
- endif
- call ch_log('Test_pipe_io_one_buffer()')
-
" Create one buffer to read from and to write to.
split pipe-io
set buftype=nofile
@@ -1126,7 +1014,6 @@ func Test_pipe_io_one_buffer()
endfunc
func Test_write_to_buffer_and_scroll()
- CheckFeature job
if !CanRunVimInTerminal()
throw 'Skipped: cannot make screendumps'
endif
@@ -1146,7 +1033,7 @@ func Test_write_to_buffer_and_scroll()
END
call writefile(lines, 'XtestBufferScroll')
let buf = RunVimInTerminal('-S XtestBufferScroll', #{rows: 10})
- sleep 500m
+ call term_wait(buf, 100)
call VerifyScreenDump(buf, 'Test_job_buffer_scroll_1', {})
" clean up
@@ -1155,11 +1042,6 @@ func Test_write_to_buffer_and_scroll()
endfunc
func Test_pipe_null()
- if !has('job')
- return
- endif
- call ch_log('Test_pipe_null()')
-
" We cannot check that no I/O works, we only check that the job starts
" properly.
let job = job_start(s:python . " test_channel_pipe.py something",
@@ -1203,10 +1085,6 @@ func Test_pipe_null()
endfunc
func Test_pipe_to_buffer_raw()
- if !has('job')
- return
- endif
- call ch_log('Test_raw_pipe_to_buffer()')
let options = {'out_mode': 'raw', 'out_io': 'buffer', 'out_name': 'testout'}
split testout
let job = job_start([s:python, '-c',
@@ -1228,11 +1106,6 @@ func Test_pipe_to_buffer_raw()
endfunc
func Test_reuse_channel()
- if !has('job')
- return
- endif
- call ch_log('Test_reuse_channel()')
-
let job = job_start(s:python . " test_channel_pipe.py")
call assert_equal("run", job_status(job))
let handle = job_getchannel(job)
@@ -1255,11 +1128,6 @@ func Test_reuse_channel()
endfunc
func Test_out_cb()
- if !has('job')
- return
- endif
- call ch_log('Test_out_cb()')
-
let dict = {'thisis': 'dict: '}
func dict.outHandler(chan, msg) dict
if type(a:msg) == v:t_string
@@ -1296,11 +1164,6 @@ func Test_out_cb()
endfunc
func Test_out_close_cb()
- if !has('job')
- return
- endif
- call ch_log('Test_out_close_cb()')
-
let s:counter = 1
let g:Ch_msg1 = ''
let g:Ch_closemsg = 0
@@ -1330,11 +1193,6 @@ func Test_out_close_cb()
endfunc
func Test_read_in_close_cb()
- if !has('job')
- return
- endif
- call ch_log('Test_read_in_close_cb()')
-
let g:Ch_received = ''
func! CloseHandler(chan)
let g:Ch_received = ch_read(a:chan)
@@ -1353,11 +1211,6 @@ endfunc
" Use channel in NL mode but received text does not end in NL.
func Test_read_in_close_cb_incomplete()
- if !has('job')
- return
- endif
- call ch_log('Test_read_in_close_cb_incomplete()')
-
let g:Ch_received = ''
func! CloseHandler(chan)
while ch_status(a:chan, {'part': 'out'}) == 'buffered'
@@ -1377,11 +1230,6 @@ func Test_read_in_close_cb_incomplete()
endfunc
func Test_out_cb_lambda()
- if !has('job')
- return
- endif
- call ch_log('Test_out_cb_lambda()')
-
let job = job_start(s:python . " test_channel_pipe.py",
\ {'out_cb': {ch, msg -> execute("let g:Ch_outmsg = 'lambda: ' . msg")},
\ 'out_mode': 'json',
@@ -1401,11 +1249,6 @@ func Test_out_cb_lambda()
endfunc
func Test_close_and_exit_cb()
- if !has('job')
- return
- endif
- call ch_log('Test_close_and_exit_cb')
-
let g:retdict = {'ret': {}}
func g:retdict.close_cb(ch) dict
let self.ret['close_cb'] = job_status(ch_getjob(a:ch))
@@ -1561,24 +1404,21 @@ function Ch_test_exit_callback(port)
endfunc
func Test_exit_callback()
- if has('job')
- call ch_log('Test_exit_callback()')
- call s:run_server('Ch_test_exit_callback')
-
- " wait up to a second for the job to exit
- for i in range(100)
- if g:Ch_job_exit_ret == 'done'
- break
- endif
- sleep 10m
- " calling job_status() triggers the callback
- call job_status(g:Ch_exit_job)
- endfor
+ call s:run_server('Ch_test_exit_callback')
- call assert_equal('done', g:Ch_job_exit_ret)
- call assert_equal('dead', job_info(g:Ch_exit_job).status)
- unlet g:Ch_exit_job
- endif
+ " wait up to a second for the job to exit
+ for i in range(100)
+ if g:Ch_job_exit_ret == 'done'
+ break
+ endif
+ sleep 10m
+ " calling job_status() triggers the callback
+ call job_status(g:Ch_exit_job)
+ endfor
+
+ call assert_equal('done', g:Ch_job_exit_ret)
+ call assert_equal('dead', job_info(g:Ch_exit_job).status)
+ unlet g:Ch_exit_job
endfunc
function MyExitTimeCb(job, status)
@@ -1589,10 +1429,6 @@ function MyExitTimeCb(job, status)
endfunction
func Test_exit_callback_interval()
- if !has('job')
- return
- endif
-
let g:exit_cb_val = {'start': reltime(), 'end': 0, 'process': 0}
let job = job_start([s:python, '-c', 'import time;time.sleep(0.5)'], {'exit_cb': 'MyExitTimeCb'})
let g:exit_cb_val.process = job_info(job).process
@@ -1671,10 +1507,6 @@ func Test_job_start_invalid()
endfunc
func Test_job_stop_immediately()
- if !has('job')
- return
- endif
-
let g:job = job_start([s:python, '-c', 'import time;time.sleep(10)'])
try
call job_stop(g:job)
@@ -1704,8 +1536,8 @@ func Test_using_freed_memory()
endfunc
func Test_collapse_buffers()
- if !executable('cat') || !has('job')
- return
+ if !executable('cat')
+ throw 'Skipped: cat program not found'
endif
sp test_channel.vim
let g:linecount = line('$')
@@ -1718,8 +1550,8 @@ func Test_collapse_buffers()
endfunc
func Test_write_to_deleted_buffer()
- if !executable('echo') || !has('job')
- return
+ if !executable('echo')
+ throw 'Skipped: echo program not found'
endif
let job = job_start('echo hello', {'out_io': 'buffer', 'out_name': 'test_buffer', 'out_msg': 0})
let bufnr = bufnr('test_buffer')
@@ -1753,8 +1585,8 @@ func Test_cmd_parsing()
endfunc
func Test_raw_passes_nul()
- if !executable('cat') || !has('job')
- return
+ if !executable('cat')
+ throw 'Skipped: cat program not found'
endif
" Test lines from the job containing NUL are stored correctly in a buffer.
@@ -1790,10 +1622,6 @@ func Test_raw_passes_nul()
endfunc
func Test_read_nonl_line()
- if !has('job')
- return
- endif
-
let g:linecount = 0
let arg = 'import sys;sys.stdout.write("1\n2\n3")'
call job_start([s:python, '-c', arg], {'callback': {-> execute('let g:linecount += 1')}})
@@ -1802,10 +1630,6 @@ func Test_read_nonl_line()
endfunc
func Test_read_nonl_in_close_cb()
- if !has('job')
- return
- endif
-
func s:close_cb(ch)
while ch_status(a:ch) == 'buffered'
let g:out .= ch_read(a:ch)
@@ -1821,10 +1645,6 @@ func Test_read_nonl_in_close_cb()
endfunc
func Test_read_from_terminated_job()
- if !has('job')
- return
- endif
-
let g:linecount = 0
let arg = 'import os,sys;os.close(1);sys.stderr.write("test\n")'
call job_start([s:python, '-c', arg], {'callback': {-> execute('let g:linecount += 1')}})
@@ -1833,7 +1653,6 @@ func Test_read_from_terminated_job()
endfunc
func Test_job_start_windows()
- CheckFeature job
CheckMSWindows
" Check that backslash in $COMSPEC is handled properly.
@@ -1848,8 +1667,6 @@ func Test_job_start_windows()
endfunc
func Test_env()
- CheckFeature job
-
let g:envstr = ''
if has('win32')
let cmd = ['cmd', '/c', 'echo %FOO%']
@@ -1863,8 +1680,6 @@ func Test_env()
endfunc
func Test_cwd()
- CheckFeature job
-
let g:envstr = ''
if has('win32')
let expect = $TEMP
@@ -1925,8 +1740,6 @@ func s:test_list_args(cmd, out, remove_lf)
endfunc
func Test_list_args()
- CheckFeature job
-
call s:test_list_args('import sys;sys.stdout.write("hello world")', "hello world", 0)
call s:test_list_args('import sys;sys.stdout.write("hello\nworld")', "hello\nworld", 0)
call s:test_list_args('import sys;sys.stdout.write(''hello\nworld'')', "hello\nworld", 0)
@@ -1953,18 +1766,6 @@ func Test_list_args()
call s:test_list_args('print("hello\tworld")', "hello\tworld", 1)
endfunc
-" Do this last, it stops any channel log.
-func Test_zz_ch_log()
- call ch_logfile('Xlog', 'w')
- call ch_log('hello there')
- call ch_log('%s%s')
- call ch_logfile('')
- let text = readfile('Xlog')
- call assert_match("hello there", text[1])
- call assert_match("%s%s", text[2])
- call delete('Xlog')
-endfunc
-
func Test_keep_pty_open()
if !has('unix')
return
@@ -1978,7 +1779,6 @@ func Test_keep_pty_open()
endfunc
func Test_job_start_in_timer()
- CheckFeature job
CheckFeature timers
func OutCb(chan, msg)
@@ -2038,7 +1838,6 @@ func Test_raw_large_data()
endfunc
func Test_no_hang_windows()
- CheckFeature job
CheckMSWindows
try
@@ -2075,7 +1874,6 @@ func Test_job_exitval_and_termsig()
endfunc
func Test_job_tty_in_out()
- CheckFeature job
CheckUnix
call writefile(['test'], 'Xtestin')
@@ -2124,3 +1922,61 @@ func Test_job_tty_in_out()
call delete('Xtestout')
call delete('Xtesterr')
endfunc
+
+" Do this last, it stops any channel log.
+func Test_zz_nl_err_to_out_pipe()
+ call ch_logfile('Xlog')
+ call ch_log('Test_zz_nl_err_to_out_pipe()')
+ let job = job_start(s:python . " test_channel_pipe.py", {'err_io': 'out'})
+ call assert_equal("run", job_status(job))
+ try
+ let handle = job_getchannel(job)
+ call ch_sendraw(handle, "echo something\n")
+ call assert_equal("something", ch_readraw(handle))
+
+ call ch_sendraw(handle, "echoerr wrong\n")
+ call assert_equal("wrong", ch_readraw(handle))
+ finally
+ call job_stop(job)
+ call ch_logfile('')
+ let loglines = readfile('Xlog')
+ call assert_true(len(loglines) > 10)
+ let found_test = 0
+ let found_send = 0
+ let found_recv = 0
+ let found_stop = 0
+ for l in loglines
+ if l =~ 'Test_zz_nl_err_to_out_pipe'
+ let found_test = 1
+ endif
+ if l =~ 'SEND on.*echo something'
+ let found_send = 1
+ endif
+ if l =~ 'RECV on.*something'
+ let found_recv = 1
+ endif
+ if l =~ 'Stopping job with'
+ let found_stop = 1
+ endif
+ endfor
+ call assert_equal(1, found_test)
+ call assert_equal(1, found_send)
+ call assert_equal(1, found_recv)
+ call assert_equal(1, found_stop)
+ " On MS-Windows need to sleep for a moment to be able to delete the file.
+ sleep 10m
+ call delete('Xlog')
+ endtry
+endfunc
+
+" Do this last, it stops any channel log.
+func Test_zz_ch_log()
+ call ch_logfile('Xlog', 'w')
+ call ch_log('hello there')
+ call ch_log('%s%s')
+ call ch_logfile('')
+ let text = readfile('Xlog')
+ call assert_match("hello there", text[1])
+ call assert_match("%s%s", text[2])
+ call delete('Xlog')
+endfunc
diff --git a/src/version.c b/src/version.c
index 5b025117a9..281e7e28dd 100644
--- a/src/version.c
+++ b/src/version.c
@@ -778,6 +778,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1777,
+/**/
1776,
/**/
1775,