#3299 Merge gcc and clang into a cc linter

Users can easily be confused when they set some options for a C or C++
compiler, and another compiler is run with different options, which
still reports errors. To remedy this, the existing `gcc` and `clang`
linters have been replaced with a `cc` linter that will run either
compiler.

This is a breaking change for ALE v3.0.0.
This commit is contained in:
w0rp 2020-08-20 01:46:29 +01:00
parent 4d42ebc160
commit 2b785688ea
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
15 changed files with 282 additions and 470 deletions

View File

@ -1,12 +1,27 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: gcc linter for c files
" Description: A C compiler linter for C files with gcc/clang, etc.
call ale#Set('c_gcc_executable', 'gcc')
call ale#Set('c_gcc_options', '-std=c11 -Wall')
call ale#Set('c_cc_executable', '<auto>')
call ale#Set('c_cc_options', '-std=c11 -Wall')
function! ale_linters#c#gcc#GetCommand(buffer, output) abort
function! ale_linters#c#cc#GetExecutable(buffer) abort
let l:executable = ale#Var(a:buffer, 'c_cc_executable')
" Default to either clang or gcc.
if l:executable is# '<auto>'
if ale#engine#IsExecutable(a:buffer, 'clang')
let l:executable = 'clang'
else
let l:executable = 'gcc'
endif
endif
return l:executable
endfunction
function! ale_linters#c#cc#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
let l:ale_flags = ale#Var(a:buffer, 'c_gcc_options')
let l:ale_flags = ale#Var(a:buffer, 'c_cc_options')
if l:cflags =~# '-std='
let l:ale_flags = substitute(
@ -29,9 +44,10 @@ function! ale_linters#c#gcc#GetCommand(buffer, output) abort
endfunction
call ale#linter#Define('c', {
\ 'name': 'gcc',
\ 'name': 'cc',
\ 'aliases': ['gcc', 'clang'],
\ 'output_stream': 'stderr',
\ 'executable': {b -> ale#Var(b, 'c_gcc_executable')},
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#c#gcc#GetCommand'))},
\ 'executable': function('ale_linters#c#cc#GetExecutable'),
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#c#cc#GetCommand'))},
\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',
\})

View File

@ -1,33 +0,0 @@
" Author: Masahiro H https://github.com/mshr-h
" Description: clang linter for c files
call ale#Set('c_clang_executable', 'clang')
call ale#Set('c_clang_options', '-std=c11 -Wall')
function! ale_linters#c#clang#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
let l:ale_flags = ale#Var(a:buffer, 'c_clang_options')
if l:cflags =~# '-std='
let l:ale_flags = substitute(
\ l:ale_flags,
\ '-std=\(c\|gnu\)[0-9]\{2\}',
\ '',
\ 'g')
endif
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
return '%e -S -x c -fsyntax-only'
\ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h'))
\ . ale#Pad(l:cflags)
\ . ale#Pad(l:ale_flags) . ' -'
endfunction
call ale#linter#Define('c', {
\ 'name': 'clang',
\ 'output_stream': 'stderr',
\ 'executable': {b -> ale#Var(b, 'c_clang_executable')},
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#c#clang#GetCommand'))},
\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',
\})

53
ale_linters/cpp/cc.vim Normal file
View File

@ -0,0 +1,53 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: A C++ compiler linter for C++ files with gcc/clang, etc.
call ale#Set('cpp_cc_executable', '<auto>')
call ale#Set('cpp_cc_options', '-std=c++14 -Wall')
function! ale_linters#cpp#cc#GetExecutable(buffer) abort
let l:executable = ale#Var(a:buffer, 'cpp_cc_executable')
" Default to either clang++ or gcc.
if l:executable is# '<auto>'
if ale#engine#IsExecutable(a:buffer, 'clang++')
let l:executable = 'clang++'
else
let l:executable = 'gcc'
endif
endif
return l:executable
endfunction
function! ale_linters#cpp#cc#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
let l:ale_flags = ale#Var(a:buffer, 'cpp_cc_options')
if l:cflags =~# '-std='
let l:ale_flags = substitute(
\ l:ale_flags,
\ '-std=\(c\|gnu\)++[0-9]\{2\}',
\ '',
\ 'g')
endif
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
"
" `-o /dev/null` or `-o null` is needed to catch all errors,
" -fsyntax-only doesn't catch everything.
return '%e -S -x c++'
\ . ' -o ' . g:ale#util#nul_file
\ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h'))
\ . ale#Pad(l:cflags)
\ . ale#Pad(l:ale_flags) . ' -'
endfunction
call ale#linter#Define('cpp', {
\ 'name': 'cc',
\ 'aliases': ['gcc', 'clang', 'g++', 'clang++'],
\ 'output_stream': 'stderr',
\ 'executable': function('ale_linters#cpp#cc#GetExecutable'),
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#cpp#cc#GetCommand'))},
\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',
\})

