1b3fa9828c
There is currently a check that tries to prevent c-flags that contain '-' in them from being unintentionally split and included in the list of commands. For example, we wouldn't want "-fno-exceptions " to appear as "-fno" and "-exceptions ". The way this check was done was by making sure the last character of the split string was a space. This meant that the very last option to appear in the compile command was ignored (as it doesn't end with a space). This fix explicitly skips the ends-with-space check on the last option in the command-line. This isn't the best fix. Really we should be using the same argument-processing rules as a shell would rather than just splitting on '-'. That's a much larger and more complicated change though.
179 lines
8.2 KiB
Text
179 lines
8.2 KiB
Text
Before:
|
|
Save g:ale_c_parse_makefile
|
|
|
|
call ale#test#SetDirectory('/testplugin/test')
|
|
|
|
let g:ale_c_parse_makefile = 1
|
|
|
|
After:
|
|
Restore
|
|
|
|
call ale#test#RestoreDirectory()
|
|
|
|
Execute(The CFlags parser should be able to parse include directives):
|
|
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#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -c file.c'])
|
|
|
|
Execute(The CFlags parser should be able to parse macro directives):
|
|
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#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=1 -c file.c'])
|
|
|
|
Execute(The CFlags parser should be able to parse macro directives with spaces):
|
|
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#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=$(( 2 * 4 )) -c file.c'])
|
|
|
|
Execute(The CFlags parser should be able to parse shell directives with spaces):
|
|
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#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=`date +%s` -c file.c'])
|
|
|
|
Execute(ParseCFlags should be able to parse flags with relative paths):
|
|
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#ParseCFlags(
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
|
\ 'gcc -Isubdir '
|
|
\ . '-I'. ale#path#Simplify('kernel/include')
|
|
\ . ' -DTEST=`date +%s` -c file.c'
|
|
\ )
|
|
|
|
Execute(ParseCFlags should be able to parse -Dgoal):
|
|
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#ParseCFlags(
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
|
\ 'gcc -Dgoal=9 -Isubdir '
|
|
\ . '-I'. ale#path#Simplify('kernel/include')
|
|
\ . ' -DTEST=`date +%s` -c file.c'
|
|
\ )
|
|
|
|
Execute(ParseCFlags should ignore -T and other arguments):
|
|
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#ParseCFlags(
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
|
\ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir --sysroot=subdir '
|
|
\ . '-I'. ale#path#Simplify('kernel/include')
|
|
\ . ' -DTEST=`date +%s` -c file.c'
|
|
\ )
|
|
|
|
Execute(ParseCFlags should handle paths with spaces in double quotes):
|
|
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#ParseCFlags(
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
|
\ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
|
|
\ . '-I"dir with spaces"' . ' -I'. ale#path#Simplify('kernel/include')
|
|
\ . ' -DTEST=`date +%s` -c file.c'
|
|
\ )
|
|
|
|
Execute(ParseCFlags should handle paths with spaces in single quotes):
|
|
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#ParseCFlags(
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
|
\ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
|
|
\ . '-I''dir with spaces''' . ' -I'. ale#path#Simplify('kernel/include')
|
|
\ . ' -DTEST=`date +%s` -c file.c'
|
|
\ )
|
|
|
|
Execute(ParseCFlags should handle paths with minuses):
|
|
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#ParseCFlags(
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
|
\ '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(ParseCFlags should handle -D with minuses):
|
|
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#ParseCFlags(
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
|
\ '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'
|
|
\ )
|
|
|
|
Execute(ParseCFlags should handle flags at the end of the line):
|
|
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')),
|
|
\ ale#c#ParseCFlags(
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
|
\ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
|
|
\ . '-Dmacro-with-dash '
|
|
\ . '-I''dir with spaces''' . ' -Idir-with-dash'
|
|
\ . ' -I'. ale#path#Simplify('kernel/include')
|
|
\ )
|
|
|
|
Execute(FlagsFromCompileCommands should tolerate empty values):
|
|
AssertEqual '', ale#c#FlagsFromCompileCommands(bufnr(''), '')
|
|
|
|
Execute(ParseCompileCommandsFlags should tolerate empty values):
|
|
AssertEqual '', ale#c#ParseCompileCommandsFlags(bufnr(''), '', [])
|
|
|
|
Execute(ParseCompileCommandsFlags should parse some basic flags):
|
|
noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'))
|
|
|
|
AssertEqual
|
|
\ '-I' . ale#path#Simplify('/usr/include/xmms2'),
|
|
\ ale#c#ParseCompileCommandsFlags(bufnr(''), ale#path#Simplify('/foo/bar/xmms2-mpris'), [
|
|
\ {
|
|
\ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'),
|
|
\ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2')
|
|
\ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
|
|
\ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
|
|
\ 'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
|
|
\ },
|
|
\ ])
|