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

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / test / test_history_saving.vader
1 Before:
2   Save g:ale_max_buffer_history_size
3   Save g:ale_history_enabled
4   Save g:ale_history_log_output
5   Save g:ale_run_synchronously
6   Save g:ale_enabled
7
8   let g:ale_enabled = 1
9   let g:ale_run_synchronously = 1
10
11   unlet! b:ale_fixers
12   unlet! b:ale_enabled
13   unlet! b:ale_history
14
15   " Temporarily set the shell to /bin/sh, if it isn't already set that way.
16   " This will make it so the test works when running it directly.
17   let g:current_shell = &shell
18
19   if !has('win32')
20     let &shell = '/bin/sh'
21   endif
22
23   let g:history = []
24   let g:ale_buffer_info = {}
25   let g:ale_max_buffer_history_size = 20
26   let g:ale_history_log_output = 0
27
28   function! TestFixer(buffer)
29     return {'command': 'echo foo'}
30   endfunction
31
32   function! CollectResults(buffer, output)
33     return []
34   endfunction
35
36   call ale#linter#Define('foobar', {
37   \ 'name': 'testlinter',
38   \ 'callback': 'CollectResults',
39   \ 'executable': has('win32') ? 'cmd' : 'echo',
40   \ 'command': has('win32')
41   \   ? 'echo command history test'
42   \   : '/bin/sh -c ''echo command history test''',
43   \ 'read_buffer': 0,
44   \})
45
46 After:
47   Restore
48
49   unlet! g:expected_results
50   unlet! b:ale_fixers
51   unlet! b:ale_enabled
52   " Clear the history we changed.
53   unlet! b:ale_history
54
55   " Reset the shell back to what it was before.
56   let &shell = g:current_shell
57   unlet g:current_shell
58   unlet g:history
59
60   call ale#engine#Cleanup(bufnr(''))
61   call ale#linter#Reset()
62
63   let g:ale_buffer_info = {}
64   let g:ale_max_buffer_history_size = 20
65   delfunction TestFixer
66   delfunction CollectResults
67
68 Given foobar (Some imaginary filetype):
69   anything
70
71 Execute(History should be set when commands are run):
72   AssertEqual 'foobar', &filetype
73
74   let b:ale_history = []
75   ALELint
76   call ale#test#FlushJobs()
77
78   let g:history = filter(
79   \ copy(ale#history#Get(bufnr(''))),
80   \ 'v:val.job_id isnot# ''executable''',
81   \)
82
83   AssertEqual 1, len(g:history)
84   AssertEqual
85   \ ['command', 'exit_code', 'job_id', 'status'],
86   \ sort(keys(g:history[0]))
87
88   if has('win32')
89     AssertEqual 'cmd /s/c "echo command history test"', g:history[0].command
90   else
91     AssertEqual ['/bin/sh', '-c', '/bin/sh -c ''echo command history test'''], g:history[0].command
92   endif
93
94   AssertEqual 'finished', g:history[0].status
95   AssertEqual 0, g:history[0].exit_code
96   " The Job ID will change each time, but we can check the type.
97   AssertEqual type(1), type(g:history[0].job_id)
98
99 Execute(History should be not set when disabled):
100   AssertEqual 'foobar', &filetype
101
102   let g:ale_history_enabled = 0
103
104   ALELint
105   call ale#test#FlushJobs()
106
107   AssertEqual [], ale#history#Get(bufnr(''))
108
109 Execute(History should include command output if logging is enabled):
110   AssertEqual 'foobar', &filetype
111
112   let g:ale_history_log_output = 1
113
114   " Retry this test until it works. This one can randomly fail.
115   let b:ale_history = []
116   ALELint
117   call ale#test#FlushJobs()
118
119   let g:history = ale#history#Get(bufnr(''))
120
121   AssertEqual 1, len(g:history)
122   AssertEqual
123   \ ['command history test'],
124   \ map(
125   \   copy(get(g:history[0], 'output', [])),
126   \   'substitute(v:val, ''[\r ]*$'', '''', ''g'')'
127   \ )
128
129 Execute(History items should be popped after going over the max):
130   let b:ale_history = map(range(20), '{''status'': ''started'', ''job_id'': v:val, ''command'': ''foobar''}')
131
132   call ale#history#Add(bufnr(''), 'started', 347, 'last command')
133
134   AssertEqual
135   \ (
136   \   map(range(1, 19), '{''status'': ''started'', ''job_id'': v:val, ''command'': ''foobar''}')
137   \   + [{'status': 'started', 'job_id': 347, 'command': 'last command'}]
138   \ ),
139   \ ale#history#Get(bufnr(''))
140
141 Execute(Nothing should be added to history if the size is too low):
142   let g:ale_max_buffer_history_size = 0
143
144   call ale#history#Add(bufnr(''), 'started', 347, 'last command')
145
146   AssertEqual [], ale#history#Get(bufnr(''))
147
148   let g:ale_max_buffer_history_size = -2
149
150   call ale#history#Add(1, 'started', 347, 'last command')
151
152   AssertEqual [], ale#history#Get(bufnr(''))
153
154 Given foobar(Some file with an imaginary filetype):
155   a
156   b
157   c
158
159 Execute(The history should be updated when fixers are run):
160   call ale#test#SetFilename('dummy.txt')
161
162   let b:ale_fixers = {'foobar': ['TestFixer']}
163   let b:ale_enabled = 0
164
165   ALEFix
166
167   AssertEqual ['started'], map(copy(b:ale_history), 'v:val.status')
168
169   call ale#test#FlushJobs()
170
171   AssertEqual ['finished'], map(copy(b:ale_history), 'v:val.status')
172
173   if has('win32')
174     AssertEqual 'cmd /s/c "echo foo ', split(b:ale_history[0].command, '<')[0]
175   else
176     AssertEqual '/bin/sh -c echo foo ', split(join(b:ale_history[0].command), '<')[0]
177   endif