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 | |
| 5 | func Test_restricted() |
| 6 | let cmd = GetVimCommand('Xrestricted') |
| 7 | if cmd == '' |
| 8 | return |
| 9 | endif |
| 10 | |
| 11 | call writefile([ |
| 12 | \ "silent !ls", |
| 13 | \ "call writefile([v:errmsg], 'Xrestrout')", |
| 14 | \ "qa!", |
| 15 | \ ], 'Xrestricted') |
| 16 | call system(cmd . ' -Z') |
| 17 | call assert_match('E145:', join(readfile('Xrestrout'))) |
| 18 | |
| 19 | call delete('Xrestricted') |
| 20 | call delete('Xrestrout') |
| 21 | endfunc |
| 22 | |
| 23 | func Run_restricted_test(ex_cmd, error) |
| 24 | let cmd = GetVimCommand('Xrestricted') |
| 25 | if cmd == '' |
| 26 | return |
| 27 | endif |
| 28 | |
| 29 | call writefile([ |
| 30 | \ a:ex_cmd, |
| 31 | \ "call writefile([v:errmsg], 'Xrestrout')", |
| 32 | \ "qa!", |
| 33 | \ ], 'Xrestricted') |
| 34 | call system(cmd . ' -Z') |
| 35 | call assert_match(a:error, join(readfile('Xrestrout'))) |
| 36 | |
| 37 | call delete('Xrestricted') |
| 38 | call delete('Xrestrout') |
| 39 | endfunc |
| 40 | |
| 41 | func Test_restricted_lua() |
| 42 | if !has('lua') |
| 43 | throw 'Skipped: Lua is not supported' |
| 44 | endif |
| 45 | call Run_restricted_test('lua print("Hello, Vim!")', 'E981:') |
| 46 | call Run_restricted_test('luado return "hello"', 'E981:') |
| 47 | call Run_restricted_test('luafile somefile', 'E981:') |
| 48 | call Run_restricted_test('call luaeval("expression")', 'E145:') |
| 49 | endfunc |
| 50 | |
| 51 | func Test_restricted_mzscheme() |
| 52 | if !has('mzscheme') |
| 53 | throw 'Skipped: MzScheme is not supported' |
| 54 | endif |
| 55 | call Run_restricted_test('mzscheme statement', 'E981:') |
| 56 | call Run_restricted_test('mzfile somefile', 'E981:') |
| 57 | call Run_restricted_test('call mzeval("expression")', 'E145:') |
| 58 | endfunc |
| 59 | |
| 60 | func Test_restricted_perl() |
| 61 | if !has('perl') |
| 62 | throw 'Skipped: Perl is not supported' |
| 63 | endif |
| 64 | " TODO: how to make Safe mode fail? |
| 65 | " call Run_restricted_test('perl system("ls")', 'E981:') |
| 66 | " call Run_restricted_test('perldo system("hello")', 'E981:') |
| 67 | " call Run_restricted_test('perlfile somefile', 'E981:') |
| 68 | " call Run_restricted_test('call perleval("system(\"ls\")")', 'E145:') |
| 69 | endfunc |
| 70 | |
| 71 | func Test_restricted_python() |
| 72 | if !has('python') |
| 73 | throw 'Skipped: Python is not supported' |
| 74 | endif |
| 75 | call Run_restricted_test('python print "hello"', 'E981:') |
| 76 | call Run_restricted_test('pydo return "hello"', 'E981:') |
| 77 | call Run_restricted_test('pyfile somefile', 'E981:') |
| 78 | call Run_restricted_test('call pyeval("expression")', 'E145:') |
| 79 | endfunc |
| 80 | |
| 81 | func Test_restricted_python3() |
| 82 | if !has('python3') |
| 83 | throw 'Skipped: Python3 is not supported' |
| 84 | endif |
| 85 | call Run_restricted_test('py3 print "hello"', 'E981:') |
| 86 | call Run_restricted_test('py3do return "hello"', 'E981:') |
| 87 | call Run_restricted_test('py3file somefile', 'E981:') |
| 88 | call Run_restricted_test('call py3eval("expression")', 'E145:') |
| 89 | endfunc |
| 90 | |
| 91 | func Test_restricted_ruby() |
| 92 | if !has('ruby') |
| 93 | throw 'Skipped: Ruby is not supported' |
| 94 | endif |
| 95 | call Run_restricted_test('ruby print "Hello"', 'E981:') |
| 96 | call Run_restricted_test('rubydo print "Hello"', 'E981:') |
| 97 | call Run_restricted_test('rubyfile somefile', 'E981:') |
| 98 | endfunc |
| 99 | |
| 100 | func Test_restricted_tcl() |
| 101 | if !has('tcl') |
| 102 | throw 'Skipped: Tcl is not supported' |
| 103 | endif |
| 104 | call Run_restricted_test('tcl puts "Hello"', 'E981:') |
| 105 | call Run_restricted_test('tcldo puts "Hello"', 'E981:') |
| 106 | call Run_restricted_test('tclfile somefile', 'E981:') |
| 107 | endfunc |