1" Test for "rvim" or "vim -Z" 2 3source shared.vim 4 5"if has('win32') && has('gui') 6" " Win32 GUI shows a dialog instead of displaying the error in the last line. 7" finish 8"endif 9 10func Test_restricted() 11 call Run_restricted_test('!ls', 'E145:') 12endfunc 13 14func Run_restricted_test(ex_cmd, error) 15 let cmd = GetVimCommand('Xrestricted') 16 if cmd == '' 17 return 18 endif 19 20 " Use a VimEnter autocommand to avoid that the error message is displayed in 21 " a dialog with an OK button. 22 call writefile([ 23 \ "func Init()", 24 \ " silent! " . a:ex_cmd, 25 \ " call writefile([v:errmsg], 'Xrestrout')", 26 \ " qa!", 27 \ "endfunc", 28 \ "au VimEnter * call Init()", 29 \ ], '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 104