summaryrefslogtreecommitdiff
path: root/test/test_c_parse_makefile.vader
blob: 7c2fc21e8617ba870464c2849154f1735057aebb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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', '-'))