Bram Moolenaar | 8c62a08 | 2019-02-08 14:34:10 +0100 | [diff] [blame] | 1 | " Test for "rvim" or "vim -Z" |
| 2 | |
| 3 | source shared.vim |
| 4 | |
Bram Moolenaar | 5a66981 | 2019-02-11 21:45:00 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | 18c5632 | 2019-02-09 11:13:12 +0100 | [diff] [blame] | 9 | |
Bram Moolenaar | 8c62a08 | 2019-02-08 14:34:10 +0100 | [diff] [blame] | 10 | func Test_restricted() |
Bram Moolenaar | 5a66981 | 2019-02-11 21:45:00 +0100 | [diff] [blame] | 11 | call Run_restricted_test('!ls', 'E145:') |
Bram Moolenaar | 8c62a08 | 2019-02-08 14:34:10 +0100 | [diff] [blame] | 12 | endfunc |
| 13 | |
| 14 | func Run_restricted_test(ex_cmd, error) |
| 15 | let cmd = GetVimCommand('Xrestricted') |
| 16 | if cmd == '' |
| 17 | return |
| 18 | endif |
| 19 | |
Bram Moolenaar | 5a66981 | 2019-02-11 21:45:00 +0100 | [diff] [blame] | 20 | " Use a VimEnter autocommand to avoid that the error message is displayed in |
| 21 | " a dialog with an OK button. |
Bram Moolenaar | 8c62a08 | 2019-02-08 14:34:10 +0100 | [diff] [blame] | 22 | call writefile([ |
Bram Moolenaar | 5a66981 | 2019-02-11 21:45:00 +0100 | [diff] [blame] | 23 | \ "func Init()", |
| 24 | \ " silent! " . a:ex_cmd, |
| 25 | \ " call writefile([v:errmsg], 'Xrestrout')", |
| 26 | \ " qa!", |
| 27 | \ "endfunc", |
| 28 | \ "au VimEnter * call Init()", |
Bram Moolenaar | 8c62a08 | 2019-02-08 14:34:10 +0100 | [diff] [blame] | 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') |
| 35 | endfunc |
| 36 | |
| 37 | func 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:') |
| 45 | endfunc |
| 46 | |
| 47 | func 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:') |
| 54 | endfunc |
| 55 | |
| 56 | func 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:') |
| 65 | endfunc |
| 66 | |
| 67 | func 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:') |
| 75 | endfunc |
| 76 | |
| 77 | func 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:') |
| 85 | endfunc |
| 86 | |
| 87 | func 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:') |
| 94 | endfunc |
| 95 | |
| 96 | func 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:') |
| 103 | endfunc |