blob: b7315e1b84503866dd125608ec8f860667d78072 [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
Dominique Pelléca0ffc02023-09-24 22:57:41 +020010 let save_LC_ALL = $LC_ALL
11 let $LC_ALL= "C"
Bram Moolenaarf0447e82018-07-03 21:26:38 +020012
Bram Moolenaardff2adc2019-07-31 22:18:22 +020013 " %:S does not work properly with 'shellslash' set
14 let save_shellslash = &shellslash
15 set noshellslash
16
Bram Moolenaar10561fe2018-05-19 15:01:10 +020017 e Xfoo.pl
18 compiler perl
19 call assert_equal('perl', b:current_compiler)
20 call assert_fails('let g:current_compiler', 'E121:')
21
Bram Moolenaar58ef8a32021-11-12 11:25:11 +000022 let verbose_efm = execute('verbose set efm')
Bram Moolenaar0a15c762021-11-12 16:09:54 +000023 call assert_match('Last set from .*[/\\]compiler[/\\]perl.vim ', verbose_efm)
Bram Moolenaar58ef8a32021-11-12 11:25:11 +000024
Bram Moolenaar10561fe2018-05-19 15:01:10 +020025 call setline(1, ['#!/usr/bin/perl -w', 'use strict;', 'my $foo=1'])
26 w!
27 call feedkeys(":make\<CR>\<CR>", 'tx')
28 call assert_fails('clist', 'E42:')
29
30 call setline(1, ['#!/usr/bin/perl -w', 'use strict;', '$foo=1'])
31 w!
32 call feedkeys(":make\<CR>\<CR>", 'tx')
33 let a=execute('clist')
Bram Moolenaarcebfcff2019-09-18 21:42:38 +020034 call assert_match('\n \d\+ Xfoo.pl:3: Global symbol "$foo" '
35 \ . 'requires explicit package name', a)
36
Bram Moolenaar10561fe2018-05-19 15:01:10 +020037
Bram Moolenaardff2adc2019-07-31 22:18:22 +020038 let &shellslash = save_shellslash
Bram Moolenaar10561fe2018-05-19 15:01:10 +020039 call delete('Xfoo.pl')
40 bw!
Dominique Pelléca0ffc02023-09-24 22:57:41 +020041 let $LC_ALL = save_LC_ALL
Bram Moolenaar10561fe2018-05-19 15:01:10 +020042endfunc
43
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010044func GetCompilerNames()
45 return glob('$VIMRUNTIME/compiler/*.vim', 0, 1)
Bram Moolenaar142f2352020-11-23 21:39:14 +010046 \ ->map({i, v -> substitute(v, '.*[\\/]\([a-zA-Z0-9_\-]*\).vim', '\1', '')})
47 \ ->sort()
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010048endfunc
49
Bram Moolenaar10561fe2018-05-19 15:01:10 +020050func Test_compiler_without_arg()
Bram Moolenaarc25e7022019-10-10 14:08:26 +020051 let runtime = substitute($VIMRUNTIME, '\\', '/', 'g')
52 let a = split(execute('compiler'))
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010053 let exp = GetCompilerNames()
54 call assert_match(runtime .. '/compiler/' .. exp[0] .. '.vim$', a[0])
55 call assert_match(runtime .. '/compiler/' .. exp[1] .. '.vim$', a[1])
56 call assert_match(runtime .. '/compiler/' .. exp[-1] .. '.vim$', a[-1])
Bram Moolenaar10561fe2018-05-19 15:01:10 +020057endfunc
58
Bram Moolenaar16531552020-02-08 16:00:46 +010059" Test executing :compiler from the command line, not from a script
60func Test_compiler_commandline()
61 call system(GetVimCommandClean() .. ' --not-a-term -c "compiler gcc" -c "call writefile([b:current_compiler], ''XcompilerOut'')" -c "quit"')
62 call assert_equal(0, v:shell_error)
63 call assert_equal(["gcc"], readfile('XcompilerOut'))
64
65 call delete('XcompilerOut')
66endfunc
67
Bram Moolenaar10561fe2018-05-19 15:01:10 +020068func Test_compiler_completion()
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010069 let clist = GetCompilerNames()->join(' ')
Bram Moolenaar10561fe2018-05-19 15:01:10 +020070 call feedkeys(":compiler \<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar60bc8e72020-11-23 21:24:58 +010071 call assert_match('^"compiler ' .. clist .. '$', @:)
Bram Moolenaar10561fe2018-05-19 15:01:10 +020072
73 call feedkeys(":compiler p\<C-A>\<C-B>\"\<CR>", 'tx')
Wu, Zhenyuf9f54242024-04-14 20:38:24 +020074 call assert_match('"compiler pandoc pbx perl\( p[a-z_]\+\)\+ pylint pyunit', @:)
Bram Moolenaar10561fe2018-05-19 15:01:10 +020075
76 call feedkeys(":compiler! p\<C-A>\<C-B>\"\<CR>", 'tx')
Wu, Zhenyuf9f54242024-04-14 20:38:24 +020077 call assert_match('"compiler! pandoc pbx perl\( p[a-z_]\+\)\+ pylint pyunit', @:)
Bram Moolenaar10561fe2018-05-19 15:01:10 +020078endfunc
79
80func Test_compiler_error()
Bram Moolenaare20b9ec2020-02-03 21:40:04 +010081 let g:current_compiler = 'abc'
Bram Moolenaar10561fe2018-05-19 15:01:10 +020082 call assert_fails('compiler doesnotexist', 'E666:')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +010083 call assert_equal('abc', g:current_compiler)
84 call assert_fails('compiler! doesnotexist', 'E666:')
85 unlet! g:current_compiler
Bram Moolenaar10561fe2018-05-19 15:01:10 +020086endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020087
88" vim: shiftwidth=2 sts=2 expandtab