blob: dd07e4a62b51ffcb3f9535e4873019f1ca591be5 [file] [log] [blame]
Bram Moolenaar79815f12016-07-09 17:07:29 +02001" test execute()
2
3func NestedEval()
4 let nested = execute('echo "nested\nlines"')
5 echo 'got: "' . nested . '"'
6endfunc
7
8func NestedRedir()
9 redir => var
10 echo 'broken'
11 redir END
12endfunc
13
14func Test_execute_string()
15 call assert_equal("\nnocompatible", execute('set compatible?'))
16 call assert_equal("\nsomething\nnice", execute('echo "something\nnice"'))
17 call assert_equal("noendofline", execute('echon "noendofline"'))
18 call assert_equal("", execute(123))
19
20 call assert_equal("\ngot: \"\nnested\nlines\"", execute('call NestedEval()'))
21 redir => redired
22 echo 'this'
23 let evaled = execute('echo "that"')
24 echo 'theend'
25 redir END
26 call assert_equal("\nthis\ntheend", redired)
27 call assert_equal("\nthat", evaled)
28
29 call assert_fails('call execute("doesnotexist")', 'E492:')
30 call assert_fails('call execute(3.4)', 'E806:')
31 call assert_fails('call execute("call NestedRedir()")', 'E930:')
32
33 call assert_equal("\nsomething", execute('echo "something"', ''))
34 call assert_equal("\nsomething", execute('echo "something"', 'silent'))
35 call assert_equal("\nsomething", execute('echo "something"', 'silent!'))
36 call assert_equal("", execute('burp', 'silent!'))
37 call assert_fails('call execute("echo \"x\"", 3.4)', 'E806:')
38
39 call assert_equal("", execute(test_null_string()))
40endfunc
41
42func Test_execute_list()
43 call assert_equal("\nsomething\nnice", execute(['echo "something"', 'echo "nice"']))
44 let l = ['for n in range(0, 3)',
45 \ 'echo n',
46 \ 'endfor']
47 call assert_equal("\n0\n1\n2\n3", execute(l))
48
49 call assert_equal("", execute([]))
50 call assert_equal("", execute(test_null_list()))
51endfunc