]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/test_c_flag_parsing.vader

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / test / test_c_flag_parsing.vader
1 Before:
2   Save g:ale_c_parse_makefile
3   Save g:ale_c_always_make
4   Save b:ale_c_always_make
5
6   call ale#test#SetDirectory('/testplugin/test')
7
8   let g:ale_c_parse_makefile = 1
9   let g:ale_c_always_make = 1
10   let b:ale_c_always_make = 1
11
12   function SplitAndParse(path_prefix, command) abort
13     let l:args = ale#c#ShellSplit(a:command)
14
15     return ale#c#ParseCFlags(a:path_prefix, 0, l:args)
16   endfunction
17
18 After:
19   delfunction SplitAndParse
20
21   Restore
22
23   call ale#test#RestoreDirectory()
24
25 Execute(The make command should be correct):
26   call ale#test#SetFilename('test-files/c/makefile_project/subdir/file.c')
27
28   AssertEqual
29   \ [
30   \   ale#path#Simplify(g:dir. '/test-files/c/makefile_project'),
31   \   'make -n --always-make',
32   \ ],
33   \ ale#c#GetMakeCommand(bufnr(''))
34
35   " You should be able to disable --always-make for a buffer.
36   let b:ale_c_always_make = 0
37
38   AssertEqual
39   \ [
40   \   ale#path#Simplify(g:dir. '/test-files/c/makefile_project'),
41   \   'make -n',
42   \ ],
43   \ ale#c#GetMakeCommand(bufnr(''))
44
45 Execute(Should recognize GNUmakefile as a makefile):
46   call ale#test#SetFilename('test-files/c/gnumakefile_project/file.c')
47
48   AssertEqual
49   \ [
50   \   ale#path#Simplify(g:dir. '/test-files/c/gnumakefile_project'),
51   \   'make -n --always-make',
52   \ ],
53   \ ale#c#GetMakeCommand(bufnr(''))
54
55 Execute(The CFlags parser should be able to parse include directives):
56   call ale#test#SetFilename('test-files/c/makefile_project/subdir/file.c')
57
58   AssertEqual
59   \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/subdir')),
60   \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -c file.c'])
61
62   AssertEqual
63   \ '-isystem ' . ale#Escape('/usr/include/dir'),
64   \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -isystem /usr/include/dir -c file.c'])
65
66 Execute(ParseCFlags should ignore -c and -o):
67   call ale#test#SetFilename('test-files/c/makefile_project/subdir/file.c')
68
69   AssertEqual
70   \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/subdir')),
71   \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -c file.c -o a.out'])
72
73 Execute(The CFlags parser should be able to parse macro directives):
74   call ale#test#SetFilename('test-files/c/makefile_project/subdir/file.c')
75
76   AssertEqual
77   \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/subdir'))
78   \   . ' -DTEST=1',
79   \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=1 -c file.c'])
80
81 Execute(The CFlags parser should be able to parse macro directives with spaces):
82   call ale#test#SetFilename('test-files/c/makefile_project/subdir/file.c')
83
84   AssertEqual
85   \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/subdir'))
86   \   . ' -DTEST=$(( 2 * 4 ))',
87   \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=$(( 2 * 4 )) -c file.c'])
88
89 Execute(The CFlags parser should be able to parse shell directives with spaces):
90   call ale#test#SetFilename('test-files/c/makefile_project/subdir/file.c')
91
92   AssertEqual
93   \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/subdir'))
94   \   .  ' -DTEST=`date +%s`',
95   \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=`date +%s` -c file.c'])
96
97 Execute(ParseCFlags should be able to parse flags with relative paths):
98   AssertEqual
99   \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/subdir'))
100   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/kernel/include'))
101   \   . ' -DTEST=`date +%s`',
102   \ SplitAndParse(
103   \   ale#path#Simplify(g:dir. '/test-files/c/makefile_project'),
104   \   'gcc -Isubdir  '
105   \     .  '-I'. ale#path#Simplify('kernel/include')
106   \     .  ' -DTEST=`date +%s` -c file.c'
107   \ )
108
109 Execute(We should handle paths with spaces in double quotes):
110   AssertEqual
111   \ '-Dgoal=9'
112   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/subdir'))
113   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/dir with spaces'))
114   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/kernel/include'))
115   \   . ' -DTEST=`date +%s`',
116   \ SplitAndParse(
117   \   ale#path#Simplify(g:dir. '/test-files/c/makefile_project'),
118   \   'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
119   \     . '-I"dir with spaces"' . ' -I'. ale#path#Simplify('kernel/include')
120   \     . ' -DTEST=`date +%s` -c file.c'
121   \ )
122
123 Execute(ParseCFlags should handle paths with spaces in single quotes):
124   AssertEqual
125   \ '-Dgoal=9'
126   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/subdir'))
127   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/dir with spaces'))
128   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/kernel/include'))
129   \   . ' -DTEST=`date +%s`',
130   \ SplitAndParse(
131   \   ale#path#Simplify(g:dir. '/test-files/c/makefile_project'),
132   \   'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
133   \     . '-I''dir with spaces''' . ' -I'. ale#path#Simplify('kernel/include')
134   \     . ' -DTEST=`date +%s` -c file.c'
135   \ )
136
137 Execute(ParseCFlags should handle paths with minuses):
138   AssertEqual
139   \ '-Dgoal=9'
140   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/subdir'))
141   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/dir with spaces'))
142   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/dir-with-dash'))
143   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/kernel/include'))
144   \   . ' -DTEST=`date +%s`',
145   \ SplitAndParse(
146   \   ale#path#Simplify(g:dir. '/test-files/c/makefile_project'),
147   \   'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
148   \     . '-I''dir with spaces''' . ' -Idir-with-dash'
149   \     . ' -I'. ale#path#Simplify('kernel/include')
150   \     . ' -DTEST=`date +%s` -c file.c'
151   \ )
152
153 Execute(We should handle -D with minuses):
154   AssertEqual
155   \ '-Dgoal=9'
156   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/subdir'))
157   \   . ' -Dmacro-with-dash'
158   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/dir with spaces'))
159   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/dir-with-dash'))
160   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/kernel/include'))
161   \   . ' -DTEST=`date +%s`',
162   \ SplitAndParse(
163   \   ale#path#Simplify(g:dir. '/test-files/c/makefile_project'),
164   \   'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
165   \     . '-Dmacro-with-dash '
166   \     . '-I''dir with spaces''' . ' -Idir-with-dash'
167   \     . ' -I'. ale#path#Simplify('kernel/include')
168   \     . ' -DTEST=`date +%s` -c file.c'
169   \ )
170
171 Execute(We should handle flags at the end of the line):
172   AssertEqual
173   \ '-Dgoal=9'
174   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/subdir'))
175   \   . ' -Dmacro-with-dash'
176   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/dir with spaces'))
177   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/dir-with-dash'))
178   \   . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/kernel/include')),
179   \ SplitAndParse(
180   \   ale#path#Simplify(g:dir. '/test-files/c/makefile_project'),
181   \   'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
182   \     . '-Dmacro-with-dash '
183   \     . '-I''dir with spaces''' . ' -Idir-with-dash'
184   \     . ' -I'. ale#path#Simplify('kernel/include')
185   \ )
186
187 Execute(FlagsFromCompileCommands should tolerate empty values):
188   AssertEqual '', ale#c#FlagsFromCompileCommands(bufnr(''), '')
189
190 Execute(ParseCompileCommandsFlags should tolerate empty values):
191   AssertEqual '', ale#c#ParseCompileCommandsFlags(bufnr(''), {}, {})
192
193 Execute(ParseCompileCommandsFlags should parse some basic flags):
194   silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'))
195
196   " We should read the absolute path filename entry, not the other ones.
197   AssertEqual
198   \ '-I ' . ale#Escape(ale#path#Simplify('/usr/include/xmms2')),
199   \ ale#c#ParseCompileCommandsFlags(
200   \   bufnr(''),
201   \   {
202   \     ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'): [
203   \       {
204   \         'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'),
205   \         'command': '/usr/bin/cc  -I' . ale#path#Simplify('/usr/include/xmms2')
206   \           . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
207   \           . '   -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
208   \         'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
209   \       },
210   \     ],
211   \     "xmms2-mpris.c": [
212   \       {
213   \         'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'),
214   \         'command': '/usr/bin/cc  -I' . ale#path#Simplify('/usr/include/ignoreme')
215   \           . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
216   \           . '   -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
217   \         'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
218   \       },
219   \     ],
220   \   },
221   \   {
222   \     ale#path#Simplify('/foo/bar/xmms2-mpris/src'): [
223   \       {
224   \         'directory': ale#path#Simplify('/foo/bar/xmms2-mpris/src'),
225   \         'command': '/usr/bin/cc  -I' . ale#path#Simplify('/usr/include/ignoreme')
226   \           . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
227   \           . '   -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
228   \         'file': 'other.c',
229   \       },
230   \     ],
231   \     "src": [
232   \       {
233   \         'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'),
234   \         'command': '/usr/bin/cc  -I' . ale#path#Simplify('/usr/include/ignoreme')
235   \           . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
236   \           . '   -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
237   \         'file': ale#path#Simplify((has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c'),
238   \       },
239   \     ],
240   \   },
241   \ )
242
243 Execute(ParseCompileCommandsFlags should fall back to files with the same name):
244   silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'))
245
246   " We should prefer the basename file flags, not the base dirname flags.
247   AssertEqual
248   \ '-I ' . ale#Escape(ale#path#Simplify('/usr/include/xmms2')),
249   \ ale#c#ParseCompileCommandsFlags(
250   \   bufnr(''),
251   \   {
252   \     "xmms2-mpris.c": [
253   \       {
254   \         'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'),
255   \         'command': '/usr/bin/cc  -I' . ale#path#Simplify('/usr/include/xmms2')
256   \           . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
257   \           . '   -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
258   \         'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
259   \       },
260   \     ],
261   \   },
262   \   {
263   \     "src": [
264   \       {
265   \         'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'),
266   \         'command': '/usr/bin/cc  -I' . ale#path#Simplify('/usr/include/ignoreme')
267   \           . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
268   \           . '   -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
269   \         'file': ale#path#Simplify((has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c'),
270   \       },
271   \     ],
272   \   },
273   \ )
274
275 Execute(ParseCompileCommandsFlags should parse flags for exact directory matches):
276   silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'))
277
278   " We should ues the exact directory flags, not the file basename flags.
279   AssertEqual
280   \ '-I ' . ale#Escape(ale#path#Simplify('/usr/include/xmms2')),
281   \ ale#c#ParseCompileCommandsFlags(
282   \   bufnr(''),
283   \   {
284   \     "xmms2-mpris.c": [
285   \       {
286   \         'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'),
287   \         'command': '/usr/bin/cc  -I' . ale#path#Simplify('/usr/include/ignoreme')
288   \           . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
289   \           . '   -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
290   \         'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
291   \       },
292   \     ],
293   \   },
294   \   {
295   \     ale#path#Simplify('/foo/bar/xmms2-mpris/src'): [
296   \       {
297   \         'directory': ale#path#Simplify('/foo/bar/xmms2-mpris/src'),
298   \         'command': '/usr/bin/cc  -I' . ale#path#Simplify('/usr/include/xmms2')
299   \           . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
300   \           . '   -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
301   \         'file': 'other.c',
302   \       },
303   \     ],
304   \     "src": [
305   \       {
306   \         'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'),
307   \         'command': '/usr/bin/cc  -I' . ale#path#Simplify('/usr/include/ignoreme')
308   \           . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
309   \           . '   -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
310   \         'file': ale#path#Simplify((has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c'),
311   \       },
312   \     ],
313   \   },
314   \ )
315
316 Execute(ParseCompileCommandsFlags should fall back to files in the same directory):
317   silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'))
318
319   AssertEqual
320   \ '-I ' . ale#Escape(ale#path#Simplify('/usr/include/xmms2')),
321   \ ale#c#ParseCompileCommandsFlags(
322   \   bufnr(''),
323   \   {},
324   \   {
325   \     "src": [
326   \       {
327   \         'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'),
328   \         'command': '/usr/bin/cc  -I' . ale#path#Simplify('/usr/include/xmms2')
329   \           . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
330   \           . '   -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
331   \         'file': ale#path#Simplify((has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c'),
332   \       },
333   \     ],
334   \   },
335   \ )
336
337 Execute(ParseCompileCommandsFlags should tolerate items without commands):
338   silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'))
339
340   AssertEqual
341   \ '',
342   \ ale#c#ParseCompileCommandsFlags(
343   \   bufnr(''),
344   \   {
345   \     "xmms2-mpris.c": [
346   \       {
347   \         'directory': '/foo/bar/xmms2-mpris',
348   \         'file': '/foo/bar/xmms2-mpris/src/xmms2-mpris.c',
349   \       },
350   \     ],
351   \   },
352   \   {},
353   \ )
354
355 Execute(ParseCompileCommandsFlags should take commands from matching .c files for .h files):
356   silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.h'))
357
358   AssertEqual
359   \ '-I ' . ale#Escape('/usr/include/xmms2'),
360   \ ale#c#ParseCompileCommandsFlags(
361   \   bufnr(''),
362   \   {
363   \     'xmms2-mpris.c': [
364   \       {
365   \         'directory': '/foo/bar/xmms2-mpris',
366   \         'file': (has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-mpris.c',
367   \         'command': '/usr/bin/cc  -I' . '/usr/include/xmms2'
368   \         . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
369   \         . '   -c ' . '/foo/bar/xmms2-mpris/src/xmms2-mpris.c',
370   \       },
371   \     ],
372   \   },
373   \   {},
374   \ )
375
376 Execute(ParseCompileCommandsFlags should take commands from matching .cpp files for .hpp files):
377   silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.hpp'))
378
379   AssertEqual
380   \ '-I ' . ale#Escape('/usr/include/xmms2'),
381   \ ale#c#ParseCompileCommandsFlags(
382   \   bufnr(''),
383   \   {
384   \     'xmms2-mpris.cpp': [
385   \       {
386   \         'directory': '/foo/bar/xmms2-mpris',
387   \         'file': (has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-mpris.cpp',
388   \         'command': '/usr/bin/cc  -I' . '/usr/include/xmms2'
389   \         . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
390   \         . '   -c ' . '/foo/bar/xmms2-mpris/src/xmms2-mpris.cpp',
391   \       },
392   \     ],
393   \   },
394   \   {
395   \   },
396   \ )
397
398 Execute(ParseCompileCommandsFlags should take commands from matching .cpp files for .h files):
399   silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.h'))
400
401   AssertEqual
402   \ '-I ' . ale#Escape('/usr/include/xmms2'),
403   \ ale#c#ParseCompileCommandsFlags(
404   \   bufnr(''),
405   \   {
406   \     'xmms2-mpris.cpp': [
407   \       {
408   \         'directory': '/foo/bar/xmms2-mpris',
409   \         'file': (has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-mpris.cpp',
410   \         'command': '/usr/bin/cc  -I' . '/usr/include/xmms2'
411   \         . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
412   \         . '   -c ' . '/foo/bar/xmms2-mpris/src/xmms2-mpris.cpp',
413   \       },
414   \     ],
415   \   },
416   \   {
417   \   },
418   \ )
419
420 Execute(ParseCompileCommandsFlags should not take commands from .c files for .h files with different names):
421   silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/other.h'))
422
423   AssertEqual
424   \ '',
425   \ ale#c#ParseCompileCommandsFlags(
426   \   bufnr(''),
427   \   {
428   \     'xmms2-mpris.c': [
429   \       {
430   \         'directory': '/foo/bar/xmms2-mpris',
431   \         'file': (has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-mpris.c',
432   \         'command': '/usr/bin/cc  -I' . '/usr/include/xmms2'
433   \         . '    -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
434   \         . '   -c ' . '/foo/bar/xmms2-mpris/src/xmms2-mpris.c',
435   \       },
436   \     ],
437   \   },
438   \   {
439   \   },
440   \ )
441
442 Execute(ShellSplit should not merge flags):
443   AssertEqual
444   \ [
445   \   'gcc',
446   \   '-Dgoal=9',
447   \   '-Tlinkerfile.ld',
448   \   'blabla',
449   \   '-Isubdir',
450   \   'subdir/somedep1.o',
451   \   'subdir/somedep2.o',
452   \   '-I''dir with spaces''',
453   \   '-Idir-with-dash',
454   \   'subdir/somedep3.o',
455   \   'subdir/somedep4.o',
456   \   '-I' . ale#path#Simplify('kernel/include'),
457   \   'subdir/somedep5.o',
458   \   'subdir/somedep6.o',
459   \ ],
460   \ ale#c#ShellSplit(
461   \   'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
462   \     . 'subdir/somedep1.o ' . 'subdir/somedep2.o '
463   \     . '-I''dir with spaces''' . ' -Idir-with-dash '
464   \     . 'subdir/somedep3.o ' . 'subdir/somedep4.o '
465   \     . ' -I'. ale#path#Simplify('kernel/include') . ' '
466   \     . 'subdir/somedep5.o ' . 'subdir/somedep6.o'
467   \ )
468
469 Execute(ShellSplit should handle parenthesis and quotes):
470   AssertEqual
471   \ [
472   \   'gcc',
473   \   '-Dgoal=9',
474   \   '-Tlinkerfile.ld',
475   \   'blabla',
476   \   '-Dtest1="('' '')"',
477   \   'file1.o',
478   \   '-Dtest2=''(` `)''',
479   \   'file2.o',
480   \   '-Dtest3=`(" ")`',
481   \   'file3.o',
482   \ ] ,
483   \ ale#c#ShellSplit(
484   \   'gcc -Dgoal=9 -Tlinkerfile.ld blabla '
485   \     . '-Dtest1="('' '')" file1.o '
486   \     . '-Dtest2=''(` `)'' file2.o '
487   \     . '-Dtest3=`(" ")` file3.o'
488   \ )
489
490 Execute(We should include several important flags):
491   AssertEqual
492   \ '-I ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/inc'))
493   \ . ' -I ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/include'))
494   \ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incquote'))
495   \ . ' -isystem ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incsystem'))
496   \ . ' -idirafter ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/incafter'))
497   \ . ' -iframework ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incframework'))
498   \ . ' -include file.h'
499   \ . ' -imacros macros.h'
500   \ . ' -Dmacro="value"'
501   \ . ' -DGoal=9'
502   \ . ' -D macro2'
503   \ . ' -D macro3="value"'
504   \ . ' -Bbdir'
505   \ . ' -B bdir2'
506   \ . ' -iprefix prefix -iwithprefix prefix2 -iwithprefixbefore prefix3'
507   \ . ' -isysroot sysroot --sysroot=test --no-sysroot-suffix -imultilib multidir'
508   \ . ' -Wsome-warning -std=c89 -pedantic -pedantic-errors -ansi'
509   \ . ' -foption -O2 -C -CC -trigraphs -nostdinc -nostdinc++'
510   \ . ' -iplugindir=dir -march=native -w',
511   \ ale#c#ParseCFlags(
512   \   ale#path#Simplify(g:dir. '/test-files/c/makefile_project'),
513   \   0,
514   \   [
515   \     'gcc',
516   \     '-Iinc',
517   \     '-I',
518   \     'include',
519   \     '-iquote',
520   \     'incquote',
521   \     '-isystem',
522   \     'incsystem',
523   \     '-idirafter',
524   \     'incafter',
525   \     '-iframework',
526   \     'incframework',
527   \     '-include',
528   \     'file.h',
529   \     '-imacros',
530   \     'macros.h',
531   \     '-Dmacro="value"',
532   \     '-DGoal=9',
533   \     '-D',
534   \     'macro2',
535   \     '-D',
536   \     'macro3="value"',
537   \     '-Bbdir',
538   \     '-B',
539   \     'bdir2',
540   \     '-iprefix',
541   \     'prefix',
542   \     '-iwithprefix',
543   \     'prefix2',
544   \     '-iwithprefixbefore',
545   \     'prefix3',
546   \     '-isysroot',
547   \     'sysroot',
548   \     '--sysroot=test',
549   \     '--no-sysroot-suffix',
550   \     '-imultilib',
551   \     'multidir',
552   \     '-Wsome-warning',
553   \     '-std=c89',
554   \     '-pedantic',
555   \     '-pedantic-errors',
556   \     '-ansi',
557   \     '-foption',
558   \     '-O2',
559   \     '-C',
560   \     '-CC',
561   \     '-trigraphs',
562   \     '-nostdinc',
563   \     '-nostdinc++',
564   \     '-iplugindir=dir',
565   \     '-march=native',
566   \     '-w',
567   \   ],
568   \ )
569
570 Execute(We should quote the flags we need to quote):
571   AssertEqual
572   \ '-I ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/inc'))
573   \ . ' -I ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/include'))
574   \ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incquote'))
575   \ . ' -isystem ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incsystem'))
576   \ . ' -idirafter ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/incafter'))
577   \ . ' -iframework ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incframework'))
578   \ . ' -include file.h'
579   \ . ' -imacros macros.h'
580   \ . ' ' . ale#Escape('-Dmacro="value"')
581   \ . ' -DGoal=9'
582   \ . ' -D macro2'
583   \ . ' -D ' . ale#Escape('macro3="value"')
584   \ . ' -Bbdir'
585   \ . ' -B bdir2'
586   \ . ' -iprefix prefix -iwithprefix prefix2 -iwithprefixbefore prefix3'
587   \ . ' -isysroot sysroot --sysroot=test'
588   \ . ' ' . ale#Escape('--sysroot="quoted"')
589   \ . ' ' . ale#Escape('--sysroot=foo bar')
590   \ . ' --no-sysroot-suffix -imultilib multidir'
591   \ . ' -Wsome-warning -std=c89 -pedantic -pedantic-errors -ansi'
592   \ . ' -foption -O2 -C -CC -trigraphs -nostdinc -nostdinc++'
593   \ . ' -iplugindir=dir -march=native -w',
594   \ ale#c#ParseCFlags(
595   \   ale#path#Simplify(g:dir. '/test-files/c/makefile_project'),
596   \   1,
597   \   [
598   \     'gcc',
599   \     '-Iinc',
600   \     '-I',
601   \     'include',
602   \     '-iquote',
603   \     'incquote',
604   \     '-isystem',
605   \     'incsystem',
606   \     '-idirafter',
607   \     'incafter',
608   \     '-iframework',
609   \     'incframework',
610   \     '-include',
611   \     'file.h',
612   \     '-imacros',
613   \     'macros.h',
614   \     '-Dmacro="value"',
615   \     '-DGoal=9',
616   \     '-D',
617   \     'macro2',
618   \     '-D',
619   \     'macro3="value"',
620   \     '-Bbdir',
621   \     '-B',
622   \     'bdir2',
623   \     '-iprefix',
624   \     'prefix',
625   \     '-iwithprefix',
626   \     'prefix2',
627   \     '-iwithprefixbefore',
628   \     'prefix3',
629   \     '-isysroot',
630   \     'sysroot',
631   \     '--sysroot=test',
632   \     '--sysroot="quoted"',
633   \     '--sysroot=foo bar',
634   \     '--no-sysroot-suffix',
635   \     '-imultilib',
636   \     'multidir',
637   \     '-Wsome-warning',
638   \     '-std=c89',
639   \     '-pedantic',
640   \     '-pedantic-errors',
641   \     '-ansi',
642   \     '-foption',
643   \     '-O2',
644   \     '-C',
645   \     '-CC',
646   \     '-trigraphs',
647   \     '-nostdinc',
648   \     '-nostdinc++',
649   \     '-iplugindir=dir',
650   \     '-march=native',
651   \     '-w',
652   \   ],
653   \ )
654
655 Execute(We should exclude other flags that cause problems):
656   AssertEqual
657   \ '',
658   \ ale#c#ParseCFlags(
659   \   ale#path#Simplify(g:dir. '/test-files/c/makefile_project'),
660   \   0,
661   \   [
662   \     'gcc',
663   \     '-Wl,option',
664   \     '-Wa,option',
665   \     '-Wp,option',
666   \     '-c',
667   \     'filename.c',
668   \     'somelib.a',
669   \     '-fdump-file=name',
670   \     '-fdiagnostics-arg',
671   \     '-fno-show-column',
672   \     '-fstack-usage',
673   \     '-Tlinkerfile.ld',
674   \   ],
675   \ )
676
677 Execute(We should expand @file in CFlags):
678   AssertEqual
679   \ '-DARGS1 -DARGS2 -O2',
680   \ ale#c#ParseCFlags(
681   \   ale#path#Simplify(g:dir. '/test-files/c/makefile_project'),
682   \   0,
683   \   [
684   \     'gcc',
685   \     '-g',
686   \     '@./args',
687   \     '-O2',
688   \   ],
689   \ )