blob: ffafd5be2133d24096b112e4b5b392e3a1e6e0c2 [file] [log] [blame]
Bram Moolenaar10561fe2018-05-19 15:01:10 +02001" Test the :compiler command
2
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01003source check.vim
Bram Moolenaar16531552020-02-08 16:00:46 +01004source shared.vim
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01005
Bram Moolenaar10561fe2018-05-19 15:01:10 +02006func Test_compiler()
7 if !executable('perl')
8 return
9 endif
Bram Moolenaar5a4c3082019-12-01 15:23:11 +010010 CheckFeature quickfix
Bram Moolenaar10561fe2018-05-19 15:01:10 +020011
Bram Moolenaarf0447e82018-07-03 21:26:38 +020012 " $LANG changes the output of Perl.
13 if $LANG != ''
14 unlet $LANG
15 endif
16
Bram Moolenaardff2adc2019-07-31 22:18:22 +020017 " %:S does not work properly with 'shellslash' set
18 let save_shellslash = &shellslash
19 set noshellslash
20
Bram Moolenaar10561fe2018-05-19 15:01:10 +020021 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')
Bram Moolenaarcebfcff2019-09-18 21:42:38 +020035 call assert_match('\n \d\+ Xfoo.pl:3: Global symbol "$foo" '
36 \ . 'requires explicit package name', a)
37
Bram Moolenaar10561fe2018-05-19 15:01:10 +020038
Bram Moolenaardff2adc2019-07-31 22:18:22 +020039 let &shellslash = save_shellslash
Bram Moolenaar10561fe2018-05-19 15:01:10 +020040 call delete('Xfoo.pl')
41 bw!
42endfunc
43
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010044func GetCompilerNames()
45 return glob('$VIMRUNTIME/compiler/*.vim', 0, 1)
46 \ ->map({k, v -> substitute(v, '.*[\\/]\([a-zA-Z0-9_\-]*\).vim', '\1', '')})
47endfunc
48
Bram Moolenaar10561fe2018-05-19 15:01:10 +020049func Test_compiler_without_arg()
Bram Moolenaarc25e7022019-10-10 14:08:26 +020050 let runtime = substitute($VIMRUNTIME, '\\', '/', 'g')
51 let a = split(execute('compiler'))
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010052 let exp = GetCompilerNames()
53 call assert_match(runtime .. '/compiler/' .. exp[0] .. '.vim$', a[0])
54 call assert_match(runtime .. '/compiler/' .. exp[1] .. '.vim$', a[1])
55 call assert_match(runtime .. '/compiler/' .. exp[-1] .. '.vim$', a[-1])
Bram Moolenaar10561fe2018-05-19 15:01:10 +020056endfunc
57
Bram Moolenaar16531552020-02-08 16:00:46 +010058" Test executing :compiler from the command line, not from a script
59func Test_compiler_commandline()
60 call system(GetVimCommandClean() .. ' --not-a-term -c "compiler gcc" -c "call writefile([b:current_compiler], ''XcompilerOut'')" -c "quit"')
61 call assert_equal(0, v:shell_error)
62 call assert_equal(["gcc"], readfile('XcompilerOut'))
63
64 call delete('XcompilerOut')
65endfunc
66
Bram Moolenaar10561fe2018-05-19 15:01:10 +020067func Test_compiler_completion()
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010068 let clist = GetCompilerNames()->join(' ')
Bram Moolenaar10561fe2018-05-19 15:01:10 +020069 call feedkeys(":compiler \<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010070 call assert_match('^"compiler ' .. clist .. '$', @:)
Bram Moolenaar10561fe2018-05-19 15:01:10 +020071
72 call feedkeys(":compiler p\<C-A>\<C-B>\"\<CR>", 'tx')
73 call assert_equal('"compiler pbx perl php pylint pyunit', @:)
74
75 call feedkeys(":compiler! p\<C-A>\<C-B>\"\<CR>", 'tx')
76 call assert_equal('"compiler! pbx perl php pylint pyunit', @:)
77endfunc
78
79func Test_compiler_error()
Bram Moolenaare20b9ec2020-02-03 21:40:04 +010080 let g:current_compiler = 'abc'
Bram Moolenaar10561fe2018-05-19 15:01:10 +020081 call assert_fails('compiler doesnotexist', 'E666:')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +010082 call assert_equal('abc', g:current_compiler)
83 call assert_fails('compiler! doesnotexist', 'E666:')
84 unlet! g:current_compiler
Bram Moolenaar10561fe2018-05-19 15:01:10 +020085endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020086
87" vim: shiftwidth=2 sts=2 expandtab