View File

@ -1,33 +0,0 @@
" Author: Tomota Nakamura <https://github.com/tomotanakamura>
" Description: clang linter for cpp files
call ale#Set('cpp_clang_executable', 'clang++')
call ale#Set('cpp_clang_options', '-std=c++14 -Wall')
function! ale_linters#cpp#clang#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
let l:ale_flags = ale#Var(a:buffer, 'cpp_clang_options')
if l:cflags =~# '-std='
let l:ale_flags = substitute(
\ l:ale_flags,
\ '-std=\(c\|gnu\)++[0-9]\{2\}',
\ '',
\ 'g')
endif
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
return '%e -S -x c++ -fsyntax-only'
\ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h'))
\ . ale#Pad(l:cflags)
\ . ale#Pad(l:ale_flags) . ' -'
endfunction
call ale#linter#Define('cpp', {
\ 'name': 'clang',
\ 'output_stream': 'stderr',
\ 'executable': {b -> ale#Var(b, 'cpp_clang_executable')},
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#cpp#clang#GetCommand'))},
\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',
\})

View File

@ -1,38 +0,0 @@
" Author: geam <mdelage@student.42.fr>
" Description: gcc linter for cpp files
"
call ale#Set('cpp_gcc_executable', 'gcc')
call ale#Set('cpp_gcc_options', '-std=c++14 -Wall')
function! ale_linters#cpp#gcc#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
let l:ale_flags = ale#Var(a:buffer, 'cpp_gcc_options')
if l:cflags =~# '-std='
let l:ale_flags = substitute(
\ l:ale_flags,
\ '-std=\(c\|gnu\)++[0-9]\{2\}',
\ '',
\ 'g')
endif
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
"
" `-o /dev/null` or `-o null` is needed to catch all errors,
" -fsyntax-only doesn't catch everything.
return '%e -S -x c++'
\ . ' -o ' . g:ale#util#nul_file
\ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h'))
\ . ale#Pad(l:cflags)
\ . ale#Pad(l:ale_flags) . ' -'
endfunction
call ale#linter#Define('cpp', {
\ 'name': 'gcc',
\ 'aliases': ['g++'],
\ 'output_stream': 'stderr',
\ 'executable': {b -> ale#Var(b, 'cpp_gcc_executable')},
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#cpp#gcc#GetCommand'))},
\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',
\})

View File

