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  call setline(1, ['#!/usr/bin/perl -w', 'use strict;', 'my $foo=1'])
25  w!
26  call feedkeys(":make\<CR>\<CR>", 'tx')
27  call assert_fails('clist', 'E42:')
28
29  call setline(1, ['#!/usr/bin/perl -w', 'use strict;', '$foo=1'])
30  w!
31  call feedkeys(":make\<CR>\<CR>", 'tx')
32  let a=execute('clist')
33  call assert_match('\n \d\+ Xfoo.pl:3: Global symbol "$foo" '
34  \ .               'requires explicit package name', a)
35
36
37  let &shellslash = save_shellslash
38  call delete('Xfoo.pl')
39  bw!
40endfunc
41
42func GetCompilerNames()
43  return glob('$VIMRUNTIME/compiler/*.vim', 0, 1)
44        \ ->map({i, v -> substitute(v, '.*[\\/]\([a-zA-Z0-9_\-]*\).vim', '\1', '')})
45        \ ->sort()
46endfunc
47
48func Test_compiler_without_arg()
49  let runtime = substitute($VIMRUNTIME, '\\', '/', 'g')
50  let a = split(execute('compiler'))
51  let exp = GetCompilerNames()
52  call assert_match(runtime .. '/compiler/' .. exp[0] .. '.vim$',  a[0])
53  call assert_match(runtime .. '/compiler/' .. exp[1] .. '.vim$',  a[1])
54  call assert_match(runtime .. '/compiler/' .. exp[-1] .. '.vim$', a[-1])
55endfunc
56
57" Test executing :compiler from the command line, not from a script
58func Test_compiler_commandline()
59  call system(GetVimCommandClean() .. ' --not-a-term -c "compiler gcc" -c "call writefile([b:current_compiler], ''XcompilerOut'')" -c "quit"')
60  call assert_equal(0, v:shell_error)
61  call assert_equal(["gcc"], readfile('XcompilerOut'))
62
63  call delete('XcompilerOut')
64endfunc
65
66func Test_compiler_completion()
67  let clist = GetCompilerNames()->join(' ')
68  call feedkeys(":compiler \<C-A>\<C-B>\"\<CR>", 'tx')
69  call assert_match('^"compiler ' .. clist .. '$', @:)
70
71  call feedkeys(":compiler p\<C-A>\<C-B>\"\<CR>", 'tx')
72  call assert_equal('"compiler pbx perl php pylint pyunit', @:)
73
74  call feedkeys(":compiler! p\<C-A>\<C-B>\"\<CR>", 'tx')
75  call assert_equal('"compiler! pbx perl php pylint pyunit', @:)
76endfunc
77
78func Test_compiler_error()
79  let g:current_compiler = 'abc'
80  call assert_fails('compiler doesnotexist', 'E666:')
81  call assert_equal('abc', g:current_compiler)
82  call assert_fails('compiler! doesnotexist', 'E666:')
83  unlet! g:current_compiler
84endfunc
85
86" vim: shiftwidth=2 sts=2 expandtab
87