mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-28 13:52:19 +08:00
Merge pull request #1434 from roel0/master
Automatically determine build flags by parsing `make -n` output #1167
This commit is contained in:
@@ -30,10 +30,10 @@ Execute(The executable should be configurable):
|
||||
Execute(The executable should be used in the command):
|
||||
AssertEqual
|
||||
\ ale#Escape('clang') . b:command_tail,
|
||||
\ ale_linters#c#clang#GetCommand(bufnr(''))
|
||||
\ ale_linters#c#clang#GetCommand(bufnr(''), [])
|
||||
|
||||
let b:ale_c_clang_executable = 'foobar'
|
||||
|
||||
AssertEqual
|
||||
\ ale#Escape('foobar') . b:command_tail,
|
||||
\ ale_linters#c#clang#GetCommand(bufnr(''))
|
||||
\ ale_linters#c#clang#GetCommand(bufnr(''), [])
|
||||
|
||||
@@ -30,10 +30,10 @@ Execute(The executable should be configurable):
|
||||
Execute(The executable should be used in the command):
|
||||
AssertEqual
|
||||
\ ale#Escape('gcc') . b:command_tail,
|
||||
\ ale_linters#c#gcc#GetCommand(bufnr(''))
|
||||
\ ale_linters#c#gcc#GetCommand(bufnr(''), [])
|
||||
|
||||
let b:ale_c_gcc_executable = 'foobar'
|
||||
|
||||
AssertEqual
|
||||
\ ale#Escape('foobar') . b:command_tail,
|
||||
\ ale_linters#c#gcc#GetCommand(bufnr(''))
|
||||
\ ale_linters#c#gcc#GetCommand(bufnr(''), [])
|
||||
|
||||
@@ -42,7 +42,7 @@ Execute(The C GCC handler should include 'include' directories for projects with
|
||||
\ . '-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')) . ' '
|
||||
\ . ' -'
|
||||
\ , ale_linters#c#gcc#GetCommand(bufnr(''))
|
||||
\ , ale_linters#c#gcc#GetCommand(bufnr(''), [])
|
||||
|
||||
Execute(The C GCC handler should include 'include' directories for projects with a configure file):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
@@ -55,7 +55,7 @@ Execute(The C GCC handler should include 'include' directories for projects with
|
||||
\ . '-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')) . ' '
|
||||
\ . ' -'
|
||||
\ , ale_linters#c#gcc#GetCommand(bufnr(''))
|
||||
\ , ale_linters#c#gcc#GetCommand(bufnr(''), [])
|
||||
|
||||
Execute(The C GCC handler should include root directories for projects with .h files in them):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
@@ -68,7 +68,7 @@ Execute(The C GCC handler should include root directories for projects with .h f
|
||||
\ . '-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')) . ' '
|
||||
\ . ' -'
|
||||
\ , ale_linters#c#gcc#GetCommand(bufnr(''))
|
||||
\ , ale_linters#c#gcc#GetCommand(bufnr(''), [])
|
||||
|
||||
Execute(The C GCC handler should include root directories for projects with .hpp files in them):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
@@ -81,7 +81,7 @@ Execute(The C GCC handler should include root directories for projects with .hpp
|
||||
\ . '-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')) . ' '
|
||||
\ . ' -'
|
||||
\ , ale_linters#c#gcc#GetCommand(bufnr(''))
|
||||
\ , ale_linters#c#gcc#GetCommand(bufnr(''), [])
|
||||
|
||||
Execute(The C Clang handler should include 'include' directories for projects with a Makefile):
|
||||
runtime! ale_linters/c/clang.vim
|
||||
@@ -94,7 +94,7 @@ Execute(The C Clang handler should include 'include' directories for projects wi
|
||||
\ . '-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')) . ' '
|
||||
\ . ' -'
|
||||
\ , ale_linters#c#clang#GetCommand(bufnr(''))
|
||||
\ , ale_linters#c#clang#GetCommand(bufnr(''), [])
|
||||
|
||||
Execute(The C Clang handler should include 'include' directories for projects with a configure file):
|
||||
runtime! ale_linters/c/clang.vim
|
||||
@@ -107,7 +107,7 @@ Execute(The C Clang handler should include 'include' directories for projects wi
|
||||
\ . '-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')) . ' '
|
||||
\ . ' -'
|
||||
\ , ale_linters#c#clang#GetCommand(bufnr(''))
|
||||
\ , ale_linters#c#clang#GetCommand(bufnr(''), [])
|
||||
|
||||
Execute(The C Clang handler should include root directories for projects with .h files in them):
|
||||
runtime! ale_linters/c/clang.vim
|
||||
@@ -120,7 +120,7 @@ Execute(The C Clang handler should include root directories for projects with .h
|
||||
\ . '-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')) . ' '
|
||||
\ . ' -'
|
||||
\ , ale_linters#c#clang#GetCommand(bufnr(''))
|
||||
\ , ale_linters#c#clang#GetCommand(bufnr(''), [])
|
||||
|
||||
Execute(The C Clang handler should include root directories for projects with .hpp files in them):
|
||||
runtime! ale_linters/c/clang.vim
|
||||
@@ -133,7 +133,7 @@ Execute(The C Clang handler should include root directories for projects with .h
|
||||
\ . '-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')) . ' '
|
||||
\ . ' -'
|
||||
\ , ale_linters#c#clang#GetCommand(bufnr(''))
|
||||
\ , ale_linters#c#clang#GetCommand(bufnr(''), [])
|
||||
|
||||
Execute(The C++ GCC handler should include 'include' directories for projects with a Makefile):
|
||||
runtime! ale_linters/cpp/gcc.vim
|
||||
|
||||
184
test/test_c_parse_makefile.vader
Normal file
184
test/test_c_parse_makefile.vader
Normal file
@@ -0,0 +1,184 @@
|
||||
Before:
|
||||
Save g:ale_c_parse_makefile
|
||||
Save g:ale_c_gcc_options
|
||||
Save g:ale_c_clang_options
|
||||
Save g:ale_cpp_gcc_options
|
||||
Save g:ale_cpp_clang_options
|
||||
|
||||
call ale#test#SetDirectory('/testplugin/test')
|
||||
|
||||
let g:ale_c_parse_makefile=1
|
||||
let g:ale_c_gcc_options = ''
|
||||
let g:ale_c_clang_options = ''
|
||||
let g:ale_cpp_gcc_options = ''
|
||||
let g:ale_cpp_clang_options = ''
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
call ale#test#RestoreDirectory()
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The CFlags parser should be able to parse include directives):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
|
||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
||||
|
||||
AssertEqual
|
||||
\ [ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))]
|
||||
\ , ale#c#ParseCFlags(bufnr(''), 'gcc -Isubdir -c file.c')
|
||||
|
||||
Execute(The CFlags parser should be able to parse macro directives):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
|
||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
||||
|
||||
AssertEqual
|
||||
\ [ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')),
|
||||
\ '-DTEST=1']
|
||||
\ , ale#c#ParseCFlags(bufnr(''), 'gcc -Isubdir -DTEST=1 -c file.c')
|
||||
|
||||
Execute(The CFlags parser should be able to parse macro directives with spaces):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
|
||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
||||
|
||||
AssertEqual
|
||||
\ [ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')),
|
||||
\ '-DTEST=$(( 2 * 4 ))']
|
||||
\ , ale#c#ParseCFlags(bufnr(''), 'gcc -Isubdir -DTEST=$(( 2 * 4 )) -c file.c')
|
||||
|
||||
Execute(The CFlags parser should be able to parse shell directives with spaces):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
|
||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
||||
|
||||
AssertEqual
|
||||
\ [ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')),
|
||||
\ '-DTEST=`date +%s`']
|
||||
\ , ale#c#ParseCFlags(bufnr(''), 'gcc -Isubdir -DTEST=`date +%s` -c file.c')
|
||||
|
||||
Execute(The CFlagsToList parser should be able to parse multiple cflags):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
|
||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
||||
|
||||
AssertEqual
|
||||
\ [ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')),
|
||||
\ '-DTEST=`date +%s`']
|
||||
\ , ale#c#ParseCFlagsToList(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
||||
\ split('gcc -Isubdir -DTEST=`date +%s` -c file.c', '-'))
|
||||
|
||||
Execute(The CFlagsToList parser should be able to parse multiple cflags #2):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
|
||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
||||
|
||||
AssertEqual
|
||||
\ [ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')),
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')),
|
||||
\ '-DTEST=`date +%s`']
|
||||
\ , ale#c#ParseCFlagsToList(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
||||
\ split('gcc -Isubdir ' .
|
||||
\ '-I'. ale#path#Simplify('kernel/include') .
|
||||
\ ' -DTEST=`date +%s` -c file.c', '-'))
|
||||
|
||||
Execute(The CFlagsToList parser should be able to parse multiple cflags #3):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
|
||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
||||
|
||||
AssertEqual
|
||||
\ ['-Dgoal=9',
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')),
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')),
|
||||
\ '-DTEST=`date +%s`']
|
||||
\ , ale#c#ParseCFlagsToList(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
||||
\ split('gcc -Dgoal=9 -Isubdir ' .
|
||||
\ '-I'. ale#path#Simplify('kernel/include') .
|
||||
\ ' -DTEST=`date +%s` -c file.c', '-'))
|
||||
|
||||
Execute(The CFlagsToList parser should be able to parse multiple cflags #4):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
|
||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
||||
|
||||
AssertEqual
|
||||
\ ['-Dgoal=9',
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')),
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')),
|
||||
\ '-DTEST=`date +%s`']
|
||||
\ , ale#c#ParseCFlagsToList(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
||||
\ split('gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' .
|
||||
\ '-I'. ale#path#Simplify('kernel/include') .
|
||||
\ ' -DTEST=`date +%s` -c file.c', '-'))
|
||||
|
||||
Execute(The CFlagsToList parser should be able to parse multiple cflags #5):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
|
||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
||||
|
||||
AssertEqual
|
||||
\ ['-Dgoal=9',
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')),
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')),
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')),
|
||||
\ '-DTEST=`date +%s`']
|
||||
\ , ale#c#ParseCFlagsToList(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
||||
\ split('gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' .
|
||||
\ '-I"dir with spaces"' . ' -I'. ale#path#Simplify('kernel/include') .
|
||||
\ ' -DTEST=`date +%s` -c file.c', '-'))
|
||||
|
||||
Execute(The CFlagsToList parser should be able to parse multiple cflags #6):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
|
||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
||||
|
||||
AssertEqual
|
||||
\ ['-Dgoal=9',
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')),
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')),
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')),
|
||||
\ '-DTEST=`date +%s`']
|
||||
\ , ale#c#ParseCFlagsToList(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
||||
\ split('gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' .
|
||||
\ '-I''dir with spaces''' . ' -I'. ale#path#Simplify('kernel/include') .
|
||||
\ ' -DTEST=`date +%s` -c file.c', '-'))
|
||||
|
||||
Execute(The CFlagsToList parser should be able to parse multiple cflags #7):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
|
||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
||||
|
||||
AssertEqual
|
||||
\ ['-Dgoal=9',
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')),
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')),
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash')),
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')),
|
||||
\ '-DTEST=`date +%s`']
|
||||
\ , ale#c#ParseCFlagsToList(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
||||
\ split('gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' .
|
||||
\ '-I''dir with spaces''' . ' -Idir-with-dash' .
|
||||
\ ' -I'. ale#path#Simplify('kernel/include') .
|
||||
\ ' -DTEST=`date +%s` -c file.c', '-'))
|
||||
|
||||
Execute(The CFlagsToList parser should be able to parse multiple cflags #8):
|
||||
runtime! ale_linters/c/gcc.vim
|
||||
|
||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
||||
|
||||
AssertEqual
|
||||
\ ['-Dgoal=9',
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')),
|
||||
\ '-Dmacro-with-dash',
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')),
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash')),
|
||||
\ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')),
|
||||
\ '-DTEST=`date +%s`']
|
||||
\ , ale#c#ParseCFlagsToList(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
||||
\ split('gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' .
|
||||
\ '-Dmacro-with-dash ' .
|
||||
\ '-I''dir with spaces''' . ' -Idir-with-dash' .
|
||||
\ ' -I'. ale#path#Simplify('kernel/include') .
|
||||
\ ' -DTEST=`date +%s` -c file.c', '-'))
|
||||
0
test/test_c_projects/makefile_project/subdir/file.c
Normal file
0
test/test_c_projects/makefile_project/subdir/file.c
Normal file
Reference in New Issue
Block a user