added test for command callback

This commit is contained in:
Colby Dehart 2018-06-06 22:58:32 -05:00
parent 81739be0a0
commit f0f569f14a
2 changed files with 46 additions and 1 deletions

View file

@ -30,8 +30,16 @@ function! ale_linters#elixir#mix#Handle(buffer, lines) abort
return l:output
endfunction
function! ale_linters#elixir#mix#FindProjectRoot(buffer) abort
let l:project_root = ale#path#FindNearestFile(a:buffer, 'mix.exs')
if !empty(l:project_root)
return fnamemodify(l:project_root, ':h')
endif
return ''
endfunction
function! ale_linters#elixir#mix#GetCommand(buffer) abort
let l:project_root = fnamemodify(ale#path#FindNearestFile(a:buffer, 'mix.exs'), ':h')
let l:project_root = ale_linters#elixir#mix#FindProjectRoot(a:buffer)
let l:temp_dir = ale#engine#CreateDirectory(a:buffer)
@ -49,4 +57,5 @@ call ale#linter#Define('elixir', {
\ 'executable': 'mix',
\ 'command_callback': 'ale_linters#elixir#mix#GetCommand',
\ 'callback': 'ale_linters#elixir#mix#Handle',
\ 'lint_file': 1,
\})

View file

@ -0,0 +1,36 @@
Before:
runtime ale_linters/elixir/mix.vim
call ale#test#SetDirectory('/testplugin/test/command_callback')
let g:env_prefix = has('win32')
\ ? 'set MIX_BUILD_PATH=TEMP && '
\ : 'MIX_BUILD_PATH=TEMP '
function! GetCommand() abort
let l:command = ale_linters#elixir#mix#GetCommand(bufnr(''))
let l:split_command = split(l:command, 'MIX_BUILD_PATH=[^ ]*\s')
return l:split_command[0] . 'MIX_BUILD_PATH=TEMP' . l:split_command[1]
endfunction
After:
Restore
unlet! g:env_prefix
call ale#linter#Reset()
call ale#test#RestoreDirectory()
delfunction GetCommand
Execute(The default mix command should be correct):
AssertEqual
\ GetCommand(),
\ 'cd '''' && '
\ . g:env_prefix
\ . 'mix compile %s'