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.
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
9 let g:ale_run_synchronously = 1
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
20 let &shell = '/bin/sh'
24 let g:ale_buffer_info = {}
25 let g:ale_max_buffer_history_size = 20
26 let g:ale_history_log_output = 0
28 function! TestFixer(buffer)
29 return {'command': 'echo foo'}
32 function! CollectResults(buffer, output)
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''',
49 unlet! g:expected_results
52 " Clear the history we changed.
55 " Reset the shell back to what it was before.
56 let &shell = g:current_shell
60 call ale#engine#Cleanup(bufnr(''))
61 call ale#linter#Reset()
63 let g:ale_buffer_info = {}
64 let g:ale_max_buffer_history_size = 20
66 delfunction CollectResults
68 Given foobar (Some imaginary filetype):
71 Execute(History should be set when commands are run):
72 AssertEqual 'foobar', &filetype
74 let b:ale_history = []
76 call ale#test#FlushJobs()
78 let g:history = filter(
79 \ copy(ale#history#Get(bufnr(''))),
80 \ 'v:val.job_id isnot# ''executable''',
83 AssertEqual 1, len(g:history)
85 \ ['command', 'exit_code', 'job_id', 'status'],
86 \ sort(keys(g:history[0]))
89 AssertEqual 'cmd /s/c "echo command history test"', g:history[0].command
91 AssertEqual ['/bin/sh', '-c', '/bin/sh -c ''echo command history test'''], g:history[0].command
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)
99 Execute(History should be not set when disabled):
100 AssertEqual 'foobar', &filetype
102 let g:ale_history_enabled = 0
105 call ale#test#FlushJobs()
107 AssertEqual [], ale#history#Get(bufnr(''))
109 Execute(History should include command output if logging is enabled):
110 AssertEqual 'foobar', &filetype
112 let g:ale_history_log_output = 1
114 " Retry this test until it works. This one can randomly fail.
115 let b:ale_history = []
117 call ale#test#FlushJobs()
119 let g:history = ale#history#Get(bufnr(''))
121 AssertEqual 1, len(g:history)
123 \ ['command history test'],
125 \ copy(get(g:history[0], 'output', [])),
126 \ 'substitute(v:val, ''[\r ]*$'', '''', ''g'')'
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''}')
132 call ale#history#Add(bufnr(''), 'started', 347, 'last command')
136 \ map(range(1, 19), '{''status'': ''started'', ''job_id'': v:val, ''command'': ''foobar''}')
137 \ + [{'status': 'started', 'job_id': 347, 'command': 'last command'}]
139 \ ale#history#Get(bufnr(''))
141 Execute(Nothing should be added to history if the size is too low):
142 let g:ale_max_buffer_history_size = 0
144 call ale#history#Add(bufnr(''), 'started', 347, 'last command')
146 AssertEqual [], ale#history#Get(bufnr(''))
148 let g:ale_max_buffer_history_size = -2
150 call ale#history#Add(1, 'started', 347, 'last command')
152 AssertEqual [], ale#history#Get(bufnr(''))
154 Given foobar(Some file with an imaginary filetype):
159 Execute(The history should be updated when fixers are run):
160 call ale#test#SetFilename('dummy.txt')
162 let b:ale_fixers = {'foobar': ['TestFixer']}
163 let b:ale_enabled = 0
167 AssertEqual ['started'], map(copy(b:ale_history), 'v:val.status')
169 call ale#test#FlushJobs()
171 AssertEqual ['finished'], map(copy(b:ale_history), 'v:val.status')
174 AssertEqual 'cmd /s/c "echo foo ', split(b:ale_history[0].command, '<')[0]
176 AssertEqual '/bin/sh -c echo foo ', split(join(b:ale_history[0].command), '<')[0]