2018-05-19 15:01:10 +02:00
|
|
|
" Test the :compiler command
|
|
|
|
|
2019-12-01 15:23:11 +01:00
|
|
|
source check.vim
|
2020-02-08 16:00:46 +01:00
|
|
|
source shared.vim
|
2019-12-01 15:23:11 +01:00
|
|
|
|
2018-05-19 15:01:10 +02:00
|
|
|
func Test_compiler()
|
|
|
|
if !executable('perl')
|
|
|
|
return
|
|
|
|
endif
|
2019-12-01 15:23:11 +01:00
|
|
|
CheckFeature quickfix
|
2018-05-19 15:01:10 +02:00
|
|
|
|
2018-07-03 21:26:38 +02:00
|
|
|
" $LANG changes the output of Perl.
|
|
|
|
if $LANG != ''
|
|
|
|
unlet $LANG
|
|
|
|
endif
|
|
|
|
|
2019-07-31 22:18:22 +02:00
|
|
|
" %:S does not work properly with 'shellslash' set
|
|
|
|
let save_shellslash = &shellslash
|
|
|
|
set noshellslash
|
|
|
|
|
2018-05-19 15:01:10 +02:00
|
|
|
e Xfoo.pl
|
|
|
|
compiler perl
|
|
|
|
call assert_equal('perl', b:current_compiler)
|
|
|
|
call assert_fails('let g:current_compiler', 'E121:')
|
|
|
|
|
|
|
|
call setline(1, ['#!/usr/bin/perl -w', 'use strict;', 'my $foo=1'])
|
|
|
|
w!
|
|
|
|
call feedkeys(":make\<CR>\<CR>", 'tx')
|
|
|
|
call assert_fails('clist', 'E42:')
|
|
|
|
|
|
|
|
call setline(1, ['#!/usr/bin/perl -w', 'use strict;', '$foo=1'])
|
|
|
|
w!
|
|
|
|
call feedkeys(":make\<CR>\<CR>", 'tx')
|
|
|
|
let a=execute('clist')
|
2019-09-18 21:42:38 +02:00
|
|
|
call assert_match('\n \d\+ Xfoo.pl:3: Global symbol "$foo" '
|
|
|
|
\ . 'requires explicit package name', a)
|
|
|
|
|
2018-05-19 15:01:10 +02:00
|
|
|
|
2019-07-31 22:18:22 +02:00
|
|
|
let &shellslash = save_shellslash
|
2018-05-19 15:01:10 +02:00
|
|
|
call delete('Xfoo.pl')
|
|
|
|
bw!
|
|
|
|
endfunc
|
|
|
|
|
2020-11-23 21:24:58 +01:00
|
|
|
func GetCompilerNames()
|
|
|
|
return glob('$VIMRUNTIME/compiler/*.vim', 0, 1)
|
|
|
|
\ ->map({k, v -> substitute(v, '.*[\\/]\([a-zA-Z0-9_\-]*\).vim', '\1', '')})
|
|
|
|
endfunc
|
|
|
|
|
2018-05-19 15:01:10 +02:00
|
|
|
func Test_compiler_without_arg()
|
2019-10-10 14:08:26 +02:00
|
|
|
let runtime = substitute($VIMRUNTIME, '\\', '/', 'g')
|
|
|
|
let a = split(execute('compiler'))
|
2020-11-23 21:24:58 +01:00
|
|
|
let exp = GetCompilerNames()
|
|
|
|
call assert_match(runtime .. '/compiler/' .. exp[0] .. '.vim$', a[0])
|
|
|
|
call assert_match(runtime .. '/compiler/' .. exp[1] .. '.vim$', a[1])
|
|
|
|
call assert_match(runtime .. '/compiler/' .. exp[-1] .. '.vim$', a[-1])
|
2018-05-19 15:01:10 +02:00
|
|
|
endfunc
|
|
|
|
|
2020-02-08 16:00:46 +01:00
|
|
|
" Test executing :compiler from the command line, not from a script
|
|
|
|
func Test_compiler_commandline()
|
|
|
|
call system(GetVimCommandClean() .. ' --not-a-term -c "compiler gcc" -c "call writefile([b:current_compiler], ''XcompilerOut'')" -c "quit"')
|
|
|
|
call assert_equal(0, v:shell_error)
|
|
|
|
call assert_equal(["gcc"], readfile('XcompilerOut'))
|
|
|
|
|
|
|
|
call delete('XcompilerOut')
|
|
|
|
endfunc
|
|
|
|
|
2018-05-19 15:01:10 +02:00
|
|
|
func Test_compiler_completion()
|
2020-11-23 21:24:58 +01:00
|
|
|
let clist = GetCompilerNames()->join(' ')
|
2018-05-19 15:01:10 +02:00
|
|
|
call feedkeys(":compiler \<C-A>\<C-B>\"\<CR>", 'tx')
|
2020-11-23 21:24:58 +01:00
|
|
|
call assert_match('^"compiler ' .. clist .. '$', @:)
|
2018-05-19 15:01:10 +02:00
|
|
|
|
|
|
|
call feedkeys(":compiler p\<C-A>\<C-B>\"\<CR>", 'tx')
|
|
|
|
call assert_equal('"compiler pbx perl php pylint pyunit', @:)
|
|
|
|
|
|
|
|
call feedkeys(":compiler! p\<C-A>\<C-B>\"\<CR>", 'tx')
|
|
|
|
call assert_equal('"compiler! pbx perl php pylint pyunit', @:)
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_compiler_error()
|
2020-02-03 21:40:04 +01:00
|
|
|
let g:current_compiler = 'abc'
|
2018-05-19 15:01:10 +02:00
|
|
|
call assert_fails('compiler doesnotexist', 'E666:')
|
2020-02-03 21:40:04 +01:00
|
|
|
call assert_equal('abc', g:current_compiler)
|
|
|
|
call assert_fails('compiler! doesnotexist', 'E666:')
|
|
|
|
unlet! g:current_compiler
|
2018-05-19 15:01:10 +02:00
|
|
|
endfunc
|
2020-08-12 18:50:36 +02:00
|
|
|
|
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|