mirror of
https://github.com/dense-analysis/ale
synced 2024-12-15 02:45:48 +00:00
103 lines
3.0 KiB
Plaintext
103 lines
3.0 KiB
Plaintext
Before:
|
|
" Temporarily set the shell to /bin/sh, if it isn't already set that way.
|
|
" This will make it so the test works when running it directly.
|
|
let g:current_shell = &shell
|
|
let &shell = '/bin/sh'
|
|
let g:history = []
|
|
let g:ale_buffer_info = {}
|
|
let g:ale_max_buffer_history_size = 20
|
|
|
|
function! CollectResults(buffer, output)
|
|
return []
|
|
endfunction
|
|
|
|
call ale#linter#Define('foobar', {
|
|
\ 'name': 'testlinter',
|
|
\ 'callback': 'CollectResults',
|
|
\ 'executable': 'echo',
|
|
\ 'command': 'echo command history test',
|
|
\ 'read_buffer': 0,
|
|
\})
|
|
|
|
After:
|
|
" Reset the shell back to what it was before.
|
|
let &shell = g:current_shell
|
|
unlet g:current_shell
|
|
let g:ale_history_enabled = 1
|
|
let g:ale_history_log_output = 0
|
|
unlet g:history
|
|
let g:ale_buffer_info = {}
|
|
let g:ale_max_buffer_history_size = 20
|
|
call ale#linter#Reset()
|
|
delfunction CollectResults
|
|
|
|
Given foobar (Some imaginary filetype):
|
|
anything
|
|
|
|
Execute(History should be set when commands are run):
|
|
AssertEqual 'foobar', &filetype
|
|
|
|
call ale#Lint()
|
|
call ale#engine#WaitForJobs(2000)
|
|
|
|
let g:history = g:ale_buffer_info[bufnr('%')].history
|
|
|
|
AssertEqual 1, len(g:history)
|
|
AssertEqual sort(['status', 'exit_code', 'job_id', 'command']), sort(keys(g:history[0]))
|
|
AssertEqual ['/bin/sh', '-c', 'echo command history test'], g:history[0].command
|
|
AssertEqual 'finished', g:history[0].status
|
|
AssertEqual 0, g:history[0].exit_code
|
|
" The Job ID will change each time, but we can check the type.
|
|
AssertEqual type(1), type(g:history[0].job_id)
|
|
|
|
Execute(History should be not set when disabled):
|
|
AssertEqual 'foobar', &filetype
|
|
|
|
let g:ale_history_enabled = 0
|
|
|
|
call ale#Lint()
|
|
call ale#engine#WaitForJobs(2000)
|
|
|
|
AssertEqual 0, len(g:ale_buffer_info[bufnr('%')].history)
|
|
|
|
Execute(History should include command output if logging is enabled):
|
|
AssertEqual 'foobar', &filetype
|
|
|
|
let g:ale_history_log_output = 1
|
|
|
|
call ale#Lint()
|
|
call ale#engine#WaitForJobs(2000)
|
|
|
|
let g:history = g:ale_buffer_info[bufnr('%')].history
|
|
|
|
AssertEqual 1, len(g:history)
|
|
AssertEqual ['command history test'], g:history[0].output
|
|
|
|
Execute(History items should be popped after going over the max):
|
|
let g:ale_buffer_info[1] = {
|
|
\ 'history': map(range(20), '{''status'': ''started'', ''job_id'': v:val, ''command'': ''foobar''}'),
|
|
\}
|
|
|
|
call ale#history#Add(1, 'started', 347, 'last command')
|
|
|
|
AssertEqual
|
|
\ (
|
|
\ map(range(1, 19), '{''status'': ''started'', ''job_id'': v:val, ''command'': ''foobar''}')
|
|
\ + [{'status': 'started', 'job_id': 347, 'command': 'last command'}]
|
|
\ ),
|
|
\ g:ale_buffer_info[1].history
|
|
|
|
Execute(Nothing should be added to history if the size is too low):
|
|
let g:ale_max_buffer_history_size = 0
|
|
let g:ale_buffer_info[1] = {'history': []}
|
|
|
|
call ale#history#Add(1, 'started', 347, 'last command')
|
|
|
|
AssertEqual [], g:ale_buffer_info[1].history
|
|
|
|
let g:ale_max_buffer_history_size = -2
|
|
|
|
call ale#history#Add(1, 'started', 347, 'last command')
|
|
|
|
AssertEqual [], g:ale_buffer_info[1].history
|