]> git.madduck.net Git - etc/vim.git/blob - test/handler/test_rust_handler.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 / handler / test_rust_handler.vader
1 Before:
2   Save g:ale_rust_ignore_secondary_spans
3
4   let g:ale_rust_ignore_secondary_spans = 0
5
6 After:
7   Restore
8
9 Execute(The Rust handler should handle rustc output):
10   call ale#test#SetFilename('src/playpen.rs')
11
12   AssertEqual
13   \ [
14   \   {
15   \     'lnum': 15,
16   \     'end_lnum': 15,
17   \     'type': 'E',
18   \     'col': 5,
19   \     'end_col': 7,
20   \     'text': 'expected one of `.`, `;`, `?`, `}`, or an operator, found `for`',
21   \   },
22   \   {
23   \      'lnum': 13,
24   \      'end_lnum': 13,
25   \      'type': 'E',
26   \      'col': 7,
27   \      'end_col': 9,
28   \      'text': 'no method named `wat` found for type `std::string::String` in the current scope',
29   \   },
30   \ ],
31   \ ale#handlers#rust#HandleRustErrors(bufnr(''), [
32   \   '',
33   \   'ignore this',
34   \   json_encode({
35   \     'message': 'expected one of `.`, `;`, `?`, `}`, or an operator, found `for`',
36   \     'code': v:null,
37   \     'level': 'error',
38   \     'spans': [
39   \       {
40   \         'file_name': '<anon>',
41   \         'byte_start': 418,
42   \         'byte_end': 421,
43   \         'line_start': 15,
44   \         'line_end': 15,
45   \         'column_start': 5,
46   \         'column_end': 8,
47   \         'is_primary': v:true,
48   \         'label': v:null,
49   \       },
50   \     ],
51   \   }),
52   \   json_encode({
53   \     'message': 'main function not found',
54   \     'code': v:null,
55   \     'level': 'error',
56   \     'spans': [],
57   \   }),
58   \   json_encode({
59   \     'code': v:null,
60   \     'level': 'error',
61   \     'message': 'no method named `wat` found for type `std::string::String` in the current scope',
62   \     'spans': [
63   \       {
64   \         'byte_end': 410,
65   \         'byte_start': 407,
66   \         'column_end': 10,
67   \         'column_start': 7,
68   \         'file_name': '<anon>',
69   \         'is_primary': v:true,
70   \         'label': v:null,
71   \         'line_end': 13,
72   \         'line_start': 13,
73   \       }
74   \     ]
75   \   }),
76   \   json_encode({
77   \     'code': v:null,
78   \     'level': 'error',
79   \     'message': 'aborting due to previous error',
80   \     'spans': [
81   \     ]
82   \   }),
83   \ ])
84
85 Execute(The Rust handler should handle cargo output):
86   call ale#test#SetFilename('src/playpen.rs')
87
88   AssertEqual
89   \ [
90   \   {
91   \     'lnum': 15,
92   \     'end_lnum': 15,
93   \     'type': 'E',
94   \     'col': 5,
95   \     'end_col': 7,
96   \     'text': 'expected one of `.`, `;`, `?`, `}`, or an operator, found `for`',
97   \   },
98   \   {
99   \     'lnum': 13,
100   \     'end_lnum': 13,
101   \     'type': 'E',
102   \     'col': 7,
103   \     'end_col': 9,
104   \     'text': 'no method named `wat` found for type `std::string::String` in the current scope',
105   \   },
106   \ ],
107   \ ale#handlers#rust#HandleRustErrors(bufnr(''), [
108   \   '',
109   \   'ignore this',
110   \   json_encode({
111   \     'message': {
112   \       'code': v:null,
113   \       'level': 'error',
114   \       'message': 'expected one of `.`, `;`, `?`, `}`, or an operator, found `for`',
115   \       'spans': [
116   \         {
117   \           'byte_end': 11508,
118   \           'byte_start': 11505,
119   \           'column_end': 8,
120   \           'column_start': 5,
121   \           'file_name': ale#path#Simplify('src/playpen.rs'),
122   \           'is_primary': v:true,
123   \           'label': v:null,
124   \           'line_end': 15,
125   \           'line_start': 15,
126   \         }
127   \       ]
128   \     },
129   \   }),
130   \   json_encode({
131   \     'message': {
132   \       'code': v:null,
133   \       'level': 'error',
134   \       'message': 'no method named `wat` found for type `std::string::String` in the current scope',
135   \       'spans': [
136   \         {
137   \           'byte_end': 11497,
138   \           'byte_start': 11494,
139   \           'column_end': 10,
140   \           'column_start': 7,
141   \           'file_name': ale#path#Simplify('src/playpen.rs'),
142   \           'is_primary': v:true,
143   \           'label': v:null,
144   \           'line_end': 13,
145   \           'line_start': 13,
146   \         }
147   \       ]
148   \     },
149   \   }),
150   \   json_encode({
151   \     'message': {
152   \       'code': v:null,
153   \       'level': 'error',
154   \       'message': 'aborting due to previous error',
155   \       'spans': [
156   \       ]
157   \     },
158   \   }),
159   \ ])
160
161 Execute(The Rust handler should should errors from expansion spans):
162   AssertEqual
163   \ [
164   \   {
165   \     'lnum': 4,
166   \     'end_lnum': 4,
167   \     'type': 'E',
168   \     'col': 21,
169   \     'end_col': 22,
170   \     'text': 'mismatched types: expected bool, found integral variable',
171   \   },
172   \ ],
173   \ ale#handlers#rust#HandleRustErrors(bufnr(''), [
174   \   json_encode({
175   \     'message': {
176   \       'code': v:null,
177   \       'level': 'error',
178   \       'message': 'mismatched types',
179   \       'spans': [
180   \         {
181   \           'byte_end': 1,
182   \           'byte_start': 1,
183   \           'column_end': 1,
184   \           'column_start': 1,
185   \           'file_name': ale#path#Simplify('src/other.rs'),
186   \           'is_primary': v:true,
187   \           'label': 'some other error',
188   \           'line_end': 4,
189   \           'line_start': 4,
190   \           'expansion': {
191   \             'span': {
192   \               'byte_end': 54,
193   \               'byte_start': 52,
194   \               'column_end': 23,
195   \               'column_start': 21,
196   \               'file_name': ale#path#Simplify('src/playpen.rs'),
197   \               'is_primary': v:true,
198   \               'label': 'expected bool, found integral variable',
199   \               'line_end': 4,
200   \               'line_start': 4,
201   \             }
202   \           }
203   \         }
204   \       ]
205   \     },
206   \   }),
207   \ ])
208
209 Execute(The Rust handler should show detailed errors):
210   call ale#test#SetFilename('src/playpen.rs')
211
212   AssertEqual
213   \ [
214   \   {
215   \     'lnum': 4,
216   \     'end_lnum': 4,
217   \     'type': 'E',
218   \     'col': 21,
219   \     'end_col': 22,
220   \     'text': 'mismatched types: expected bool, found integral variable',
221   \   },
222   \ ],
223   \ ale#handlers#rust#HandleRustErrors(bufnr(''), [
224   \   '',
225   \   'ignore this',
226   \   json_encode({
227   \     'message': {
228   \       'code': v:null,
229   \       'level': 'error',
230   \       'message': 'mismatched types',
231   \       'spans': [
232   \         {
233   \           'byte_end': 54,
234   \           'byte_start': 52,
235   \           'column_end': 23,
236   \           'column_start': 21,
237   \           'expansion': v:null,
238   \           'file_name': ale#path#Simplify('src/playpen.rs'),
239   \           'is_primary': v:true,
240   \           'label': 'expected bool, found integral variable',
241   \           'line_end': 4,
242   \           'line_start': 4,
243   \         }
244   \       ]
245   \     },
246   \   }),
247   \   json_encode({
248   \     'message': {
249   \       'code': v:null,
250   \       'level': 'error',
251   \       'message': 'aborting due to previous error(s)',
252   \       'spans': [
253   \       ]
254   \     },
255   \   }),
256   \ ])
257
258 Execute(The Rust handler should show detailed clippy errors with rendered field if it's available):
259   call ale#test#SetFilename('src/playpen.rs')
260
261   AssertEqual
262   \ [
263   \   {
264   \     'lnum': 4,
265   \     'end_lnum': 4,
266   \     'type': 'E',
267   \     'col': 21,
268   \     'end_col': 22,
269   \     'text': 'mismatched types: expected bool, found integral variable',
270   \     'detail': 'this is a detailed description',
271   \   },
272   \ ],
273   \ ale#handlers#rust#HandleRustErrors(bufnr(''), [
274   \   '',
275   \   'ignore this',
276   \   json_encode({
277   \     'message': {
278   \       'code': v:null,
279   \       'level': 'error',
280   \       'message': 'mismatched types',
281   \       'rendered': 'this is a detailed description',
282   \       'spans': [
283   \         {
284   \           'byte_end': 54,
285   \           'byte_start': 52,
286   \           'column_end': 23,
287   \           'column_start': 21,
288   \           'expansion': v:null,
289   \           'file_name': ale#path#Simplify('src/playpen.rs'),
290   \           'is_primary': v:true,
291   \           'label': 'expected bool, found integral variable',
292   \           'line_end': 4,
293   \           'line_start': 4,
294   \         }
295   \       ]
296   \     },
297   \   }),
298   \   json_encode({
299   \     'message': {
300   \       'code': v:null,
301   \       'level': 'error',
302   \       'message': 'aborting due to previous error(s)',
303   \       'spans': [
304   \       ]
305   \     },
306   \   }),
307   \ ])
308
309 Execute(The Rust handler should find correct files):
310   call ale#test#SetFilename('src/noerrors/mod.rs')
311
312   AssertEqual
313   \ [],
314   \ ale#handlers#rust#HandleRustErrors(bufnr(''), [
315   \   '',
316   \   'ignore this',
317   \   json_encode({
318   \     'message': {
319   \       'code': v:null,
320   \       'level': 'error',
321   \       'message': 'unresolved import `Undefined`',
322   \       'spans': [
323   \         {
324   \           'byte_end': 103,
325   \           'byte_start': 94,
326   \           'column_end': 14,
327   \           'column_start': 5,
328   \           'file_name': 'src/haserrors/mod.rs',
329   \           'is_primary': v:true,
330   \           'label': 'no `Undefined` in the root',
331   \           'line_end': 1,
332   \           'line_start': 1,
333   \         }
334   \       ]
335   \     },
336   \   }),
337   \   json_encode({
338   \     'message': {
339   \       'code': v:null,
340   \       'level': 'error',
341   \       'message': 'aborting due to previous error',
342   \       'spans': [
343   \       ]
344   \     },
345   \   }),
346   \ ])
347
348 Execute(The Rust handler should remove secondary spans if set):
349   call ale#test#SetFilename('src/noerrors/mod.rs')
350
351   AssertEqual
352   \ [
353   \   {
354   \     'lnum': 1,
355   \     'end_lnum': 1,
356   \     'type': 'E',
357   \     'end_col': 20,
358   \     'col': 1,
359   \     'text': 'this function takes 1 parameter but 0 were supplied: defined here',
360   \   },
361   \   {
362   \     'lnum': 1,
363   \     'end_lnum': 1,
364   \     'type': 'E',
365   \     'end_col': 45,
366   \     'col': 40,
367   \     'text': 'this function takes 1 parameter but 0 were supplied: expected 1 parameter',
368   \   },
369   \ ],
370   \ ale#handlers#rust#HandleRustErrors(bufnr(''), [
371   \   '',
372   \   'fn test(x: u8) -> u8 { x } fn main() { x(); }',
373   \   json_encode({
374   \     'message': {
375   \       'code': {
376   \         'code': 'E0061',
377   \         'explanation': 'Dummy explanation; not used'
378   \       },
379   \       'level': 'error',
380   \       'message': 'this function takes 1 parameter but 0 were supplied',
381   \       'spans': [
382   \         {
383   \           'byte_end': 20,
384   \           'byte_start': 0,
385   \           'column_end': 21,
386   \           'column_start': 1,
387   \           'file_name': 'src/noerrors/mod.rs',
388   \           'is_primary': v:false,
389   \           'label': 'defined here',
390   \           'line_end': 1,
391   \           'line_start': 1,
392   \         },
393   \         {
394   \           'byte_end': 45,
395   \           'byte_start': 39,
396   \           'column_end': 46,
397   \           'column_start': 40,
398   \           'file_name': '<anon>',
399   \           'is_primary': v:true,
400   \           'label': 'expected 1 parameter',
401   \           'line_end': 1,
402   \           'line_start': 1,
403   \         },
404   \       ]
405   \     },
406   \   }),
407   \   json_encode({
408   \     'message': {
409   \       'code': v:null,
410   \       'level': 'error',
411   \       'message': 'aborting due to previous error',
412   \       'spans': []
413   \     },
414   \   }),
415   \   json_encode({
416   \     'message': {
417   \       'code': v:null,
418   \       'level': 'error',
419   \       'message': 'For more information about this error, try `rustc --explain E0061`.',
420   \       'spans': []
421   \     },
422   \   }),
423   \ ])
424
425   let g:ale_rust_ignore_secondary_spans = 1
426
427   AssertEqual
428   \ [
429   \   {
430   \     'lnum': 1,
431   \     'end_lnum': 1,
432   \     'type': 'E',
433   \     'end_col': 45,
434   \     'col': 40,
435   \     'text': 'this function takes 1 parameter but 0 were supplied: expected 1 parameter',
436   \   },
437   \ ],
438   \ ale#handlers#rust#HandleRustErrors(bufnr(''), [
439   \   '',
440   \   'fn test(x: u8) -> u8 { x } fn main() { x(); }',
441   \   json_encode({
442   \     'message': {
443   \       'code': {
444   \         'code': 'E0061',
445   \         'explanation': 'Dummy explanation; not used'
446   \       },
447   \       'level': 'error',
448   \       'message': 'this function takes 1 parameter but 0 were supplied',
449   \       'spans': [
450   \         {
451   \           'byte_end': 20,
452   \           'byte_start': 0,
453   \           'column_end': 21,
454   \           'column_start': 1,
455   \           'file_name': 'src/noerrors/mod.rs',
456   \           'is_primary': v:false,
457   \           'label': 'defined here',
458   \           'line_end': 1,
459   \           'line_start': 1,
460   \         },
461   \         {
462   \           'byte_end': 45,
463   \           'byte_start': 39,
464   \           'column_end': 46,
465   \           'column_start': 40,
466   \           'file_name': '<anon>',
467   \           'is_primary': v:true,
468   \           'label': 'expected 1 parameter',
469   \           'line_end': 1,
470   \           'line_start': 1,
471   \         },
472   \       ]
473   \     },
474   \   }),
475   \   json_encode({
476   \     'message': {
477   \       'code': v:null,
478   \       'level': 'error',
479   \       'message': 'aborting due to previous error',
480   \       'spans': []
481   \     },
482   \   }),
483   \   json_encode({
484   \     'message': {
485   \       'code': v:null,
486   \       'level': 'error',
487   \       'message': 'For more information about this error, try `rustc --explain E0061`.',
488   \       'spans': []
489   \     },
490   \   }),
491   \ ])