summaryrefslogtreecommitdiff
path: root/test/test_c_import_paths.vader
blob: 6080779ff303428cd52d70bddab411fba77acbf1 (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
Before:
  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_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()

" Run this only once for this series of tests. The cleanup Execute step
" will run at the bottom of this file.
"
" We need to move .git/HEAD away so we don't match it, as we need to test
" functions which look for .git/HEAD.
Execute(Move .git/HEAD to a temp dir):
  let g:temp_head_filename = tempname()
  let g:head_filename = findfile('.git/HEAD', ';')

  if !empty(g:head_filename)
    call writefile(readfile(g:head_filename, 'b'), g:temp_head_filename, 'b')
    call delete(g:head_filename)
  endif

Execute(The C GCC handler should include 'include' directories for projects with a Makefile):
  runtime! ale_linters/c/gcc.vim

  call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')

  AssertEqual
  \ ale#Escape('gcc')
  \   . ' -S -x c -fsyntax-only '
  \   . '-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(''))

Execute(The C GCC handler should include 'include' directories for projects with a configure file):
  runtime! ale_linters/c/gcc.vim

  call ale#test#SetFilename('test_c_projects/configure_project/subdir/file.c')

  AssertEqual
  \ ale#Escape('gcc')
  \   . ' -S -x c -fsyntax-only '
  \   . '-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(''))

Execute(The C GCC handler should include root directories for projects with .h files in them):
  runtime! ale_linters/c/gcc.vim

  call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.c')

  AssertEqual
  \ ale#Escape('gcc')
  \   . ' -S -x c -fsyntax-only '
  \   . '-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(''))

Execute(The C GCC handler should include root directories for projects with .hpp files in them):
  runtime! ale_linters/c/gcc.vim

  call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.c')

  AssertEqual
  \ ale#Escape('gcc')
  \   . ' -S -x c -fsyntax-only '
  \   . '-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(''))

Execute(The C Clang handler should include 'include' directories for projects with a Makefile):
  runtime! ale_linters/c/clang.vim

  call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')

  AssertEqual
  \   ale#Escape('clang')
  \   . ' -S -x c -fsyntax-only '
  \   . '-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(''))

Execute(The C Clang handler should include 'include' directories for projects with a configure file):
  runtime! ale_linters/c/clang.vim

  call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.c')

  AssertEqual
  \   ale#Escape('clang')
  \   . ' -S -x c -fsyntax-only '
  \   . '-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(''))

Execute(The C Clang handler should include root directories for projects with .h files in them):
  runtime! ale_linters/c/clang.vim

  call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.c')

  AssertEqual
  \   ale#Escape('clang')
  \   . ' -S -x c -fsyntax-only '
  \   . '-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(''))

Execute(The C Clang handler should include root directories for projects with .hpp files in them):
  runtime! ale_linters/c/clang.vim

  call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.c')

  AssertEqual
  \   ale#Escape('clang')
  \   . ' -S -x c -fsyntax-only '
  \   . '-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(''))

Execute(The C++ GCC handler should include 'include' directories for projects with a Makefile):
  runtime! ale_linters/cpp/gcc.vim

  call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.cpp')

  AssertEqual
  \   ale#Escape('gcc')
  \   . ' -S -x c++ -fsyntax-only '
  \   . '-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#cpp#gcc#GetCommand(bufnr(''))

Execute(The C++ GCC handler should include 'include' directories for projects with a configure file):
  runtime! ale_linters/cpp/gcc.vim

  call ale#test#SetFilename('test_c_projects/configure_project/subdir/file.cpp')

  AssertEqual
  \   ale#Escape('gcc')
  \   . ' -S -x c++ -fsyntax-only '
  \   . '-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#cpp#gcc#GetCommand(bufnr(''))

Execute(The C++ GCC handler should include root directories for projects with .h files in them):
  runtime! ale_linters/cpp/gcc.vim

  call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.cpp')

  AssertEqual
  \   ale#Escape('gcc')
  \   . ' -S -x c++ -fsyntax-only '
  \   . '-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#cpp#gcc#GetCommand(bufnr(''))

Execute(The C++ GCC handler should include root directories for projects with .hpp files in them):
  runtime! ale_linters/cpp/gcc.vim

  call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.cpp')

  AssertEqual
  \   ale#Escape('gcc')
  \   . ' -S -x c++ -fsyntax-only '
  \   . '-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#cpp#gcc#GetCommand(bufnr(''))

Execute(The C++ Clang handler should include 'include' directories for projects with a Makefile):
  runtime! ale_linters/cpp/clang.vim

  call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.cpp')

  AssertEqual
  \   ale#Escape('clang++')
  \   . ' -S -x c++ -fsyntax-only '
  \   . '-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#cpp#clang#GetCommand(bufnr(''))

Execute(The C++ Clang handler should include 'include' directories for projects with a configure file):
  runtime! ale_linters/cpp/clang.vim

  call ale#test#SetFilename('test_c_projects/configure_project/subdir/file.cpp')

  AssertEqual
  \   ale#Escape('clang++')
  \   . ' -S -x c++ -fsyntax-only '
  \   . '-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#cpp#clang#GetCommand(bufnr(''))

Execute(The C++ Clang handler should include root directories for projects with .h files in them):
  runtime! ale_linters/cpp/clang.vim

  call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.cpp')

  AssertEqual
  \   ale#Escape('clang++')
  \   . ' -S -x c++ -fsyntax-only '
  \   . '-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#cpp#clang#GetCommand(bufnr(''))

Execute(The C++ Clang handler should include root directories for projects with .hpp files in them):
  runtime! ale_linters/cpp/clang.vim

  call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.cpp')

  AssertEqual
  \   ale#Escape('clang++')
  \   . ' -S -x c++ -fsyntax-only '
  \   . '-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#cpp#clang#GetCommand(bufnr(''))

Execute(The C++ Clang handler shoud use the include directory based on the .git location):
  runtime! ale_linters/cpp/clang.vim

  if !isdirectory(g:dir . '/test_c_projects/git_and_nested_makefiles/.git')
    call mkdir(g:dir . '/test_c_projects/git_and_nested_makefiles/.git')
  endif

  if !filereadable(g:dir . '/test_c_projects/git_and_nested_makefiles/.git/HEAD')
    call writefile([], g:dir . '/test_c_projects/git_and_nested_makefiles/.git/HEAD')
  endif

  call ale#test#SetFilename('test_c_projects/git_and_nested_makefiles/src/file.cpp')

  AssertEqual
  \   ale#Escape('clang++')
  \   . ' -S -x c++ -fsyntax-only '
  \   . '-iquote ' . ale#Escape(ale#path#Simplify(g:dir .  '/test_c_projects/git_and_nested_makefiles/src')) . ' '
  \   . ' -I' . ale#Escape(ale#path#Simplify(g:dir .  '/test_c_projects/git_and_nested_makefiles/include')) . ' '
  \   . ' -'
  \ , ale_linters#cpp#clang#GetCommand(bufnr(''))

Execute(The C++ ClangTidy handler should include json folders for projects with suitable build directory in them):
  runtime! ale_linters/cpp/clangtidy.vim

  call ale#test#SetFilename('test_c_projects/json_project/subdir/file.cpp')

  AssertEqual
  \ ale#Escape('clang-tidy')
  \   . ' -checks=' . ale#Escape('*') . ' %s '
  \   . '-p ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/json_project/build'))
  \ , ale_linters#cpp#clangtidy#GetCommand(bufnr(''))

Execute(Move .git/HEAD back):
  if !empty(g:head_filename)
    call writefile(readfile(g:temp_head_filename, 'b'), g:head_filename, 'b')
    call delete(g:temp_head_filename)
  endif

  unlet! g:temp_head_filename
  unlet! g:head_filename