2018-07-29 18:24:19 +00:00
|
|
|
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
|
2019-01-22 02:45:17 +00:00
|
|
|
\ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'),
|
2018-07-29 18:24:19 +00:00
|
|
|
\ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -c file.c'])
|
|
|
|
|
2019-01-22 02:45:17 +00:00
|
|
|
AssertEqual
|
|
|
|
\ '-isystem ' . '/usr/include/dir',
|
|
|
|
\ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -isystem /usr/include/dir -c file.c'])
|
|
|
|
|
|
|
|
Execute(ParseCFlags should ignore -c and -o):
|
|
|
|
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'),
|
|
|
|
\ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -c file.c -o a.out'])
|
|
|
|
|
2018-07-29 18:24:19 +00:00
|
|
|
Execute(The CFlags parser should be able to parse macro directives):
|
|
|
|
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
|
|
|
|
|
|
|
AssertEqual
|
2019-01-22 02:45:17 +00:00
|
|
|
\ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . ' -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
|
2019-01-22 02:45:17 +00:00
|
|
|
\ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . ' -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
|
2019-01-22 02:45:17 +00:00
|
|
|
\ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . ' -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
|
2019-01-22 02:45:17 +00:00
|
|
|
\ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
|
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . ' -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'
|
2019-01-22 02:45:17 +00:00
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
|
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . ' -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 handle paths with spaces in double quotes):
|
|
|
|
AssertEqual
|
|
|
|
\ '-Dgoal=9'
|
2019-01-22 02:45:17 +00:00
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
|
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/"dir with spaces"')
|
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . ' -DTEST=`date +%s`',
|
|
|
|
\ ale#c#ParseCFlags(
|
|
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
2019-01-22 02:45:17 +00:00
|
|
|
\ 'gcc -Dgoal=9 -Isubdir '
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . '-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'
|
2019-01-22 02:45:17 +00:00
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
|
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. "/test_c_projects/makefile_project/'dir with spaces'")
|
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . ' -DTEST=`date +%s`',
|
|
|
|
\ ale#c#ParseCFlags(
|
|
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
2019-01-22 02:45:17 +00:00
|
|
|
\ 'gcc -Dgoal=9 -Isubdir '
|
|
|
|
\ . "-I'dir with spaces'" . ' -I'. ale#path#Simplify('kernel/include')
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . ' -DTEST=`date +%s` -c file.c'
|
|
|
|
\ )
|
|
|
|
|
|
|
|
Execute(ParseCFlags should handle paths with minuses):
|
|
|
|
AssertEqual
|
|
|
|
\ '-Dgoal=9'
|
2019-01-22 02:45:17 +00:00
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
|
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash')
|
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . ' -DTEST=`date +%s`',
|
|
|
|
\ ale#c#ParseCFlags(
|
|
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
2019-01-22 02:45:17 +00:00
|
|
|
\ 'gcc -Dgoal=9 -Isubdir '
|
|
|
|
\ . ' -Idir-with-dash'
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . ' -I'. ale#path#Simplify('kernel/include')
|
|
|
|
\ . ' -DTEST=`date +%s` -c file.c'
|
|
|
|
\ )
|
|
|
|
|
|
|
|
Execute(ParseCFlags should handle -D with minuses):
|
|
|
|
AssertEqual
|
|
|
|
\ '-Dgoal=9'
|
2019-01-22 02:45:17 +00:00
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . ' -Dmacro-with-dash'
|
2019-01-22 02:45:17 +00:00
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . ' -DTEST=`date +%s`',
|
|
|
|
\ ale#c#ParseCFlags(
|
|
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
2019-01-22 02:45:17 +00:00
|
|
|
\ 'gcc -Dgoal=9 -Isubdir '
|
2018-07-29 18:24:19 +00:00
|
|
|
\ . '-Dmacro-with-dash '
|
|
|
|
\ . ' -I'. ale#path#Simplify('kernel/include')
|
|
|
|
\ . ' -DTEST=`date +%s` -c file.c'
|
|
|
|
\ )
|
|
|
|
|
2018-09-11 01:46:18 +00:00
|
|
|
Execute(ParseCFlags should handle flags at the end of the line):
|
|
|
|
AssertEqual
|
|
|
|
\ '-Dgoal=9'
|
2019-01-22 02:45:17 +00:00
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
|
|
|
|
\ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include'),
|
2018-09-11 01:46:18 +00:00
|
|
|
\ ale#c#ParseCFlags(
|
|
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
2019-01-22 02:45:17 +00:00
|
|
|
\ 'gcc -Dgoal=9 -Isubdir '
|
2018-09-11 01:46:18 +00:00
|
|
|
\ . ' -I'. ale#path#Simplify('kernel/include')
|
|
|
|
\ )
|
|
|
|
|
2018-07-29 18:24:19 +00:00
|
|
|
Execute(FlagsFromCompileCommands should tolerate empty values):
|
|
|
|
AssertEqual '', ale#c#FlagsFromCompileCommands(bufnr(''), '')
|
|
|
|
|
|
|
|
Execute(ParseCompileCommandsFlags should tolerate empty values):
|
2019-01-07 02:17:32 +00:00
|
|
|
AssertEqual '', ale#c#ParseCompileCommandsFlags(bufnr(''), {}, {})
|
2018-07-29 18:24:19 +00:00
|
|
|
|
|
|
|
Execute(ParseCompileCommandsFlags should parse some basic flags):
|
2018-07-29 18:30:12 +00:00
|
|
|
noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'))
|
2018-07-29 18:24:19 +00:00
|
|
|
|
|
|
|
AssertEqual
|
2019-01-22 02:45:17 +00:00
|
|
|
\ '-I' . '/usr/include/xmms2',
|
2019-01-07 02:17:32 +00:00
|
|
|
\ ale#c#ParseCompileCommandsFlags(bufnr(''), { "xmms2-mpris.c": [
|
2018-07-29 18:24:19 +00:00
|
|
|
\ {
|
2019-01-22 02:45:17 +00:00
|
|
|
\ 'directory': '/foo/bar/xmms2-mpris',
|
|
|
|
\ 'command': '/usr/bin/cc -I' . '/usr/include/xmms2'
|
2018-07-29 18:30:12 +00:00
|
|
|
\ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
|
2019-01-22 02:45:17 +00:00
|
|
|
\ . ' -c ' . '/foo/bar/xmms2-mpris/src/xmms2-mpris.c',
|
|
|
|
\ 'file': '/foo/bar/xmms2-mpris/src/xmms2-mpris.c',
|
2018-07-29 18:24:19 +00:00
|
|
|
\ },
|
2018-12-17 04:47:35 +00:00
|
|
|
\ ] }, {})
|
|
|
|
|
|
|
|
Execute(ParseCompileCommandsFlags should fall back to files in the same directory):
|
|
|
|
noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'))
|
|
|
|
|
|
|
|
AssertEqual
|
2019-01-22 02:45:17 +00:00
|
|
|
\ '-I' . '/usr/include/xmms2',
|
2019-01-07 02:17:32 +00:00
|
|
|
\ ale#c#ParseCompileCommandsFlags(bufnr(''), {}, { "src": [
|
2018-12-17 04:47:35 +00:00
|
|
|
\ {
|
2019-01-22 02:45:17 +00:00
|
|
|
\ 'directory': '/foo/bar/xmms2-mpris',
|
|
|
|
\ 'command': '/usr/bin/cc -I' . '/usr/include/xmms2'
|
2018-12-17 04:47:35 +00:00
|
|
|
\ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
|
2019-01-22 02:45:17 +00:00
|
|
|
\ . ' -c ' . '/foo/bar/xmms2-mpris/src/xmms2-mpris.c',
|
|
|
|
\ 'file': (has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c',
|
2018-12-17 04:47:35 +00:00
|
|
|
\ },
|
|
|
|
\ ] })
|
2018-12-29 11:13:23 +00:00
|
|
|
|
2019-01-09 15:39:05 +00:00
|
|
|
Execute(ParseCFlags should handle parenthesis and quotes):
|
|
|
|
AssertEqual
|
2019-01-22 02:45:17 +00:00
|
|
|
\ '-Dgoal=9 -Dtest1="('' '')" file1.o -Dtest2=''(` `)'' file2.o -Dtest3=`(" ")` file3.o',
|
2019-01-09 15:39:05 +00:00
|
|
|
\ ale#c#ParseCFlags(
|
|
|
|
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
|
2019-01-22 02:45:17 +00:00
|
|
|
\ 'gcc -Dgoal=9 '
|
2019-01-09 15:39:05 +00:00
|
|
|
\ . '-Dtest1="('' '')" file1.o '
|
|
|
|
\ . '-Dtest2=''(` `)'' file2.o '
|
|
|
|
\ . '-Dtest3=`(" ")` file3.o '
|
|
|
|
\ )
|