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_mode() 11 let lines =<< trim END 12 if has('lua') 13 call assert_fails('lua print("Hello, Vim!")', 'E981:') 14 call assert_fails('luado return "hello"', 'E981:') 15 call assert_fails('luafile somefile', 'E981:') 16 call assert_fails('call luaeval("expression")', 'E145:') 17 endif 18 19 if has('mzscheme') 20 call assert_fails('mzscheme statement', 'E981:') 21 call assert_fails('mzfile somefile', 'E981:') 22 call assert_fails('call mzeval("expression")', 'E145:') 23 endif 24 25 if has('perl') 26 " TODO: how to make Safe mode fail? 27 " call assert_fails('perl system("ls")', 'E981:') 28 " call assert_fails('perldo system("hello")', 'E981:') 29 " call assert_fails('perlfile somefile', 'E981:') 30 " call assert_fails('call perleval("system(\"ls\")")', 'E145:') 31 endif 32 33 if has('python') 34 call assert_fails('python print "hello"', 'E981:') 35 call assert_fails('pydo return "hello"', 'E981:') 36 call assert_fails('pyfile somefile', 'E981:') 37 call assert_fails('call pyeval("expression")', 'E145:') 38 endif 39 40 if has('python3') 41 call assert_fails('py3 print "hello"', 'E981:') 42 call assert_fails('py3do return "hello"', 'E981:') 43 call assert_fails('py3file somefile', 'E981:') 44 call assert_fails('call py3eval("expression")', 'E145:') 45 endif 46 47 if has('ruby') 48 call assert_fails('ruby print "Hello"', 'E981:') 49 call assert_fails('rubydo print "Hello"', 'E981:') 50 call assert_fails('rubyfile somefile', 'E981:') 51 endif 52 53 if has('tcl') 54 call assert_fails('tcl puts "Hello"', 'E981:') 55 call assert_fails('tcldo puts "Hello"', 'E981:') 56 call assert_fails('tclfile somefile', 'E981:') 57 endif 58 59 if has('clientserver') 60 call assert_fails('let s=remote_peek(10)', 'E145:') 61 call assert_fails('let s=remote_read(10)', 'E145:') 62 call assert_fails('let s=remote_send("vim", "abc")', 'E145:') 63 call assert_fails('let s=server2client(10, "abc")', 'E145:') 64 endif 65 66 if has('terminal') 67 call assert_fails('terminal', 'E145:') 68 call assert_fails('call term_start("vim")', 'E145:') 69 call assert_fails('call term_dumpwrite(1, "Xfile")', 'E145:') 70 endif 71 72 if has('channel') 73 call assert_fails("call ch_logfile('Xlog')", 'E145:') 74 call assert_fails("call ch_open('localhost:8765')", 'E145:') 75 endif 76 77 if has('job') 78 call assert_fails("call job_start('vim')", 'E145:') 79 endif 80 81 if has('unix') && has('libcall') 82 call assert_fails("echo libcall('libc.so', 'getenv', 'HOME')", 'E145:') 83 endif 84 call assert_fails("call rename('a', 'b')", 'E145:') 85 call assert_fails("call delete('Xfile')", 'E145:') 86 call assert_fails("call mkdir('Xdir')", 'E145:') 87 call assert_fails('!ls', 'E145:') 88 call assert_fails('shell', 'E145:') 89 call assert_fails('stop', 'E145:') 90 call assert_fails('exe "normal \<C-Z>"', 'E145:') 91 set insertmode 92 call assert_fails('call feedkeys("\<C-Z>", "xt")', 'E145:') 93 set insertmode& 94 call assert_fails('suspend', 'E145:') 95 call assert_fails('call system("ls")', 'E145:') 96 call assert_fails('call systemlist("ls")', 'E145:') 97 if has('unix') 98 call assert_fails('cd `pwd`', 'E145:') 99 endif 100 101 call writefile(v:errors, 'Xresult') 102 qa! 103 END 104 call writefile(lines, 'Xrestricted') 105 if RunVim([], [], '-Z --clean -S Xrestricted') 106 call assert_equal([], readfile('Xresult')) 107 endif 108 109 call delete('Xrestricted') 110 call delete('Xresult') 111endfunc 112 113" vim: shiftwidth=2 sts=2 expandtab 114