Simplify the code for most linters and tests with closures

This commit is contained in:
w0rp
2018-08-02 23:44:12 +01:00
parent 9ef266d050
commit 217284360d
102 changed files with 631 additions and 1232 deletions

View File

@@ -54,9 +54,14 @@ function! ale#assert#Linter(expected_executable, expected_command) abort
endif
else
let l:command = ale#linter#GetCommand(l:buffer, l:linter)
endif
if type(l:command) is v:t_string
" Replace %e with the escaped executable, so tests keep passing after
" linters are changed to use %e.
let l:command = substitute(l:command, '%e', '\=ale#Escape(l:executable)', 'g')
else
call map(l:command, 'substitute(v:val, ''%e'', ''\=ale#Escape(l:executable)'', ''g'')')
endif
AssertEqual
@@ -126,7 +131,9 @@ function! ale#assert#SetUpLinterTest(filetype, name) abort
execute 'runtime ale_linters/' . a:filetype . '/' . a:name . '.vim'
call ale#test#SetDirectory('/testplugin/test/command_callback')
if !exists('g:dir')
call ale#test#SetDirectory('/testplugin/test/command_callback')
endif
command! -nargs=+ WithChainResults :call ale#assert#WithChainResults(<args>)
command! -nargs=+ AssertLinter :call ale#assert#Linter(<args>)
@@ -140,14 +147,33 @@ function! ale#assert#TearDownLinterTest() abort
unlet! g:ale_create_dummy_temporary_file
let s:chain_results = []
delcommand WithChainResults
delcommand AssertLinter
delcommand AssertLinterNotExecuted
delcommand AssertLSPOptions
delcommand AssertLSPLanguage
delcommand AssertLSPProject
if exists(':WithChainResults')
delcommand WithChainResults
endif
call ale#test#RestoreDirectory()
if exists(':AssertLinter')
delcommand AssertLinter
endif
if exists(':AssertLinterNotExecuted')
delcommand AssertLinterNotExecuted
endif
if exists(':AssertLSPOptions')
delcommand AssertLSPOptions
endif
if exists(':AssertLSPLanguage')
delcommand AssertLSPLanguage
endif
if exists(':AssertLSPProject')
delcommand AssertLSPProject
endif
if exists('g:dir')
call ale#test#RestoreDirectory()
endif
Restore