summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_channel.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-08-13 17:13:09 +0200
committerBram Moolenaar <Bram@vim.org>2017-08-13 17:13:09 +0200
commitdcaa61384ca76e42f7feda5640fb85b58cee03e5 (patch)
tree21eb8c92bc31eae5fe4d51c6f19bed1c05f01eb9 /src/testdir/test_channel.vim
parent274a52fd58bbd88f5fe8b96d87abe3574c8169af (diff)
patch 8.0.0928: MS-Windows: passing arglist to job has escaping problemsv8.0.0928
Problem: MS-Windows: passing arglist to job has escaping problems. Solution: Improve escaping. (Yasuhiro Matsumoto, closes #1954)
Diffstat (limited to 'src/testdir/test_channel.vim')
-rw-r--r--src/testdir/test_channel.vim92
1 files changed, 65 insertions, 27 deletions
diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim
index 42f0810ee3..951f9a3baf 100644
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -1636,12 +1636,7 @@ func Test_read_nonl_line()
endif
let g:linecount = 0
- if has('win32')
- " workaround: 'shellescape' does improper escaping double quotes
- let arg = 'import sys;sys.stdout.write(\"1\n2\n3\")'
- else
- let arg = 'import sys;sys.stdout.write("1\n2\n3")'
- endif
+ let arg = 'import sys;sys.stdout.write("1\n2\n3")'
call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'})
call WaitFor('3 <= g:linecount')
call assert_equal(3, g:linecount)
@@ -1653,12 +1648,7 @@ func Test_read_from_terminated_job()
endif
let g:linecount = 0
- if has('win32')
- " workaround: 'shellescape' does improper escaping double quotes
- let arg = 'import os,sys;os.close(1);sys.stderr.write(\"test\n\")'
- else
- let arg = 'import os,sys;os.close(1);sys.stderr.write("test\n")'
- endif
+ let arg = 'import os,sys;os.close(1);sys.stderr.write("test\n")'
call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'})
call WaitFor('1 <= g:linecount')
call assert_equal(1, g:linecount)
@@ -1669,15 +1659,15 @@ func Test_env()
return
endif
- let s:envstr = ''
+ let g:envstr = ''
if has('win32')
- call job_start(['cmd', '/c', 'echo %FOO%'], {'callback': {ch,msg->execute(":let s:envstr .= msg")}, 'env':{'FOO': 'bar'}})
+ call job_start(['cmd', '/c', 'echo %FOO%'], {'callback': {ch,msg->execute(":let g:envstr .= msg")}, 'env':{'FOO': 'bar'}})
else
- call job_start([&shell, &shellcmdflag, 'echo $FOO'], {'callback': {ch,msg->execute(":let s:envstr .= msg")}, 'env':{'FOO': 'bar'}})
+ call job_start([&shell, &shellcmdflag, 'echo $FOO'], {'callback': {ch,msg->execute(":let g:envstr .= msg")}, 'env':{'FOO': 'bar'}})
endif
- call WaitFor('"" != s:envstr')
- call assert_equal("bar", s:envstr)
- unlet s:envstr
+ call WaitFor('"" != g:envstr')
+ call assert_equal("bar", g:envstr)
+ unlet g:envstr
endfunc
func Test_cwd()
@@ -1685,22 +1675,22 @@ func Test_cwd()
return
endif
- let s:envstr = ''
+ let g:envstr = ''
if has('win32')
let expect = $TEMP
- call job_start(['cmd', '/c', 'echo %CD%'], {'callback': {ch,msg->execute(":let s:envstr .= msg")}, 'cwd': expect})
+ call job_start(['cmd', '/c', 'echo %CD%'], {'callback': {ch,msg->execute(":let g:envstr .= msg")}, 'cwd': expect})
else
let expect = $HOME
- call job_start(['pwd'], {'callback': {ch,msg->execute(":let s:envstr .= msg")}, 'cwd': expect})
+ call job_start(['pwd'], {'callback': {ch,msg->execute(":let g:envstr .= msg")}, 'cwd': expect})
endif
- call WaitFor('"" != s:envstr')
+ call WaitFor('"" != g:envstr')
let expect = substitute(expect, '[/\\]$', '', '')
- let s:envstr = substitute(s:envstr, '[/\\]$', '', '')
- if $CI != '' && stridx(s:envstr, '/private/') == 0
- let s:envstr = s:envstr[8:]
+ let g:envstr = substitute(g:envstr, '[/\\]$', '', '')
+ if $CI != '' && stridx(g:envstr, '/private/') == 0
+ let g:envstr = g:envstr[8:]
endif
- call assert_equal(expect, s:envstr)
- unlet s:envstr
+ call assert_equal(expect, g:envstr)
+ unlet g:envstr
endfunc
function Ch_test_close_lambda(port)
@@ -1721,3 +1711,51 @@ func Test_close_lambda()
call ch_log('Test_close_lambda()')
call s:run_server('Ch_test_close_lambda')
endfunc
+
+func s:test_list_args(cmd, out, remove_lf)
+ try
+ let g:out = ''
+ call job_start([s:python, '-c', a:cmd], {'callback': {ch, msg -> execute('let g:out .= msg')}, 'out_mode': 'raw'})
+ call WaitFor('"" != g:out')
+ if has('win32')
+ let g:out = substitute(g:out, '\r', '', 'g')
+ endif
+ if a:remove_lf
+ let g:out = substitute(g:out, '\n$', '', 'g')
+ endif
+ call assert_equal(a:out, g:out)
+ finally
+ unlet g:out
+ endtry
+endfunc
+
+func Test_list_args()
+ if !has('job')
+ return
+ endif
+
+ 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)
+ 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^world'')', "hello^world", 0)
+ 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\\world'')', "hello\\world", 0)
+ 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\"world\"")', 'hello"world"', 0)
+ call s:test_list_args('import sys;sys.stdout.write("h\"ello worl\"d")', 'h"ello worl"d', 0)
+ call s:test_list_args('import sys;sys.stdout.write("h\"e\\\"llo wor\\\"l\"d")', 'h"e\"llo wor\"l"d', 0)
+ call s:test_list_args('import sys;sys.stdout.write("h\"e\\\"llo world")', 'h"e\"llo world', 0)
+ call s:test_list_args('import sys;sys.stdout.write("hello\tworld")', "hello\tworld", 0)
+
+ " tests which not contain spaces in the argument
+ call s:test_list_args('print("hello\nworld")', "hello\nworld", 1)
+ call s:test_list_args('print(''hello\nworld'')', "hello\nworld", 1)
+ call s:test_list_args('print(''hello"world'')', "hello\"world", 1)
+ call s:test_list_args('print(''hello^world'')', "hello^world", 1)
+ call s:test_list_args('print("hello&&world")', "hello&&world", 1)
+ call s:test_list_args('print(''hello\\world'')', "hello\\world", 1)
+ call s:test_list_args('print(''hello\\\\world'')', "hello\\\\world", 1)
+ call s:test_list_args('print("hello\"world\"")', 'hello"world"', 1)
+ call s:test_list_args('print("hello\tworld")', "hello\tworld", 1)
+endfunc