]> git.madduck.net Git - etc/vim.git/blob - test/smoke_test.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 / smoke_test.vader
1 Before:
2   Save g:ale_enabled
3   Save g:ale_set_lists_synchronously
4   Save g:ale_buffer_info
5   Save &shell
6
7   let g:ale_enabled = 1
8   let g:ale_buffer_info = {}
9   let g:ale_set_lists_synchronously = 1
10
11   function! TestCallback(buffer, output)
12     " Windows adds extra spaces to the text from echo.
13     return [{
14     \ 'lnum': 2,
15     \ 'col': 3,
16     \ 'text': substitute(a:output[0], ' *$', '', ''),
17     \}]
18   endfunction
19   function! TestCallback2(buffer, output)
20     return [{
21     \ 'lnum': 3,
22     \ 'col': 4,
23     \ 'text': substitute(a:output[0],  ' *$', '', ''),
24     \}]
25   endfunction
26
27   " Running the command in another subshell seems to help here.
28   call ale#linter#Define('foobar', {
29   \ 'name': 'testlinter',
30   \ 'callback': 'TestCallback',
31   \ 'executable': has('win32') ? 'cmd' : 'echo',
32   \ 'command': has('win32') ? 'echo foo bar' : '/bin/sh -c ''echo foo bar''',
33   \})
34
35 After:
36   Restore
37
38   unlet! g:i
39   unlet! g:results
40   unlet! g:expected_results
41
42   delfunction TestCallback
43   delfunction TestCallback2
44   call ale#engine#Cleanup(bufnr(''))
45   call ale#linter#Reset()
46
47 Given foobar (Some imaginary filetype):
48   foo
49   bar
50   baz
51
52 Execute(Linters should run with the default options):
53   AssertEqual 'foobar', &filetype
54
55   let g:expected_results = [{
56   \   'bufnr': bufnr('%'),
57   \   'lnum': 2,
58   \   'vcol': 0,
59   \   'col': 3,
60   \   'text': 'foo bar',
61   \   'type': 'E',
62   \   'nr': -1,
63   \   'pattern': '',
64   \   'valid': 1,
65   \ }]
66
67   " Try the test a few times over in NeoVim 0.3 or Windows or Vim 8.2,
68   " where tests fail randomly.
69   for g:i in range(has('nvim-0.3') || has('win32') || has('patch-8.2.2401') ? 5 : 1)
70     call ale#Queue(0, '')
71     call ale#test#WaitForJobs(2000)
72
73     let g:results = ale#test#GetLoclistWithoutNewerKeys()
74
75     if g:results == g:expected_results
76       break
77     endif
78   endfor
79
80   AssertEqual g:expected_results, g:results
81
82 Execute(Linters should run in PowerShell too):
83   if has('win32')
84     set shell=powershell
85
86     AssertEqual 'foobar', &filetype
87
88     " Replace the callback to handle two lines.
89     function! TestCallback(buffer, output)
90       " Windows adds extra spaces to the text from echo.
91       return [
92       \ {
93       \   'lnum': 1,
94       \   'col': 3,
95       \   'text': substitute(a:output[0], ' *$', '', ''),
96       \ },
97       \ {
98       \   'lnum': 2,
99       \   'col': 3,
100       \   'text': substitute(a:output[1], ' *$', '', ''),
101       \ },
102       \]
103     endfunction
104
105     " Recreate the command string to use &&, which PowerShell does not support.
106     call ale#linter#Reset()
107     call ale#linter#Define('foobar', {
108     \ 'name': 'testlinter',
109     \ 'callback': 'TestCallback',
110     \ 'executable': 'cmd',
111     \ 'command': 'echo foo && echo bar',
112     \})
113
114     call ale#Queue(0, '')
115     call ale#test#WaitForJobs(4000)
116
117     AssertEqual [
118     \ {
119     \   'bufnr': bufnr('%'),
120     \   'lnum': 1,
121     \   'vcol': 0,
122     \   'col': 3,
123     \   'text': 'foo',
124     \   'type': 'E',
125     \   'nr': -1,
126     \   'pattern': '',
127     \   'valid': 1,
128     \ },
129     \ {
130     \   'bufnr': bufnr('%'),
131     \   'lnum': 2,
132     \   'vcol': 0,
133     \   'col': 3,
134     \   'text': 'bar',
135     \   'type': 'E',
136     \   'nr': -1,
137     \   'pattern': '',
138     \   'valid': 1,
139     \ },
140     \], ale#test#GetLoclistWithoutNewerKeys()
141   endif