cc: fix using '-x c*-header' for header files with GCC. (#4334)

Gcc does not support `x c*-header` when using `-` as input filename,
which is what ALE does.

Rework the feature to only use `-x c*-header` flag when using Clang and
not GCC.

The feature is now also controlled with the variable
`g:ale_c_cc_use_header_lang_flag` and
`g:ale_cpp_cc_use_header_lang_flag`.
This commit is contained in:
Nicolas Pauss
2022-10-12 00:05:37 +02:00
committed by GitHub
parent f085227504
commit 951a668b14
7 changed files with 161 additions and 21 deletions

View File

@@ -54,18 +54,41 @@ Execute(The -std flag should be replaced by parsed C flags):
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail
Execute(The header files should use -x c-header):
Execute(gcc should not use -x c-header with header files by default):
call ale#test#SetFilename('../test-files/c/makefile_project/subdir/test.h')
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail
Execute(clang should use -x c-header with header files by default):
let g:executable_map = {'clang': 1}
let b:command_tail = substitute(b:command_tail, '-x c', '-x c-header', '')
call ale#test#SetFilename('../test-files/c/makefile_project/subdir/test.h')
AssertLinter 'clang', ale#Escape('clang') . b:command_tail
Execute(gcc should use -x c-header with header files if configured to do so):
let b:ale_c_cc_use_header_lang_flag = 1
let b:command_tail = substitute(b:command_tail, '-x c', '-x c-header', '')
call ale#test#SetFilename('../test-files/c/makefile_project/subdir/test.h')
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail
Execute(clang should not use -x c-header with header files if configured to do so):
let g:executable_map = {'clang': 1}
let b:ale_c_cc_use_header_lang_flag = 0
call ale#test#SetFilename('../test-files/c/makefile_project/subdir/test.h')
AssertLinter 'clang', ale#Escape('clang') . b:command_tail
Execute(The header file extensions should be configurable):
let g:executable_map = {'clang': 1}
let b:command_tail = substitute(b:command_tail, '-x c', '-x c-header', '')
call ale#assert#SetUpLinterTest('c', 'cc')
let b:ale_c_cc_header_exts = ['json']
call ale#test#SetFilename('../test-files/c/json_project/build/compile_commands.json')
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail
AssertLinter 'clang', ale#Escape('clang') . b:command_tail

View File

@@ -54,18 +54,41 @@ Execute(The -std flag should be replaced by parsed C flags):
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail
Execute(The header files should use -x c++-header):
Execute(gcc should not use -x c++-header with header files by default):
call ale#test#SetFilename('../test-files/c/hpp_file_project/test.hpp')
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail
Execute(clang++ should use -x c++-header with header files by default):
let g:executable_map = {'clang++': 1}
let b:command_tail = substitute(b:command_tail, '-x c++', '-x c++-header', '')
call ale#test#SetFilename('../test-files/c/hpp_file_project/test.hpp')
AssertLinter 'clang++', ale#Escape('clang++') . b:command_tail
Execute(gcc should use -x c-header with header files if configured to do so):
let b:ale_cpp_cc_use_header_lang_flag = 1
let b:command_tail = substitute(b:command_tail, '-x c++', '-x c++-header', '')
call ale#test#SetFilename('../test-files/c/hpp_file_project/test.hpp')
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail
Execute(clang should not use -x c-header with header files if configured to do so):
let g:executable_map = {'clang++': 1}
let b:ale_cpp_cc_use_header_lang_flag = 0
call ale#test#SetFilename('../test-files/c/hpp_file_project/test.hpp')
AssertLinter 'clang++', ale#Escape('clang++') . b:command_tail
Execute(The header file extensions should be configurable):
let g:executable_map = {'clang++': 1}
let b:command_tail = substitute(b:command_tail, '-x c++', '-x c++-header', '')
call ale#assert#SetUpLinterTest('cpp', 'cc')
let b:ale_cpp_cc_header_exts = ['json']
call ale#test#SetFilename('../test-files/c/json_project/build/compile_commands.json')
AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail
AssertLinter 'clang++', ale#Escape('clang++') . b:command_tail