1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
" Tests for system() and systemlist()
func Test_System()
if !executable('echo') || !executable('cat') || !executable('wc')
return
endif
let out = system('echo 123')
" On Windows we may get a trailing space.
if out != "123 \n"
call assert_equal("123\n", out)
endif
let out = systemlist('echo 123')
" On Windows we may get a trailing space and CR.
if out != ["123 \r"]
call assert_equal(['123'], out)
endif
call assert_equal('123', system('cat', '123'))
call assert_equal(['123'], systemlist('cat', '123'))
call assert_equal(["as\<NL>df"], systemlist('cat', ["as\<NL>df"]))
new Xdummy
call setline(1, ['asdf', "pw\<NL>er", 'xxxx'])
let out = system('wc -l', bufnr('%'))
" On OS/X we get leading spaces
let out = substitute(out, '^ *', '', '')
call assert_equal("3\n", out)
let out = systemlist('wc -l', bufnr('%'))
" On Windows we may get a trailing CR.
if out != ["3\r"]
" On OS/X we get leading spaces
if type(out) == v:t_list
let out[0] = substitute(out[0], '^ *', '', '')
endif
call assert_equal(['3'], out)
endif
let out = systemlist('cat', bufnr('%'))
" On Windows we may get a trailing CR.
if out != ["asdf\r", "pw\<NL>er\r", "xxxx\r"]
call assert_equal(['asdf', "pw\<NL>er", 'xxxx'], out)
endif
bwipe!
call assert_fails('call system("wc -l", 99999)', 'E86:')
endfunc
func Test_system_exmode()
if has('unix') " echo $? only works on Unix
let cmd = ' -es -u NONE -c "source Xscript" +q; echo "result=$?"'
" Need to put this in a script, "catch" isn't found after an unknown
" function.
call writefile(['try', 'call doesnotexist()', 'catch', 'endtry'], 'Xscript')
let a = system(v:progpath . cmd)
call assert_match('result=0', a)
call assert_equal(0, v:shell_error)
endif
" Error before try does set error flag.
call writefile(['call nosuchfunction()', 'try', 'call doesnotexist()', 'catch', 'endtry'], 'Xscript')
if has('unix') " echo $? only works on Unix
let a = system(v:progpath . cmd)
call assert_notequal('0', a[0])
endif
let cmd = ' -es -u NONE -c "source Xscript" +q'
let a = system(v:progpath . cmd)
call assert_notequal(0, v:shell_error)
call delete('Xscript')
if has('unix') " echo $? only works on Unix
let cmd = ' -es -u NONE -c "call doesnotexist()" +q; echo $?'
let a = system(v:progpath. cmd)
call assert_notequal(0, a[0])
endif
let cmd = ' -es -u NONE -c "call doesnotexist()" +q'
let a = system(v:progpath. cmd)
call assert_notequal(0, v:shell_error)
if has('unix') " echo $? only works on Unix
let cmd = ' -es -u NONE -c "call doesnotexist()|let a=1" +q; echo $?'
let a = system(v:progpath. cmd)
call assert_notequal(0, a[0])
endif
let cmd = ' -es -u NONE -c "call doesnotexist()|let a=1" +q'
let a = system(v:progpath. cmd)
call assert_notequal(0, v:shell_error)
endfunc
|