blob: 09c03f7f20dd8a072941938a9494a825e93d5aca [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()
Bram Moolenaaraeb313f2020-11-27 19:13:28 +01007 CheckExecutable perl
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01008 CheckFeature quickfix
Bram Moolenaar10561fe2018-05-19 15:01:10 +02009
Bram Moolenaarf0447e82018-07-03 21:26:38 +020010 " $LANG changes the output of Perl.
11 if $LANG != ''
12 unlet $LANG
13 endif
14
Bram Moolenaardff2adc2019-07-31 22:18:22 +020015 " %:S does not work properly with 'shellslash' set
16 let save_shellslash = &shellslash
17 set noshellslash
18
Bram Moolenaar10561fe2018-05-19 15:01:10 +020019 e Xfoo.pl
20 compiler perl
21 call assert_equal('perl', b:current_compiler)
22 call assert_fails('let g:current_compiler', 'E121:')
23
Bram Moolenaar58ef8a32021-11-12 11:25:11 +000024 let verbose_efm = execute('verbose set efm')
25 call assert_match('Last set from .*/compiler/perl.vim ', verbose_efm)
26
Bram Moolenaar10561fe2018-05-19 15:01:10 +020027 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')
Bram Moolenaarcebfcff2019-09-18 21:42:38 +020036 call assert_match('\n \d\+ Xfoo.pl:3: Global symbol "$foo" '
37 \ . 'requires explicit package name', a)
38
Bram Moolenaar10561fe2018-05-19 15:01:10 +020039
Bram Moolenaardff2adc2019-07-31 22:18:22 +020040 let &shellslash = save_shellslash
Bram Moolenaar10561fe2018-05-19 15:01:10 +020041 call delete('Xfoo.pl')
42 bw!
43endfunc
44
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010045func GetCompilerNames()
46 return glob('$VIMRUNTIME/compiler/*.vim', 0, 1)
Bram Moolenaar142f2352020-11-23 21:39:14 +010047 \ ->map({i, v -> substitute(v, '.*[\\/]\([a-zA-Z0-9_\-]*\).vim', '\1', '')})
48 \ ->sort()
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010049endfunc
50
Bram Moolenaar10561fe2018-05-19 15:01:10 +020051func Test_compiler_without_arg()
Bram Moolenaarc25e7022019-10-10 14:08:26 +020052 let runtime = substitute($VIMRUNTIME, '\\', '/', 'g')
53 let a = split(execute('compiler'))
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010054 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])
Bram Moolenaar10561fe2018-05-19 15:01:10 +020058endfunc
59
Bram Moolenaar16531552020-02-08 16:00:46 +010060" 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
Bram Moolenaar10561fe2018-05-19 15:01:10 +020069func Test_compiler_completion()
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010070 let clist = GetCompilerNames()->join(' ')
Bram Moolenaar10561fe2018-05-19 15:01:10 +020071 call feedkeys(":compiler \<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010072 call assert_match('^"compiler ' .. clist .. '$', @:)
Bram Moolenaar10561fe2018-05-19 15:01:10 +020073
74 call feedkeys(":compiler p\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarc17ba792021-04-03 19:07:05 +020075 call assert_match('"compiler pbx perl\( p[a-z]\+\)\+ pylint pyunit', @:)
Bram Moolenaar10561fe2018-05-19 15:01:10 +020076
77 call feedkeys(":compiler! p\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarc17ba792021-04-03 19:07:05 +020078 call assert_match('"compiler! pbx perl\( p[a-z]\+\)\+ pylint pyunit', @:)
Bram Moolenaar10561fe2018-05-19 15:01:10 +020079endfunc
80
81func Test_compiler_error()
Bram Moolenaare20b9ec2020-02-03 21:40:04 +010082 let g:current_compiler = 'abc'
Bram Moolenaar10561fe2018-05-19 15:01:10 +020083 call assert_fails('compiler doesnotexist', 'E666:')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +010084 call assert_equal('abc', g:current_compiler)
85 call assert_fails('compiler! doesnotexist', 'E666:')
86 unlet! g:current_compiler
Bram Moolenaar10561fe2018-05-19 15:01:10 +020087endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020088
89" vim: shiftwidth=2 sts=2 expandtab