@ -1,6 +1,9 @@
===============================================================================
ALE C Integration *ale-c-options*
For basic checking of problems with C files, ALE offers the `cc` linter, which
runs either `clang`, or `gcc`. See |ale-c-cc|.
===============================================================================
Global Options
@ -11,12 +14,12 @@ g:ale_c_build_dir_names *g:ale_c_build_dir_names*
Type: |List|
Default: `['build', 'bin']`
A list of directory names to be used when searching upwards from cpp
files to discover compilation databases with. For directory named `'foo'`,
ALE will search for `'foo/compile_commands.json'` in all directories on and above
the directory containing the cpp file to find path to compilation database.
This feature is useful for the clang tools wrapped around LibTooling (namely
here, clang-tidy)
A list of directory names to be used when searching upwards from cpp files
to discover compilation databases with. For directory named `'foo'`, ALE
will search for `'foo/compile_commands.json'` in all directories on and
above the directory containing the cpp file to find path to compilation
database. This feature is useful for the clang tools wrapped around
LibTooling (namely here, clang-tidy)
g:ale_c_build_dir *g:ale_c_build_dir*
@ -94,22 +97,58 @@ g:ale_c_astyle_project_options *g:ale_c_astyle_project_options*
===============================================================================
clang *ale-c-clang*
cc *ale-c-cc*
*ale-c-gcc*
*ale-c-clang*
g:ale_c_clang_executable *g:ale_c_clang_executable*
*b:ale_c_clang_executable*
g:ale_c_cc_executable *g:ale_c_cc_executable*
*b:ale_c_cc_executable*
Type: |String|
Default: `'clang'`
Default: `'<auto>'`
This variable can be changed to use a different executable for clang.
This variable can be changed to use a different executable for a C compiler.
ALE will try to use `clang` if Clang is available, otherwise ALE will
default to checking C code with `gcc`.
g:ale_c_clang_options *g:ale_c_clang_options*
*b:ale_c_clang_options*
g:ale_c_cc_options *g:ale_c_cc_options*
*b:ale_c_cc_options*
Type: |String|
Default: `'-std=c11 -Wall'`
This variable can be changed to modify flags given to clang.
This variable can be change to modify flags given to the C compiler.
===============================================================================
ccls *ale-c-ccls*
g:ale_c_ccls_executable *g:ale_c_ccls_executable*
*b:ale_c_ccls_executable*
Type: |String|
Default: `'ccls'`
This variable can be changed to use a different executable for ccls.
g:ale_c_ccls_init_options *g:ale_c_ccls_init_options*
*b:ale_c_ccls_init_options*
Type: |Dictionary|
Default: `{}`
This variable can be changed to customize ccls initialization options.
Example: >
{
\ 'cacheDirectory': '/tmp/ccls',
\ 'cacheFormat': 'binary',
\ 'diagnostics': {
\ 'onOpen': 0,
\ 'opChange': 1000,
\ },
\ }
<
Visit https://github.com/MaskRay/ccls/wiki/Initialization-options for all
available options and explanations.
===============================================================================
@ -294,25 +333,6 @@ g:ale_c_flawfinder_error_severity *g:ale_c_flawfinder_error_severity*
error. This setting also applies to flawfinder for c++.
===============================================================================
gcc *ale-c-gcc*
g:ale_c_gcc_executable *g:ale_c_gcc_executable*
*b:ale_c_gcc_executable*
Type: |String|
Default: `'gcc'`
This variable can be changed to use a different executable for gcc.
g:ale_c_gcc_options *g:ale_c_gcc_options*
*b:ale_c_gcc_options*
Type: |String|
Default: `'-std=c11 -Wall'`
This variable can be change to modify flags given to gcc.
===============================================================================
uncrustify *ale-c-uncrustify*
@ -332,36 +352,5 @@ g:ale_c_uncrustify_options *g:ale_c_uncrustify_options*
This variable can be change to modify flags given to uncrustify.
===============================================================================
ccls *ale-c-ccls*
g:ale_c_ccls_executable *g:ale_c_ccls_executable*
*b:ale_c_ccls_executable*
Type: |String|
Default: `'ccls'`
This variable can be changed to use a different executable for ccls.
g:ale_c_ccls_init_options *g:ale_c_ccls_init_options*
*b:ale_c_ccls_init_options*
Type: |Dictionary|
Default: `{}`
This variable can be changed to customize ccls initialization options.
Example: >
{
\ 'cacheDirectory': '/tmp/ccls',
\ 'cacheFormat': 'binary',
\ 'diagnostics': {
\ 'onOpen': 0,
\ 'opChange': 1000,
\ },
\ }
<
Visit https://github.com/MaskRay/ccls/wiki/Initialization-options for all
available options and explanations.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -1,6 +1,9 @@
===============================================================================
ALE C++ Integration *ale-cpp-options*
For basic checking of problems with C++ files, ALE offers the `cc` linter,
which runs either `clang++`, or `gcc`. See |ale-cpp-cc|.
===============================================================================
Global Options
@ -38,41 +41,58 @@ g:ale_cpp_astyle_project_options *g:ale_cpp_astyle_project_options*
===============================================================================
clang *ale-cpp-clang*
cc *ale-cpp-cc*
*ale-cpp-gcc*
*ale-cpp-clang*
g:ale_cpp_clang_executable *g:ale_cpp_clang_executable*
*b:ale_cpp_clang_executable*
g:ale_cpp_cc_executable *g:ale_cpp_cc_executable*
*b:ale_cpp_cc_executable*
Type: |String|
Default: `'clang++'`
Default: `'<auto>'`
This variable can be changed to use a different executable for clang.
This variable can be changed to use a different executable for a C++ compiler.
ALE will try to use `clang++` if Clang is available, otherwise ALE will
default to checking C++ code with `gcc`.
g:ale_cpp_clang_options *g:ale_cpp_clang_options*
*b:ale_cpp_clang_options*
g:ale_cpp_cc_options *g:ale_cpp_cc_options*
*b:ale_cpp_cc_options*
Type: |String|
Default: `'-std=c++14 -Wall'`
This variable can be changed to modify flags given to clang.
This variable can be change to modify flags given to the C++ compiler.
===============================================================================
clangd *ale-cpp-clangd*
ccls *ale-cpp-ccls*
g:ale_cpp_clangd_executable *g:ale_cpp_clangd_executable*
*b:ale_cpp_clangd_executable*
g:ale_cpp_ccls_executable *g:ale_cpp_ccls_executable*
*b:ale_cpp_ccls_executable*
Type: |String|
Default: `'clangd'`
Default: `'ccls'`
This variable can be changed to use a different executable for clangd.
This variable can be changed to use a different executable for ccls.
g:ale_cpp_clangd_options *g:ale_cpp_clangd_options*
*b:ale_cpp_clangd_options*
Type: |String|
Default: `''`
g:ale_cpp_ccls_init_options *g:ale_cpp_ccls_init_options*
*b:ale_cpp_ccls_init_options*
Type: |Dictionary|
Default: `{}`
This variable can be changed to modify flags given to clangd.
This variable can be changed to customize ccls initialization options.
Example: >
{
\ 'cacheDirectory': '/tmp/ccls',
\ 'cacheFormat': 'binary',
\ 'diagnostics': {
\ 'onOpen': 0,
\ 'opChange': 1000,
\ },
\ }
<
Visit https://github.com/MaskRay/ccls/wiki/Initialization-options for all
available options and explanations.
===============================================================================
@ -106,6 +126,25 @@ g:ale_cpp_clangcheck_options *g:ale_cpp_clangcheck_options*
option.
===============================================================================
clangd *ale-cpp-clangd*
g:ale_cpp_clangd_executable *g:ale_cpp_clangd_executable*
*b:ale_cpp_clangd_executable*
Type: |String|
Default: `'clangd'`
This variable can be changed to use a different executable for clangd.
g:ale_cpp_clangd_options *g:ale_cpp_clangd_options*
*b:ale_cpp_clangd_options*
Type: |String|
Default: `''`
This variable can be changed to modify flags given to clangd.
===============================================================================
clang-format *ale-cpp-clangformat*
@ -295,61 +334,11 @@ g:ale_cpp_flawfinder_options *g:ale-cpp-flawfinder*
This variable can be used to pass extra options into the flawfinder command.
===============================================================================
gcc *ale-cpp-gcc*
g:ale_cpp_gcc_executable *g:ale_cpp_gcc_executable*
*b:ale_cpp_gcc_executable*
Type: |String|
Default: `'gcc'`
This variable can be changed to use a different executable for gcc.
g:ale_cpp_gcc_options *g:ale_cpp_gcc_options*
*b:ale_cpp_gcc_options*
Type: |String|
Default: `'-std=c++14 -Wall'`
This variable can be changed to modify flags given to gcc.
===============================================================================
uncrustify *ale-cpp-uncrustify*
See |ale-c-uncrustify| for information about the available options.
===============================================================================
ccls *ale-cpp-ccls*
g:ale_cpp_ccls_executable *g:ale_cpp_ccls_executable*
*b:ale_cpp_ccls_executable*
Type: |String|
Default: `'ccls'`
This variable can be changed to use a different executable for ccls.
g:ale_cpp_ccls_init_options *g:ale_cpp_ccls_init_options*
*b:ale_cpp_ccls_init_options*
Type: |Dictionary|
Default: `{}`
This variable can be changed to customize ccls initialization options.
Example: >
{
\ 'cacheDirectory': '/tmp/ccls',
\ 'cacheFormat': 'binary',
\ 'diagnostics': {
\ 'onOpen': 0,
\ 'opChange': 1000,
\ },
\ }
<
Visit https://github.com/MaskRay/ccls/wiki/Initialization-options for all
available options and explanations.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -48,7 +48,7 @@ Notes:
* C
* `astyle`
* `ccls`
* `clang`
* `clang` (`cc`)
* `clangd`
* `clang-format`
* `clangtidy`!!
@ -56,7 +56,7 @@ Notes:
* `cpplint`!!
* `cquery`
* `flawfinder`
* `gcc`
* `gcc` (`cc`)
* `uncrustify`
* C#
* `csc`!!
@ -66,7 +66,7 @@ Notes:
* C++ (filetype cpp)
* `astyle`
* `ccls`
* `clang`
* `clang` (`cc`)
* `clangcheck`!!
* `clangd`
* `clang-format`
@ -76,7 +76,7 @@ Notes:
* `cpplint`!!
* `cquery`
* `flawfinder`
* `gcc`
* `gcc` (`cc`)
* `uncrustify`
* Chef
* `cookstyle`

