]> git.madduck.net Git - etc/vim.git/blob - test/test_lint_file_linters.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:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / test / test_lint_file_linters.vader
1 Before:
2   Save g:ale_fix_on_save
3   Save g:ale_enabled
4   Save g:ale_run_synchronously
5   Save g:ale_set_lists_synchronously
6   Save g:ale_buffer_info
7   Save g:ale_linters
8
9   let g:ale_buffer_info = {}
10   let g:ale_run_synchronously = 1
11   unlet! g:ale_run_synchronously_callbacks
12   let g:ale_set_lists_synchronously = 1
13   let b:ale_save_event_fired = 0
14
15   let g:buffer_result = [
16   \ {
17   \   'lnum': 1,
18   \   'col': 1,
19   \   'text': 'buffer error',
20   \   'type': 'E',
21   \ },
22   \ {
23   \   'lnum': 2,
24   \   'col': 1,
25   \   'text': 'buffer warning',
26   \   'type': 'W',
27   \ },
28   \]
29
30   function! LintFileCallback(buffer, output)
31     return [
32     \ {
33     \   'lnum': 1,
34     \   'col': 3,
35     \   'text': 'file warning',
36     \   'type': 'W',
37     \ },
38     \ {
39     \   'lnum': 2,
40     \   'col': 3,
41     \   'text': 'file error',
42     \   'type': 'E',
43     \ },
44     \]
45   endfunction
46
47   function! BufferCallback(buffer, output)
48     return deepcopy(g:buffer_result)
49   endfunction
50
51   function! GetSimplerLoclist()
52     let l:loclist = []
53
54     for l:item in ale#test#GetLoclistWithoutNewerKeys()
55       call add(l:loclist, {
56       \ 'lnum': l:item.lnum,
57       \ 'col': l:item.col,
58       \ 'text': l:item.text,
59       \ 'type': l:item.type,
60       \})
61     endfor
62
63     return l:loclist
64   endfunction
65
66   call ale#linter#Define('foobar', {
67   \ 'name': 'lint_file_linter',
68   \ 'callback': 'LintFileCallback',
69   \ 'executable': has('win32') ? 'cmd' : 'echo',
70   \ 'command': 'echo',
71   \ 'lint_file': 1,
72   \})
73
74   call ale#linter#Define('foobar', {
75   \ 'name': 'buffer_linter',
76   \ 'callback': 'BufferCallback',
77   \ 'executable': has('win32') ? 'cmd' : 'echo',
78   \ 'command': 'echo',
79   \ 'read_buffer': 0,
80   \})
81
82   let g:filename = tempname()
83   call writefile([], g:filename)
84   call ale#test#SetFilename(g:filename)
85
86 After:
87   if !g:ale_run_synchronously
88     call ale#engine#Cleanup(bufnr(''))
89   endif
90
91   Restore
92
93   unlet! g:ale_run_synchronously_callbacks
94   unlet! b:ale_save_event_fired
95   unlet! b:ale_enabled
96   unlet g:buffer_result
97   let g:ale_buffer_info = {}
98   call ale#linter#Reset()
99   call setloclist(0, [])
100   delfunction LintFileCallback
101   delfunction BufferCallback
102
103   if filereadable(g:filename)
104     call delete(g:filename)
105   endif
106
107   unlet g:filename
108
109 Given foobar (Some imaginary filetype):
110   foo
111   bar
112   baz
113
114 Execute(Running linters without 'lint_file' should run only buffer linters):
115   call ale#Queue(0)
116   call ale#test#FlushJobs()
117
118   AssertEqual [
119   \ {
120   \   'lnum': 1,
121   \   'col': 1,
122   \   'text': 'buffer error',
123   \   'type': 'E',
124   \ },
125   \ {
126   \   'lnum': 2,
127   \   'col': 1,
128   \   'text': 'buffer warning',
129   \   'type': 'W',
130   \ },
131   \], GetSimplerLoclist()
132
133 Execute(Running linters with 'lint_file' should run all linters):
134   Assert filereadable(expand('%:p')), 'The file was not readable'
135
136   call ale#Queue(0, 'lint_file')
137   call ale#test#FlushJobs()
138
139   AssertEqual [
140   \ {
141   \   'lnum': 1,
142   \   'col': 1,
143   \   'text': 'buffer error',
144   \   'type': 'E',
145   \ },
146   \ {
147   \   'lnum': 1,
148   \   'col': 3,
149   \   'text': 'file warning',
150   \   'type': 'W',
151   \ },
152   \ {
153   \   'lnum': 2,
154   \   'col': 1,
155   \   'text': 'buffer warning',
156   \   'type': 'W',
157   \ },
158   \ {
159   \   'lnum': 2,
160   \   'col': 3,
161   \   'text': 'file error',
162   \   'type': 'E',
163   \ },
164   \], GetSimplerLoclist()
165
166 Execute(Linter errors from files should be kept):
167   Assert filereadable(expand('%:p')), 'The file was not readable'
168
169   call ale#Queue(0, 'lint_file')
170   call ale#test#FlushJobs()
171
172   " Change the results for the buffer callback.
173   let g:buffer_result = [
174   \ {
175   \   'lnum': 1,
176   \   'col': 1,
177   \   'text': 'new buffer error',
178   \   'type': 'E',
179   \ },
180   \]
181
182   call ale#Queue(0)
183   call ale#test#FlushJobs()
184
185   AssertEqual [
186   \ {
187   \   'lnum': 1,
188   \   'col': 1,
189   \   'text': 'new buffer error',
190   \   'type': 'E',
191   \ },
192   \ {
193   \   'lnum': 1,
194   \   'col': 3,
195   \   'text': 'file warning',
196   \   'type': 'W',
197   \ },
198   \ {
199   \   'lnum': 2,
200   \   'col': 3,
201   \   'text': 'file error',
202   \   'type': 'E',
203   \ },
204   \], GetSimplerLoclist()
205
206 Execute(Linter errors from files should be kept when no other linters are run):
207   let g:ale_linters = {'foobar': ['lint_file_linter']}
208   Assert filereadable(expand('%:p')), 'The file was not readable'
209
210   call ale#Queue(0, 'lint_file')
211   call ale#test#FlushJobs()
212
213   AssertEqual [
214   \ {
215   \   'lnum': 1,
216   \   'col': 3,
217   \   'text': 'file warning',
218   \   'type': 'W',
219   \ },
220   \ {
221   \   'lnum': 2,
222   \   'col': 3,
223   \   'text': 'file error',
224   \   'type': 'E',
225   \ },
226   \], GetSimplerLoclist()
227
228   call ale#Queue(0)
229
230   AssertEqual [
231   \ {
232   \   'lnum': 1,
233   \   'col': 3,
234   \   'text': 'file warning',
235   \   'type': 'W',
236   \ },
237   \ {
238   \   'lnum': 2,
239   \   'col': 3,
240   \   'text': 'file error',
241   \   'type': 'E',
242   \ },
243   \], GetSimplerLoclist()
244
245 Execute(The Save event should respect the buffer number):
246   let g:ale_linters = {'foobar': ['lint_file_linter']}
247   Assert filereadable(expand('%:p')), 'The file was not readable'
248
249   call ale#events#SaveEvent(bufnr('') + 1)
250   call ale#test#FlushJobs()
251
252   " We shouldn't get any prblems yet.
253   AssertEqual [], GetSimplerLoclist()
254
255   call ale#events#SaveEvent(bufnr(''))
256   call ale#test#FlushJobs()
257
258   " We should get them now we used the right buffer number.
259   AssertEqual [
260   \ {
261   \   'lnum': 1,
262   \   'col': 3,
263   \   'text': 'file warning',
264   \   'type': 'W',
265   \ },
266   \ {
267   \   'lnum': 2,
268   \   'col': 3,
269   \   'text': 'file error',
270   \   'type': 'E',
271   \ },
272   \], GetSimplerLoclist()
273
274 Execute(The Save event should set b:ale_save_event_fired to 1):
275   let g:ale_lint_on_save = 1
276   let b:ale_enabled = 1
277
278   call ale#linter#Reset()
279   call ale#events#SaveEvent(bufnr(''))
280   call ale#test#FlushJobs()
281
282   " This flag needs to be set so windows can be opened, etc.
283   AssertEqual 1, b:ale_save_event_fired
284
285 Execute(b:ale_save_event_fired should be set to 0 when results are set):
286   let b:ale_save_event_fired = 1
287
288   call ale#engine#SetResults(bufnr(''), [])
289   call ale#test#FlushJobs()
290
291   AssertEqual 0, b:ale_save_event_fired
292
293 Execute(lint_file linters should stay running after checking without them):
294   let g:ale_run_synchronously = 0
295
296   " Run all linters, then just the buffer linters.
297   call ale#Queue(0, 'lint_file')
298   call ale#Queue(0)
299
300   " The lint_file linter should still be running.
301   AssertEqual
302   \ ['lint_file_linter', 'buffer_linter'],
303   \ map(copy(g:ale_buffer_info[bufnr('')].active_linter_list), 'v:val.name')
304   " We should have 1 job for each linter.
305   AssertEqual
306   \ 2,
307   \ len(keys(get(get(ale#command#GetData(), bufnr(''), {}), 'jobs', {})))
308
309   call ale#test#WaitForJobs(2000)
310
311 Execute(The save event should not lint the buffer when ALE is disabled):
312   let g:ale_enabled = 0
313   call ale#events#SaveEvent(bufnr(''))
314   call ale#test#FlushJobs()
315
316   AssertEqual [], GetSimplerLoclist()
317   AssertEqual 0, b:ale_save_event_fired