2017-02-14 18:44:37 -05:00
|
|
|
Before:
|
2017-06-06 14:54:10 -04:00
|
|
|
Save g:ale_max_buffer_history_size
|
|
|
|
Save g:ale_history_log_output
|
2017-08-31 11:46:40 -04:00
|
|
|
Save g:ale_run_synchronously
|
2017-06-06 14:54:10 -04:00
|
|
|
|
2017-08-31 11:46:40 -04:00
|
|
|
unlet! b:ale_fixers
|
|
|
|
unlet! b:ale_enabled
|
2017-08-25 17:22:26 -04:00
|
|
|
unlet! b:ale_history
|
|
|
|
|
2017-04-02 17:57:29 -04:00
|
|
|
" 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
|
2017-09-10 19:47:27 -04:00
|
|
|
|
|
|
|
if !has('win32')
|
|
|
|
let &shell = '/bin/sh'
|
|
|
|
endif
|
|
|
|
|
2017-02-14 18:44:37 -05:00
|
|
|
let g:history = []
|
|
|
|
let g:ale_buffer_info = {}
|
|
|
|
let g:ale_max_buffer_history_size = 20
|
2017-06-06 14:54:10 -04:00
|
|
|
let g:ale_history_log_output = 0
|
2017-02-14 18:44:37 -05:00
|
|
|
|
2017-08-31 11:46:40 -04:00
|
|
|
function! TestFixer(buffer)
|
|
|
|
return {'command': 'echo foo'}
|
|
|
|
endfunction
|
|
|
|
|
2017-02-14 18:44:37 -05:00
|
|
|
function! CollectResults(buffer, output)
|
|
|
|
return []
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('foobar', {
|
|
|
|
\ 'name': 'testlinter',
|
|
|
|
\ 'callback': 'CollectResults',
|
2017-09-10 19:47:27 -04:00
|
|
|
\ 'executable': has('win32') ? 'cmd' : 'echo',
|
|
|
|
\ 'command': has('win32')
|
|
|
|
\ ? 'echo command history test'
|
|
|
|
\ : '/bin/sh -c ''echo command history test''',
|
2017-02-14 18:44:37 -05:00
|
|
|
\ 'read_buffer': 0,
|
|
|
|
\})
|
|
|
|
|
|
|
|
After:
|
2017-06-06 14:54:10 -04:00
|
|
|
Restore
|
|
|
|
|
2018-07-15 16:20:56 -04:00
|
|
|
unlet! g:expected_results
|
2017-08-31 11:46:40 -04:00
|
|
|
unlet! b:ale_fixers
|
|
|
|
unlet! b:ale_enabled
|
2017-08-25 17:22:26 -04:00
|
|
|
" Clear the history we changed.
|
|
|
|
unlet! b:ale_history
|
|
|
|
|
2017-04-02 17:57:29 -04:00
|
|
|
" Reset the shell back to what it was before.
|
|
|
|
let &shell = g:current_shell
|
|
|
|
unlet g:current_shell
|
2017-02-16 16:33:44 -05:00
|
|
|
let g:ale_history_enabled = 1
|
2017-02-16 18:18:57 -05:00
|
|
|
let g:ale_history_log_output = 0
|
2017-02-14 18:44:37 -05:00
|
|
|
unlet g:history
|
2018-06-28 08:53:49 -04:00
|
|
|
|
|
|
|
call ale#engine#Cleanup(bufnr(''))
|
|
|
|
call ale#linter#Reset()
|
|
|
|
|
2017-02-14 18:44:37 -05:00
|
|
|
let g:ale_buffer_info = {}
|
|
|
|
let g:ale_max_buffer_history_size = 20
|
2017-08-31 11:46:40 -04:00
|
|
|
delfunction TestFixer
|
2017-02-14 18:44:37 -05:00
|
|
|
delfunction CollectResults
|
|
|
|
|
|
|
|
Given foobar (Some imaginary filetype):
|
|
|
|
anything
|
|
|
|
|
|
|
|
Execute(History should be set when commands are run):
|
|
|
|
AssertEqual 'foobar', &filetype
|
|
|
|
|
2018-07-15 16:20:56 -04:00
|
|
|
let g:expected_results = ['command', 'exit_code', 'job_id', 'status']
|
|
|
|
|
|
|
|
" Retry this test until it works. This one can randomly fail.
|
|
|
|
for g:i in range(has('nvim-0.3') || has('win32') ? 5 : 1)
|
|
|
|
let b:ale_history = []
|
|
|
|
call ale#Lint()
|
|
|
|
call ale#engine#WaitForJobs(2000)
|
|
|
|
|
|
|
|
let g:history = filter(
|
|
|
|
\ copy(ale#history#Get(bufnr(''))),
|
|
|
|
\ 'v:val.job_id isnot# ''executable''',
|
|
|
|
\)
|
|
|
|
|
|
|
|
AssertEqual 1, len(g:history)
|
2017-02-14 18:44:37 -05:00
|
|
|
|
2018-07-15 16:20:56 -04:00
|
|
|
if sort(keys(g:history[0])) == g:expected_results
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
2017-02-14 18:44:37 -05:00
|
|
|
|
2018-07-15 16:20:56 -04:00
|
|
|
AssertEqual g:expected_results, sort(keys(g:history[0]))
|
2017-09-10 19:47:27 -04:00
|
|
|
|
|
|
|
if has('win32')
|
2018-01-17 13:08:17 -05:00
|
|
|
AssertEqual 'cmd /s/c "echo command history test"', g:history[0].command
|
2017-09-10 19:47:27 -04:00
|
|
|
else
|
|
|
|
AssertEqual ['/bin/sh', '-c', '/bin/sh -c ''echo command history test'''], g:history[0].command
|
|
|
|
endif
|
|
|
|
|
2017-02-16 17:19:53 -05:00
|
|
|
AssertEqual 'finished', g:history[0].status
|
|
|
|
AssertEqual 0, g:history[0].exit_code
|
2017-02-14 18:44:37 -05:00
|
|
|
" The Job ID will change each time, but we can check the type.
|
|
|
|
AssertEqual type(1), type(g:history[0].job_id)
|
|
|
|
|
2017-02-16 16:33:44 -05:00
|
|
|
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)
|
|
|
|
|
2017-08-25 17:22:26 -04:00
|
|
|
AssertEqual [], ale#history#Get(bufnr(''))
|
2017-02-16 16:33:44 -05:00
|
|
|
|
2017-02-16 18:18:57 -05:00
|
|
|
Execute(History should include command output if logging is enabled):
|
|
|
|
AssertEqual 'foobar', &filetype
|
|
|
|
|
|
|
|
let g:ale_history_log_output = 1
|
2018-07-15 16:20:56 -04:00
|
|
|
let g:expected_results = ['command history test']
|
2017-02-16 18:18:57 -05:00
|
|
|
|
2018-07-15 16:20:56 -04:00
|
|
|
" Retry this test until it works. This one can randomly fail.
|
|
|
|
for g:i in range(has('nvim-0.3') || has('win32') ? 5 : 1)
|
|
|
|
let b:ale_history = []
|
|
|
|
call ale#Lint()
|
|
|
|
call ale#engine#WaitForJobs(2000)
|
|
|
|
|
|
|
|
let g:history = ale#history#Get(bufnr(''))
|
|
|
|
|
|
|
|
AssertEqual 1, len(g:history)
|
2017-02-16 18:18:57 -05:00
|
|
|
|
2018-07-15 16:20:56 -04:00
|
|
|
if get(g:history[0], 'output', []) == g:expected_results
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
2017-02-16 18:18:57 -05:00
|
|
|
|
2018-07-15 16:20:56 -04:00
|
|
|
AssertEqual g:expected_results, get(g:history[0], 'output', [])
|
2017-02-16 18:18:57 -05:00
|
|
|
|
2017-02-14 18:44:37 -05:00
|
|
|
Execute(History items should be popped after going over the max):
|
2017-08-25 17:22:26 -04:00
|
|
|
let b:ale_history = map(range(20), '{''status'': ''started'', ''job_id'': v:val, ''command'': ''foobar''}')
|
2017-02-14 18:44:37 -05:00
|
|
|
|
2017-08-25 17:22:26 -04:00
|
|
|
call ale#history#Add(bufnr(''), 'started', 347, 'last command')
|
2017-02-14 18:44:37 -05:00
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ (
|
2017-02-16 16:18:03 -05:00
|
|
|
\ map(range(1, 19), '{''status'': ''started'', ''job_id'': v:val, ''command'': ''foobar''}')
|
|
|
|
\ + [{'status': 'started', 'job_id': 347, 'command': 'last command'}]
|
2017-02-14 18:44:37 -05:00
|
|
|
\ ),
|
2017-08-25 17:22:26 -04:00
|
|
|
\ ale#history#Get(bufnr(''))
|
2017-02-14 18:44:37 -05:00
|
|
|
|
|
|
|
Execute(Nothing should be added to history if the size is too low):
|
|
|
|
let g:ale_max_buffer_history_size = 0
|
|
|
|
|
2017-08-25 17:22:26 -04:00
|
|
|
call ale#history#Add(bufnr(''), 'started', 347, 'last command')
|
2017-02-14 18:44:37 -05:00
|
|
|
|
2017-08-25 17:22:26 -04:00
|
|
|
AssertEqual [], ale#history#Get(bufnr(''))
|
2017-02-14 18:44:37 -05:00
|
|
|
|
|
|
|
let g:ale_max_buffer_history_size = -2
|
|
|
|
|
2017-02-16 16:18:03 -05:00
|
|
|
call ale#history#Add(1, 'started', 347, 'last command')
|
2017-02-14 18:44:37 -05:00
|
|
|
|
2017-08-25 17:22:26 -04:00
|
|
|
AssertEqual [], ale#history#Get(bufnr(''))
|
2017-08-31 11:46:40 -04:00
|
|
|
|
|
|
|
Given foobar(Some file with an imaginary filetype):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
|
|
|
|
Execute(The history should be updated when fixers are run):
|
2017-09-10 19:47:27 -04:00
|
|
|
call ale#test#SetFilename('dummy.txt')
|
|
|
|
|
2017-08-31 11:46:40 -04:00
|
|
|
let b:ale_fixers = {'foobar': ['TestFixer']}
|
|
|
|
let b:ale_enabled = 0
|
|
|
|
let g:ale_run_synchronously = 1
|
|
|
|
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
AssertEqual ['finished'], map(copy(b:ale_history), 'v:val.status')
|
2017-09-10 19:47:27 -04:00
|
|
|
|
|
|
|
if has('win32')
|
2018-01-17 13:08:17 -05:00
|
|
|
AssertEqual 'cmd /s/c "echo foo ', split(b:ale_history[0].command, '<')[0]
|
2017-09-10 19:47:27 -04:00
|
|
|
else
|
|
|
|
AssertEqual '/bin/sh -c echo foo ', split(join(b:ale_history[0].command), '<')[0]
|
|
|
|
endif
|