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