2018-08-06 19:53:11 -07:00
|
|
|
" Test the :compiler command
|
|
|
|
|
2022-11-07 04:40:30 -07:00
|
|
|
source check.vim
|
|
|
|
source shared.vim
|
|
|
|
|
2018-08-06 19:53:11 -07:00
|
|
|
func Test_compiler()
|
2022-11-07 04:40:30 -07:00
|
|
|
CheckExecutable perl
|
|
|
|
CheckFeature quickfix
|
2018-08-06 19:53:11 -07:00
|
|
|
|
2018-11-15 03:42:18 -07:00
|
|
|
" $LANG changes the output of Perl.
|
|
|
|
if $LANG != ''
|
|
|
|
unlet $LANG
|
|
|
|
endif
|
|
|
|
|
2019-09-18 18:52:19 -07:00
|
|
|
" %:S does not work properly with 'shellslash' set
|
|
|
|
let save_shellslash = &shellslash
|
|
|
|
set noshellslash
|
|
|
|
|
2018-08-06 19:53:11 -07:00
|
|
|
e Xfoo.pl
|
|
|
|
compiler perl
|
|
|
|
call assert_equal('perl', b:current_compiler)
|
|
|
|
call assert_fails('let g:current_compiler', 'E121:')
|
|
|
|
|
2022-01-21 03:18:18 -07:00
|
|
|
let verbose_efm = execute('verbose set efm')
|
2022-01-21 03:18:18 -07:00
|
|
|
call assert_match('Last set from .*[/\\]compiler[/\\]perl.vim ', verbose_efm)
|
2022-01-21 03:18:18 -07:00
|
|
|
|
2018-08-06 19:53:11 -07:00
|
|
|
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 18:52:37 -07:00
|
|
|
call assert_match('\n \d\+ Xfoo.pl:3: Global symbol "$foo" '
|
|
|
|
\ . 'requires explicit package name', a)
|
|
|
|
|
2018-08-06 19:53:11 -07:00
|
|
|
|
2019-09-18 18:52:19 -07:00
|
|
|
let &shellslash = save_shellslash
|
2018-08-06 19:53:11 -07:00
|
|
|
call delete('Xfoo.pl')
|
|
|
|
bw!
|
|
|
|
endfunc
|
|
|
|
|
2021-01-30 10:20:33 -07:00
|
|
|
func GetCompilerNames()
|
2021-11-01 16:24:49 -07:00
|
|
|
return glob('$VIMRUNTIME/compiler/*.vim', 0, 1)
|
|
|
|
\ ->map({i, v -> substitute(v, '.*[\\/]\([a-zA-Z0-9_\-]*\).vim', '\1', '')})
|
|
|
|
\ ->sort()
|
2021-01-30 10:20:33 -07:00
|
|
|
endfunc
|
|
|
|
|
2018-08-06 19:53:11 -07:00
|
|
|
func Test_compiler_without_arg()
|
2020-02-08 16:20:28 -07:00
|
|
|
let runtime = substitute($VIMRUNTIME, '\\', '/', 'g')
|
|
|
|
let a = split(execute('compiler'))
|
2021-01-30 10:20:33 -07: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-08-06 19:53:11 -07:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_compiler_completion()
|
2021-11-01 16:24:49 -07:00
|
|
|
let clist = GetCompilerNames()->join(' ')
|
2018-08-06 19:53:11 -07:00
|
|
|
call feedkeys(":compiler \<C-A>\<C-B>\"\<CR>", 'tx')
|
2021-01-30 10:20:33 -07:00
|
|
|
call assert_match('^"compiler ' .. clist .. '$', @:)
|
2018-08-06 19:53:11 -07:00
|
|
|
|
|
|
|
call feedkeys(":compiler p\<C-A>\<C-B>\"\<CR>", 'tx')
|
2021-04-03 17:29:34 -07:00
|
|
|
call assert_match('"compiler pbx perl\( p[a-z]\+\)\+ pylint pyunit', @:)
|
2018-08-06 19:53:11 -07:00
|
|
|
|
|
|
|
call feedkeys(":compiler! p\<C-A>\<C-B>\"\<CR>", 'tx')
|
2021-04-03 17:29:34 -07:00
|
|
|
call assert_match('"compiler! pbx perl\( p[a-z]\+\)\+ pylint pyunit', @:)
|
2018-08-06 19:53:11 -07:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_compiler_error()
|
2022-07-11 16:22:17 -07:00
|
|
|
let g:current_compiler = 'abc'
|
2018-08-06 19:53:11 -07:00
|
|
|
call assert_fails('compiler doesnotexist', 'E666:')
|
2022-07-11 16:22:17 -07:00
|
|
|
call assert_equal('abc', g:current_compiler)
|
|
|
|
call assert_fails('compiler! doesnotexist', 'E666:')
|
|
|
|
unlet! g:current_compiler
|
2018-08-06 19:53:11 -07:00
|
|
|
endfunc
|