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