blob: 85da94c4188869c82d11ec5deaa31a85269368a9 [file] [log] [blame]
Bram Moolenaar8c62a082019-02-08 14:34:10 +01001" Test for "rvim" or "vim -Z"
2
3source shared.vim
4
Bram Moolenaar18c56322019-02-09 11:13:12 +01005if has('win32') && has('gui')
6 " Win32 GUI shows a dialog instead of displaying the error in the last line.
7 finish
8endif
9
Bram Moolenaar8c62a082019-02-08 14:34:10 +010010func Test_restricted()
11 let cmd = GetVimCommand('Xrestricted')
12 if cmd == ''
13 return
14 endif
15
16 call writefile([
17 \ "silent !ls",
18 \ "call writefile([v:errmsg], 'Xrestrout')",
19 \ "qa!",
20 \ ], 'Xrestricted')
21 call system(cmd . ' -Z')
22 call assert_match('E145:', join(readfile('Xrestrout')))
23
24 call delete('Xrestricted')
25 call delete('Xrestrout')
26endfunc
27
28func Run_restricted_test(ex_cmd, error)
29 let cmd = GetVimCommand('Xrestricted')
30 if cmd == ''
31 return
32 endif
33
34 call writefile([
35 \ a:ex_cmd,
36 \ "call writefile([v:errmsg], 'Xrestrout')",
37 \ "qa!",
38 \ ], 'Xrestricted')
39 call system(cmd . ' -Z')
40 call assert_match(a:error, join(readfile('Xrestrout')))
41
42 call delete('Xrestricted')
43 call delete('Xrestrout')
44endfunc
45
46func Test_restricted_lua()
47 if !has('lua')
48 throw 'Skipped: Lua is not supported'
49 endif
50 call Run_restricted_test('lua print("Hello, Vim!")', 'E981:')
51 call Run_restricted_test('luado return "hello"', 'E981:')
52 call Run_restricted_test('luafile somefile', 'E981:')
53 call Run_restricted_test('call luaeval("expression")', 'E145:')
54endfunc
55
56func Test_restricted_mzscheme()
57 if !has('mzscheme')
58 throw 'Skipped: MzScheme is not supported'
59 endif
60 call Run_restricted_test('mzscheme statement', 'E981:')
61 call Run_restricted_test('mzfile somefile', 'E981:')
62 call Run_restricted_test('call mzeval("expression")', 'E145:')
63endfunc
64
65func Test_restricted_perl()
66 if !has('perl')
67 throw 'Skipped: Perl is not supported'
68 endif
69 " TODO: how to make Safe mode fail?
70 " call Run_restricted_test('perl system("ls")', 'E981:')
71 " call Run_restricted_test('perldo system("hello")', 'E981:')
72 " call Run_restricted_test('perlfile somefile', 'E981:')
73 " call Run_restricted_test('call perleval("system(\"ls\")")', 'E145:')
74endfunc
75
76func Test_restricted_python()
77 if !has('python')
78 throw 'Skipped: Python is not supported'
79 endif
80 call Run_restricted_test('python print "hello"', 'E981:')
81 call Run_restricted_test('pydo return "hello"', 'E981:')
82 call Run_restricted_test('pyfile somefile', 'E981:')
83 call Run_restricted_test('call pyeval("expression")', 'E145:')
84endfunc
85
86func Test_restricted_python3()
87 if !has('python3')
88 throw 'Skipped: Python3 is not supported'
89 endif
90 call Run_restricted_test('py3 print "hello"', 'E981:')
91 call Run_restricted_test('py3do return "hello"', 'E981:')
92 call Run_restricted_test('py3file somefile', 'E981:')
93 call Run_restricted_test('call py3eval("expression")', 'E145:')
94endfunc
95
96func Test_restricted_ruby()
97 if !has('ruby')
98 throw 'Skipped: Ruby is not supported'
99 endif
100 call Run_restricted_test('ruby print "Hello"', 'E981:')
101 call Run_restricted_test('rubydo print "Hello"', 'E981:')
102 call Run_restricted_test('rubyfile somefile', 'E981:')
103endfunc
104
105func Test_restricted_tcl()
106 if !has('tcl')
107 throw 'Skipped: Tcl is not supported'
108 endif
109 call Run_restricted_test('tcl puts "Hello"', 'E981:')
110 call Run_restricted_test('tcldo puts "Hello"', 'E981:')
111 call Run_restricted_test('tclfile somefile', 'E981:')
112endfunc