blob: be00d180c4046ac285c738f7030499f67f0e2a4c [file] [log] [blame]
Bram Moolenaar12c44922017-01-08 13:26:03 +01001" Tests for system() and systemlist()
2
3function! Test_System()
4 if !executable('echo') || !executable('cat') || !executable('wc')
5 return
6 endif
Bram Moolenaar9d9c3562017-01-08 13:55:06 +01007 let out = system('echo 123')
8 " On Windows we may get a trailing space.
9 if out != "123 \n"
10 call assert_equal("123\n", out)
11 endif
12
13 let out = systemlist('echo 123')
14 " On Windows we may get a trailing space and CR.
15 if out != ["123 \r"]
16 call assert_equal(['123'], out)
17 endif
18
Bram Moolenaar12c44922017-01-08 13:26:03 +010019 call assert_equal('123', system('cat', '123'))
20 call assert_equal(['123'], systemlist('cat', '123'))
21 call assert_equal(["as\<NL>df"], systemlist('cat', ["as\<NL>df"]))
22 new Xdummy
23 call setline(1, ['asdf', "pw\<NL>er", 'xxxx'])
24 call assert_equal("3\n", system('wc -l', bufnr('%')))
Bram Moolenaar9d9c3562017-01-08 13:55:06 +010025
26 let out = systemlist('wc -l', bufnr('%'))
27 " On Windows we may get a trailing CR.
28 if out != ["3\r"]
29 call assert_equal(['3'], out)
30 endif
31
32 let out = systemlist('cat', bufnr('%'))
33 " On Windows we may get a trailing CR.
34 if out != ["asdf\r", "pw\<NL>er\r", "xxxx\r"]
35 call assert_equal(['asdf', "pw\<NL>er", 'xxxx'], out)
36 endif
Bram Moolenaar12c44922017-01-08 13:26:03 +010037 bwipe!
38
39 call assert_fails('call system("wc -l", 99999)', 'E86:')
40endfunction