View File

@ -2322,16 +2322,15 @@ documented in additional help files.
bibclean..............................|ale-bib-bibclean|
c.......................................|ale-c-options|
astyle................................|ale-c-astyle|
clang.................................|ale-c-clang|
cc....................................|ale-c-cc|
ccls..................................|ale-c-ccls|
clangd................................|ale-c-clangd|
clang-format..........................|ale-c-clangformat|
clangtidy.............................|ale-c-clangtidy|
cppcheck..............................|ale-c-cppcheck|
cquery................................|ale-c-cquery|
flawfinder............................|ale-c-flawfinder|
gcc...................................|ale-c-gcc|
uncrustify............................|ale-c-uncrustify|
ccls..................................|ale-c-ccls|
chef....................................|ale-chef-options|
cookstyle.............................|ale-chef-cookstyle|
foodcritic............................|ale-chef-foodcritic|
@ -2345,9 +2344,10 @@ documented in additional help files.
cmake-format..........................|ale-cmake-cmakeformat|
cpp.....................................|ale-cpp-options|
astyle................................|ale-cpp-astyle|
clang.................................|ale-cpp-clang|
clangd................................|ale-cpp-clangd|
cc....................................|ale-cpp-cc|
ccls..................................|ale-cpp-ccls|
clangcheck............................|ale-cpp-clangcheck|
clangd................................|ale-cpp-clangd|
clang-format..........................|ale-cpp-clangformat|
clangtidy.............................|ale-cpp-clangtidy|
clazy.................................|ale-cpp-clazy|
@ -2355,9 +2355,7 @@ documented in additional help files.
cpplint...............................|ale-cpp-cpplint|
cquery................................|ale-cpp-cquery|
flawfinder............................|ale-cpp-flawfinder|
gcc...................................|ale-cpp-gcc|
uncrustify............................|ale-cpp-uncrustify|
ccls..................................|ale-cpp-ccls|
c#......................................|ale-cs-options|
csc...................................|ale-cs-csc|
mcs...................................|ale-cs-mcs|

