1" Test the :compiler command 2 3source check.vim 4source shared.vim 5 6func Test_compiler() 7 if !executable('perl') 8 return 9 endif 10 CheckFeature quickfix 11 12 " $LANG changes the output of Perl. 13 if $LANG != '' 14 unlet $LANG 15 endif 16 17 " %:S does not work properly with 'shellslash' set 18 let save_shellslash = &shellslash 19 set noshellslash 20 21 e Xfoo.pl 22 compiler perl 23 call assert_equal('perl', b:current_compiler) 24 call assert_fails('let g:current_compiler', 'E121:') 25 26 call setline(1, ['#!/usr/bin/perl -w', 'use strict;', 'my $foo=1']) 27 w! 28 call feedkeys(":make\<CR>\<CR>", 'tx') 29 call assert_fails('clist', 'E42:') 30 31 call setline(1, ['#!/usr/bin/perl -w', 'use strict;', '$foo=1']) 32 w! 33 call feedkeys(":make\<CR>\<CR>", 'tx') 34 let a=execute('clist') 35 call assert_match('\n \d\+ Xfoo.pl:3: Global symbol "$foo" ' 36 \ . 'requires explicit package name', a) 37 38 39 let &shellslash = save_shellslash 40 call delete('Xfoo.pl') 41 bw! 42endfunc 43 44func GetCompilerNames() 45 return glob('$VIMRUNTIME/compiler/*.vim', 0, 1) 46 \ ->map({i, v -> substitute(v, '.*[\\/]\([a-zA-Z0-9_\-]*\).vim', '\1', '')}) 47 \ ->sort() 48endfunc 49 50func Test_compiler_without_arg() 51 let runtime = substitute($VIMRUNTIME, '\\', '/', 'g') 52 let a = split(execute('compiler')) 53 let exp = GetCompilerNames() 54 call assert_match(runtime .. '/compiler/' .. exp[0] .. '.vim$', a[0]) 55 call assert_match(runtime .. '/compiler/' .. exp[1] .. '.vim$', a[1]) 56 call assert_match(runtime .. '/compiler/' .. exp[-1] .. '.vim$', a[-1]) 57endfunc 58 59" Test executing :compiler from the command line, not from a script 60func Test_compiler_commandline() 61 call system(GetVimCommandClean() .. ' --not-a-term -c "compiler gcc" -c "call writefile([b:current_compiler], ''XcompilerOut'')" -c "quit"') 62 call assert_equal(0, v:shell_error) 63 call assert_equal(["gcc"], readfile('XcompilerOut')) 64 65 call delete('XcompilerOut') 66endfunc 67 68func Test_compiler_completion() 69 let clist = GetCompilerNames()->join(' ') 70 call feedkeys(":compiler \<C-A>\<C-B>\"\<CR>", 'tx') 71 call assert_match('^"compiler ' .. clist .. '$', @:) 72 73 call feedkeys(":compiler p\<C-A>\<C-B>\"\<CR>", 'tx') 74 call assert_equal('"compiler pbx perl php pylint pyunit', @:) 75 76 call feedkeys(":compiler! p\<C-A>\<C-B>\"\<CR>", 'tx') 77 call assert_equal('"compiler! pbx perl php pylint pyunit', @:) 78endfunc 79 80func Test_compiler_error() 81 let g:current_compiler = 'abc' 82 call assert_fails('compiler doesnotexist', 'E666:') 83 call assert_equal('abc', g:current_compiler) 84 call assert_fails('compiler! doesnotexist', 'E666:') 85 unlet! g:current_compiler 86endfunc 87 88" vim: shiftwidth=2 sts=2 expandtab 89