View File

@ -1,16 +1,25 @@
Before:
Save g:ale_c_parse_makefile
Save g:ale_history_enabled
let g:ale_c_parse_makefile = 0
let g:ale_history_enabled = 0
let g:get_cflags_return_value = ''
let g:executable_map = {}
runtime autoload/ale/c.vim
runtime autoload/ale/engine.vim
function! ale#engine#IsExecutable(buffer, executable) abort
return has_key(g:executable_map, a:executable)
endfunction
function! ale#c#GetCFlags(buffer, output) abort
return g:get_cflags_return_value
endfunction
let g:ale_c_parse_makefile = 0
call ale#assert#SetUpLinterTest('c', 'gcc')
call ale#assert#SetUpLinterTest('c', 'cc')
let b:command_tail = ' -S -x c'
\ . ' -o ' . (has('win32') ? 'nul': '/dev/null')
@ -19,16 +28,23 @@ Before:
After:
unlet! g:get_cflags_return_value
unlet! g:executable_map
unlet! b:command_tail
runtime autoload/ale/c.vim
runtime autoload/ale/engine.vim
call ale#assert#TearDownLinterTest()
Execute(clang should be used instead of gcc, if available):
let g:executable_map = {'clang': 1}
AssertLinter 'clang', [ale#Escape('clang') . b:command_tail]
Execute(The executable should be configurable):
AssertLinter 'gcc', [ale#Escape('gcc') . b:command_tail]
let b:ale_c_gcc_executable = 'foobar'
let b:ale_c_cc_executable = 'foobar'
AssertLinter 'foobar', [ale#Escape('foobar') . b:command_tail]

View File

@ -1,37 +0,0 @@
Before:
Save g:ale_c_parse_makefile
let g:ale_c_parse_makefile = 0
let g:get_cflags_return_value = ''
runtime autoload/ale/c.vim
function! ale#c#GetCFlags(buffer, output) abort
return g:get_cflags_return_value
endfunction
call ale#assert#SetUpLinterTest('c', 'clang')
let b:command_tail = ' -S -x c -fsyntax-only -iquote'
\ . ' ' . ale#Escape(getcwd())
\ . ' -std=c11 -Wall -'
After:
unlet! g:get_cflags_return_value
unlet! b:command_tail
runtime autoload/ale/c.vim
call ale#assert#TearDownLinterTest()
Execute(The executable should be configurable):
AssertLinter 'clang', [ale#Escape('clang') . b:command_tail]
let b:ale_c_clang_executable = 'foobar'
AssertLinter 'foobar', [ale#Escape('foobar') . b:command_tail]
Execute(The -std flag should be replaced by parsed C flags):
let b:command_tail = substitute(b:command_tail, 'c11', 'c99 ', '')
let g:get_cflags_return_value = '-std=c99'
AssertLinter 'clang', ale#Escape('clang') . b:command_tail

View File

@ -7,6 +7,7 @@ Before:
Save g:__ale_c_project_filenames
let g:original_project_filenames = g:__ale_c_project_filenames
let g:executable_map = {}
" Remove the .git/HEAD dir for C import paths for these tests.
" The tests run inside of a git repo.
@ -18,17 +19,26 @@ Before:
let g:ale_c_parse_compile_commands = 0
let g:ale_c_parse_makefile = 0
runtime autoload/ale/engine.vim
function! ale#engine#IsExecutable(buffer, executable) abort
return has_key(g:executable_map, a:executable)
endfunction
After:
Restore
unlet! g:original_project_filenames
unlet! g:executable_map
runtime autoload/ale/engine.vim
call ale#assert#TearDownLinterTest()
Execute(The C GCC handler should include 'include' directories for projects with a Makefile):
call ale#assert#SetUpLinterTest('c', 'gcc')
Execute(The C cc linter should include 'include' directories for projects with a Makefile):
call ale#assert#SetUpLinterTest('c', 'cc')
call ale#test#SetFilename('../test_c_projects/makefile_project/subdir/file.c')
let g:ale_c_gcc_options = ''
let g:ale_c_cc_options = ''
AssertLinter 'gcc',
\ ale#Escape('gcc')
@ -37,10 +47,10 @@ Execute(The C GCC handler should include 'include' directories for projects with
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/makefile_project/include'))
\ . ' -'
Execute(The C GCC handler should include 'include' directories for projects with a configure file):
call ale#assert#SetUpLinterTest('c', 'gcc')
Execute(The C cc linter should include 'include' directories for projects with a configure file):
call ale#assert#SetUpLinterTest('c', 'cc')
call ale#test#SetFilename('../test_c_projects/configure_project/subdir/file.c')
let g:ale_c_gcc_options = ''
let g:ale_c_cc_options = ''
AssertLinter 'gcc',
\ ale#Escape('gcc')
@ -49,10 +59,10 @@ Execute(The C GCC handler should include 'include' directories for projects with
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/configure_project/include'))
\ . ' -'
Execute(The C GCC handler should include root directories for projects with .h files in them):
call ale#assert#SetUpLinterTest('c', 'gcc')
Execute(The C cc linter should include root directories for projects with .h files in them):
call ale#assert#SetUpLinterTest('c', 'cc')
call ale#test#SetFilename('../test_c_projects/h_file_project/subdir/file.c')
let g:ale_c_gcc_options = ''
let g:ale_c_cc_options = ''
AssertLinter 'gcc',
\ ale#Escape('gcc')
@ -61,10 +71,10 @@ Execute(The C GCC handler should include root directories for projects with .h f
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/h_file_project'))
\ . ' -'
Execute(The C GCC handler should include root directories for projects with .hpp files in them):
call ale#assert#SetUpLinterTest('c', 'gcc')
Execute(The C cc linter should include root directories for projects with .hpp files in them):
call ale#assert#SetUpLinterTest('c', 'cc')
call ale#test#SetFilename('../test_c_projects/hpp_file_project/subdir/file.c')
let g:ale_c_gcc_options = ''
let g:ale_c_cc_options = ''
AssertLinter 'gcc',
\ ale#Escape('gcc')
@ -73,54 +83,6 @@ Execute(The C GCC handler should include root directories for projects with .hpp
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/hpp_file_project'))
\ . ' -'
Execute(The C Clang handler should include 'include' directories for projects with a Makefile):
call ale#assert#SetUpLinterTest('c', 'clang')
call ale#test#SetFilename('../test_c_projects/makefile_project/subdir/file.c')
let g:ale_c_clang_options = ''
AssertLinter 'clang',
\ ale#Escape('clang')
\ . ' -S -x c -fsyntax-only'
\ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/makefile_project/subdir'))
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/makefile_project/include'))
\ . ' -'
Execute(The C Clang handler should include 'include' directories for projects with a configure file):
call ale#assert#SetUpLinterTest('c', 'clang')
call ale#test#SetFilename('../test_c_projects/h_file_project/subdir/file.c')
let g:ale_c_clang_options = ''
AssertLinter 'clang',
\ ale#Escape('clang')
\ . ' -S -x c -fsyntax-only'
\ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/h_file_project/subdir'))
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/h_file_project'))
\ . ' -'
Execute(The C Clang handler should include root directories for projects with .h files in them):
call ale#assert#SetUpLinterTest('c', 'clang')
call ale#test#SetFilename('../test_c_projects/h_file_project/subdir/file.c')
let g:ale_c_clang_options = ''
AssertLinter 'clang',
\ ale#Escape('clang')
\ . ' -S -x c -fsyntax-only'
\ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/h_file_project/subdir'))
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/h_file_project'))
\ . ' -'
Execute(The C Clang handler should include root directories for projects with .hpp files in them):
call ale#assert#SetUpLinterTest('c', 'clang')
call ale#test#SetFilename('../test_c_projects/hpp_file_project/subdir/file.c')
let g:ale_c_clang_options = ''
AssertLinter 'clang',
\ ale#Escape('clang')
\ . ' -S -x c -fsyntax-only'
\ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/hpp_file_project/subdir'))
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/hpp_file_project'))
\ . ' -'
Execute(The C ClangTidy handler should include 'include' directories for projects with a Makefile):
call ale#assert#SetUpLinterTest('c', 'clangtidy')
call ale#test#SetFilename('../test_c_projects/makefile_project/subdir/file.cpp')
@ -131,10 +93,10 @@ Execute(The C ClangTidy handler should include 'include' directories for project
\ . ' %s '
\ . '-- -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/makefile_project/include'))
Execute(The C++ GCC handler should include 'include' directories for projects with a Makefile):
call ale#assert#SetUpLinterTest('cpp', 'gcc')
Execute(The C++ cc linter should include 'include' directories for projects with a Makefile):
call ale#assert#SetUpLinterTest('cpp', 'cc')
call ale#test#SetFilename('../test_c_projects/makefile_project/subdir/file.cpp')
let g:ale_cpp_gcc_options = ''
let g:ale_cpp_cc_options = ''
AssertLinter 'gcc',
\ ale#Escape('gcc')
@ -143,10 +105,10 @@ Execute(The C++ GCC handler should include 'include' directories for projects wi
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/makefile_project/include'))
\ . ' -'
Execute(The C++ GCC handler should include 'include' directories for projects with a configure file):
call ale#assert#SetUpLinterTest('cpp', 'gcc')
Execute(The C++ cc linter should include 'include' directories for projects with a configure file):
call ale#assert#SetUpLinterTest('cpp', 'cc')
call ale#test#SetFilename('../test_c_projects/configure_project/subdir/file.cpp')
let g:ale_cpp_gcc_options = ''
let g:ale_cpp_cc_options = ''
AssertLinter 'gcc',
\ ale#Escape('gcc')
@ -155,10 +117,10 @@ Execute(The C++ GCC handler should include 'include' directories for projects wi
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/configure_project/include'))
\ . ' -'
Execute(The C++ GCC handler should include root directories for projects with .h files in them):
call ale#assert#SetUpLinterTest('cpp', 'gcc')
Execute(The C++ cc linter should include root directories for projects with .h files in them):
call ale#assert#SetUpLinterTest('cpp', 'cc')
call ale#test#SetFilename('../test_c_projects/h_file_project/subdir/file.cpp')
let g:ale_cpp_gcc_options = ''
let g:ale_cpp_cc_options = ''
AssertLinter 'gcc',
\ ale#Escape('gcc')
@ -167,10 +129,10 @@ Execute(The C++ GCC handler should include root directories for projects with .h
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/h_file_project'))
\ . ' -'
Execute(The C++ GCC handler should include root directories for projects with .hpp files in them):
call ale#assert#SetUpLinterTest('cpp', 'gcc')
Execute(The C++ cc linter should include root directories for projects with .hpp files in them):
call ale#assert#SetUpLinterTest('cpp', 'cc')
call ale#test#SetFilename('../test_c_projects/hpp_file_project/subdir/file.cpp')
let g:ale_cpp_gcc_options = ''
let g:ale_cpp_cc_options = ''
AssertLinter 'gcc',
\ ale#Escape('gcc')
@ -179,54 +141,6 @@ Execute(The C++ GCC handler should include root directories for projects with .h
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/hpp_file_project'))
\ . ' -'
Execute(The C++ Clang handler should include 'include' directories for projects with a Makefile):
call ale#assert#SetUpLinterTest('cpp', 'clang')
call ale#test#SetFilename('../test_c_projects/makefile_project/subdir/file.cpp')
let g:ale_cpp_clang_options = ''
AssertLinter 'clang++',
\ ale#Escape('clang++')
\ . ' -S -x c++ -fsyntax-only'
\ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/makefile_project/subdir'))
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/makefile_project/include'))
\ . ' -'
Execute(The C++ Clang handler should include 'include' directories for projects with a configure file):
call ale#assert#SetUpLinterTest('cpp', 'clang')
call ale#test#SetFilename('../test_c_projects/configure_project/subdir/file.cpp')
let g:ale_cpp_clang_options = ''
AssertLinter 'clang++',
\ ale#Escape('clang++')
\ . ' -S -x c++ -fsyntax-only'
\ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/configure_project/subdir'))
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/configure_project/include'))
\ . ' -'
Execute(The C++ Clang handler should include root directories for projects with .h files in them):
call ale#assert#SetUpLinterTest('cpp', 'clang')
call ale#test#SetFilename('../test_c_projects/h_file_project/subdir/file.cpp')
let g:ale_cpp_clang_options = ''
AssertLinter 'clang++',
\ ale#Escape('clang++')
\ . ' -S -x c++ -fsyntax-only'
\ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/h_file_project/subdir'))
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/h_file_project'))
\ . ' -'
Execute(The C++ Clang handler should include root directories for projects with .hpp files in them):
call ale#assert#SetUpLinterTest('cpp', 'clang')
call ale#test#SetFilename('../test_c_projects/hpp_file_project/subdir/file.cpp')
let g:ale_cpp_clang_options = ''
AssertLinter 'clang++',
\ ale#Escape('clang++')
\ . ' -S -x c++ -fsyntax-only'
\ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/hpp_file_project/subdir'))
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/../test_c_projects/hpp_file_project'))
\ . ' -'
Execute(The C++ ClangTidy handler should include json folders for projects with suitable build directory in them):
call ale#assert#SetUpLinterTest('cpp', 'clangtidy')
call ale#test#SetFilename('../test_c_projects/json_project/subdir/file.cpp')

View File

@ -1,37 +0,0 @@
Before:
Save g:ale_c_parse_makefile
let g:ale_c_parse_makefile = 0
let g:get_cflags_return_value = ''
runtime autoload/ale/c.vim
function! ale#c#GetCFlags(buffer, output) abort
return g:get_cflags_return_value
endfunction
call ale#assert#SetUpLinterTest('cpp', 'clang')
let b:command_tail = ' -S -x c++ -fsyntax-only -iquote'
\ . ' ' . ale#Escape(getcwd())
\ . ' -std=c++14 -Wall -'
After:
unlet! g:get_cflags_return_value
unlet! b:command_tail
runtime autoload/ale/c.vim
call ale#assert#TearDownLinterTest()
Execute(The executable should be configurable):
AssertLinter 'clang++', ale#Escape('clang++') . b:command_tail
let b:ale_cpp_clang_executable = 'foobar'
AssertLinter 'foobar', ale#Escape('foobar') . b:command_tail
Execute(The -std flag should be replaced by parsed C flags):
let b:command_tail = substitute(b:command_tail, 'c++14', 'c++11 ', '')
let g:get_cflags_return_value = '-std=c++11'
AssertLinter 'clang++', ale#Escape('clang++') . b:command_tail

View File

@ -1,16 +1,26 @@
Before:
Save g:ale_c_parse_makefile
Save g:ale_history_enabled
let g:ale_c_parse_makefile = 0
let g:ale_history_enabled = 0
let g:get_cflags_return_value = ''
let g:executable_map = {}
runtime autoload/ale/c.vim
runtime autoload/ale/engine.vim
function! ale#engine#IsExecutable(buffer, executable) abort
return has_key(g:executable_map, a:executable)
endfunction
function! ale#c#GetCFlags(buffer, output) abort
return g:get_cflags_return_value
endfunction
call ale#assert#SetUpLinterTest('cpp', 'gcc')
call ale#assert#SetUpLinterTest('cpp', 'cc')
let b:command_tail = ' -S -x c++'
\ . ' -o ' . (has('win32') ? 'nul': '/dev/null')
\ . ' -iquote ' . ale#Escape(getcwd())
@ -18,18 +28,25 @@ Before:
After:
unlet! g:get_cflags_return_value
unlet! g:executable_map
unlet! b:command_tail
runtime autoload/ale/c.vim
runtime autoload/ale/engine.vim
call ale#assert#TearDownLinterTest()
Execute(clang++ should be used instead of gcc, if available):
let g:executable_map = {'clang++': 1}
AssertLinter 'clang++', [ale#Escape('clang++') . b:command_tail]
Execute(The executable should be configurable):
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail
AssertLinter 'gcc', [ale#Escape('gcc') . b:command_tail]
let b:ale_cpp_gcc_executable = 'foobar'
let b:ale_cpp_cc_executable = 'foobar'
AssertLinter 'foobar', ale#Escape('foobar') . b:command_tail
AssertLinter 'foobar', [ale#Escape('foobar') . b:command_tail]
Execute(The -std flag should be replaced by parsed C flags):
let b:command_tail = substitute(b:command_tail, 'c++14', 'c++11 ', '')

View File

@ -1,8 +1,19 @@
Before:
Save g:ale_c_build_dir
Save g:ale_c_clangtidy_executable
Save g:ale_c_clangtidy_checks
Save g:ale_c_clangtidy_extra_options
Save g:ale_cpp_clangtidy_executable
Save g:ale_cpp_clangtidy_checks
Save g:ale_cpp_clangtidy_extra_options
" Use an invalid global executable, so we don't match it.
let g:ale_c_clangtidy_executable = 'xxxinvalid'
let g:ale_c_clangtidy_checks = []
let g:ale_c_clangtidy_extra_options = ''
let g:ale_cpp_clangtidy_executable = 'xxxinvalidpp'
let g:ale_cpp_clangtidy_checks = []
let g:ale_cpp_clangtidy_extra_options = ''
let g:ale_c_build_dir = ''
call ale#test#SetDirectory('/testplugin/test/fixers')
@ -36,16 +47,3 @@ Execute(The clangtidy callback should include any additional options):
\ . ' -fix -fix-errors --some-option %t',
\ },
\ ale#fixers#clangtidy#Fix(bufnr(''))
Execute(The clangtidy callback should support cpp files):
call ale#test#SetFilename('c_paths/dummy.cpp')
let g:ale_cpp_clangtidy_executable = 'invalidpp'
set filetype=cpp " The test fails without this
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_cpp_clangtidy_executable)
\ . ' -fix -fix-errors %t',
\ },
\ ale#fixers#clangtidy#Fix(bufnr(''))