Fix ALEInfo and some test issues

This commit is contained in:
w0rp 2017-05-27 23:51:27 +01:00
parent aca5a00fb7
commit c17346d402
4 changed files with 183 additions and 186 deletions

View File

@ -109,14 +109,14 @@ function! s:EchoLinterAliases(all_linters) abort
let l:first = 1 let l:first = 1
for l:linter in a:all_linters for l:linter in a:all_linters
if !empty(l:linter.aliaes) if !empty(l:linter.aliases)
if !l:first if l:first
echom ' Linter Aliases:' echom ' Linter Aliases:'
endif endif
let l:first = 0 let l:first = 0
echom string(l:linter.name) . ' -> ' . string(l:linter.aliaes) echom string(l:linter.name) . ' -> ' . string(l:linter.aliases)
endif endif
endfor endfor
endfunction endfunction
@ -138,11 +138,6 @@ function! ale#debugging#Info() abort
let l:all_names = map(copy(l:all_linters), 'v:val[''name'']') let l:all_names = map(copy(l:all_linters), 'v:val[''name'']')
let l:enabled_names = map(copy(l:enabled_linters), 'v:val[''name'']') let l:enabled_names = map(copy(l:enabled_linters), 'v:val[''name'']')
let l:linter_aliases = []
for l:linter in l:all_linters
call add(l:linter_aliases, [l:linter.name, l:linter.aliaes])
endfor
" Load linter variables to display " Load linter variables to display
" This must be done after linters are loaded. " This must be done after linters are loaded.

View File

@ -4,7 +4,7 @@
let s:linters = {} let s:linters = {}
" Default filetype aliaes. " Default filetype aliases.
" The user defined aliases will be merged with this Dictionary. " The user defined aliases will be merged with this Dictionary.
let s:default_ale_linter_aliases = { let s:default_ale_linter_aliases = {
\ 'Dockerfile': 'dockerfile', \ 'Dockerfile': 'dockerfile',

View File

@ -1,4 +1,9 @@
Before: Before:
Save g:ale_warn_about_trailing_whitespace
Save g:ale_linters
let g:ale_warn_about_trailing_whitespace = 1
let g:testlinter1 = {'name': 'testlinter1', 'executable': 'testlinter1', 'command': 'testlinter1', 'callback': 'testCB1', 'output_stream': 'stdout'} let g:testlinter1 = {'name': 'testlinter1', 'executable': 'testlinter1', 'command': 'testlinter1', 'callback': 'testCB1', 'output_stream': 'stdout'}
let g:testlinter2 = {'name': 'testlinter2', 'executable': 'testlinter2', 'command': 'testlinter2', 'callback': 'testCB2', 'output_stream': 'stdout'} let g:testlinter2 = {'name': 'testlinter2', 'executable': 'testlinter2', 'command': 'testlinter2', 'callback': 'testCB2', 'output_stream': 'stdout'}
@ -6,8 +11,7 @@ Before:
let g:ale_linters = {} let g:ale_linters = {}
let g:ale_linter_aliases = {} let g:ale_linter_aliases = {}
let g:ale_buffer_info = {} let g:ale_buffer_info = {}
let g:globals_string = join([ let g:globals_lines = [
\ '',
\ ' Global Variables:', \ ' Global Variables:',
\ '', \ '',
\ 'let g:ale_echo_cursor = 1', \ 'let g:ale_echo_cursor = 1',
@ -33,10 +37,29 @@ Before:
\ 'let g:ale_sign_warning = ''--''', \ 'let g:ale_sign_warning = ''--''',
\ 'let g:ale_statusline_format = [''%d error(s)'', ''%d warning(s)'', ''OK'']', \ 'let g:ale_statusline_format = [''%d error(s)'', ''%d warning(s)'', ''OK'']',
\ 'let g:ale_warn_about_trailing_whitespace = 1', \ 'let g:ale_warn_about_trailing_whitespace = 1',
\], "\n") \]
let g:command_header = "\n Command History:\n" let g:command_header = [
\ ' Command History:',
\]
function CheckInfo(expected_list) abort
let l:output = ''
redir => l:output
noautocmd silent ALEInfo
redir END
AssertEqual a:expected_list, split(l:output, "\n")
endfunction
After: After:
Restore
let g:ale_buffer_info = {}
unlet! g:testlinter1
unlet! g:testlinter2
unlet! b:ale_linters unlet! b:ale_linters
unlet! g:output unlet! g:output
unlet! g:globals_string unlet! g:globals_string
@ -48,121 +71,113 @@ After:
unlet! g:ale_testft2_testlinter2_foo unlet! g:ale_testft2_testlinter2_foo
unlet! b:ale_testft2_testlinter2_foo unlet! b:ale_testft2_testlinter2_foo
unlet! g:ale_testft2_testlinter2_bar unlet! g:ale_testft2_testlinter2_bar
delfunction CheckInfo
Given nolintersft (Empty buffer with no linters): Given nolintersft (Empty buffer with no linters):
Execute (ALEInfo with no linters should return the right output): Execute (ALEInfo with no linters should return the right output):
redir => g:output call CheckInfo([
silent ALEInfo \ ' Current Filetype: nolintersft',
redir END \ 'Available Linters: []',
AssertEqual "\n \ ' Enabled Linters: []',
\ Current Filetype: nolintersft\n \ ' Linter Variables:',
\Available Linters: []\n \ '',
\ Enabled Linters: []\n \] + g:globals_lines + g:command_header)
\ Linter Variables:\n
\" . g:globals_string . g:command_header, g:output
Given (Empty buffer with no filetype): Given (Empty buffer with no filetype):
Execute (ALEInfo should return buffer-local global ALE settings): Execute (ALEInfo should return buffer-local global ALE settings):
let b:ale_linters = {'x': ['y']} let b:ale_linters = {'x': ['y']}
let g:globals_string = substitute(
\ g:globals_string, call insert(
\ 'let g:ale_linters = {}', \ g:globals_lines,
\ "let g:ale_linters = {}\nlet b:ale_linters = {'x': ['y']}", \ 'let b:ale_linters = {''x'': [''y'']}',
\ '' \ index(g:globals_lines, 'let g:ale_linters = {}') + 1
\) \)
redir => g:output call CheckInfo([
silent ALEInfo \ ' Current Filetype: ',
redir END \ 'Available Linters: []',
AssertEqual "\n \ ' Enabled Linters: []',
\ Current Filetype: \n \ ' Linter Variables:',
\Available Linters: []\n \ '',
\ Enabled Linters: []\n \] + g:globals_lines + g:command_header)
\ Linter Variables:\n
\" . g:globals_string . g:command_header, g:output
Given (Empty buffer with no filetype): Given (Empty buffer with no filetype):
Execute (ALEInfo with no filetype should return the right output): Execute (ALEInfo with no filetype should return the right output):
redir => g:output call CheckInfo([
silent ALEInfo \ ' Current Filetype: ',
redir END \ 'Available Linters: []',
AssertEqual "\n \ ' Enabled Linters: []',
\ Current Filetype: \n \ ' Linter Variables:',
\Available Linters: []\n \ '',
\ Enabled Linters: []\n \] + g:globals_lines + g:command_header)
\ Linter Variables:\n
\" . g:globals_string . g:command_header, g:output
Given testft (Empty buffer): Given testft (Empty buffer):
Execute (ALEInfo with a single linter should return the right output): Execute (ALEInfo with a single linter should return the right output):
call ale#linter#Define('testft', g:testlinter1) call ale#linter#Define('testft', g:testlinter1)
redir => g:output
silent ALEInfo call CheckInfo([
redir END \ ' Current Filetype: testft',
AssertEqual "\n \ 'Available Linters: [''testlinter1'']',
\ Current Filetype: testft\n \ ' Enabled Linters: [''testlinter1'']',
\Available Linters: ['testlinter1']\n \ ' Linter Variables:',
\ Enabled Linters: ['testlinter1']\n \ '',
\ Linter Variables:\n \] + g:globals_lines + g:command_header)
\" . g:globals_string . g:command_header, g:output
Given testft (Empty buffer): Given testft (Empty buffer):
Execute (ALEInfo with two linters should return the right output): Execute (ALEInfo with two linters should return the right output):
call ale#linter#Define('testft', g:testlinter1) call ale#linter#Define('testft', g:testlinter1)
call ale#linter#Define('testft', g:testlinter2) call ale#linter#Define('testft', g:testlinter2)
redir => g:output
silent ALEInfo call CheckInfo([
redir END \ ' Current Filetype: testft',
AssertEqual "\n \ 'Available Linters: [''testlinter1'', ''testlinter2'']',
\ Current Filetype: testft\n \ ' Enabled Linters: [''testlinter1'', ''testlinter2'']',
\Available Linters: ['testlinter1', 'testlinter2']\n \ ' Linter Variables:',
\ Enabled Linters: ['testlinter1', 'testlinter2']\n \ '',
\ Linter Variables:\n \] + g:globals_lines + g:command_header)
\" . g:globals_string . g:command_header, g:output
Given testft (Empty buffer): Given testft (Empty buffer):
Execute (ALEInfo should calculate enabled linters correctly): Execute (ALEInfo should calculate enabled linters correctly):
call ale#linter#Define('testft', g:testlinter1) call ale#linter#Define('testft', g:testlinter1)
call ale#linter#Define('testft', g:testlinter2) call ale#linter#Define('testft', g:testlinter2)
let g:ale_linters = { 'testft': ['testlinter2'] } let g:ale_linters = {'testft': ['testlinter2']}
redir => g:output
silent ALEInfo let g:globals_lines[index(g:globals_lines, 'let g:ale_linters = {}')]
redir END \ = 'let g:ale_linters = {''testft'': [''testlinter2'']}'
AssertEqual "\n
\ Current Filetype: testft\n call CheckInfo([
\Available Linters: ['testlinter1', 'testlinter2']\n \ ' Current Filetype: testft',
\ Enabled Linters: ['testlinter2']\n \ 'Available Linters: [''testlinter1'', ''testlinter2'']',
\ Linter Variables:\n \ ' Enabled Linters: [''testlinter2'']',
\", \ ' Linter Variables:',
\ "\n" . join(split(g:output, "\n")[:4], "\n") \ '',
\] + g:globals_lines + g:command_header)
Given testft (Empty buffer): Given testft (Empty buffer):
Execute (ALEInfo should only return linters for current filetype): Execute (ALEInfo should only return linters for current filetype):
call ale#linter#Define('testft', g:testlinter1) call ale#linter#Define('testft', g:testlinter1)
call ale#linter#Define('testft2', g:testlinter2) call ale#linter#Define('testft2', g:testlinter2)
redir => g:output
silent ALEInfo call CheckInfo([
redir END \ ' Current Filetype: testft',
AssertEqual "\n \ 'Available Linters: [''testlinter1'']',
\ Current Filetype: testft\n \ ' Enabled Linters: [''testlinter1'']',
\Available Linters: ['testlinter1']\n \ ' Linter Variables:',
\ Enabled Linters: ['testlinter1']\n \ '',
\ Linter Variables:\n \] + g:globals_lines + g:command_header)
\" . g:globals_string . g:command_header, g:output
Given testft.testft2 (Empty buffer with two filetypes): Given testft.testft2 (Empty buffer with two filetypes):
Execute (ALEInfo with compound filetypes should return linters for both of them): Execute (ALEInfo with compound filetypes should return linters for both of them):
call ale#linter#Define('testft', g:testlinter1) call ale#linter#Define('testft', g:testlinter1)
call ale#linter#Define('testft2', g:testlinter2) call ale#linter#Define('testft2', g:testlinter2)
redir => g:output
silent ALEInfo call CheckInfo([
redir END \ ' Current Filetype: testft.testft2',
AssertEqual "\n \ 'Available Linters: [''testlinter1'', ''testlinter2'']',
\ Current Filetype: testft.testft2\n \ ' Enabled Linters: [''testlinter1'', ''testlinter2'']',
\Available Linters: ['testlinter1', 'testlinter2']\n \ ' Linter Variables:',
\ Enabled Linters: ['testlinter1', 'testlinter2']\n \ '',
\ Linter Variables:\n \] + g:globals_lines + g:command_header)
\" . g:globals_string . g:command_header, g:output
Given testft.testft2 (Empty buffer with two filetypes): Given testft.testft2 (Empty buffer with two filetypes):
Execute (ALEInfo should return appropriately named global variables): Execute (ALEInfo should return appropriately named global variables):
@ -173,20 +188,18 @@ Execute (ALEInfo should return appropriately named global variables):
call ale#linter#Define('testft', g:testlinter1) call ale#linter#Define('testft', g:testlinter1)
call ale#linter#Define('testft2', g:testlinter2) call ale#linter#Define('testft2', g:testlinter2)
redir => g:output
silent ALEInfo call CheckInfo([
redir END \ ' Current Filetype: testft.testft2',
AssertEqual "\n \ 'Available Linters: [''testlinter1'', ''testlinter2'']',
\ Current Filetype: testft.testft2\n \ ' Enabled Linters: [''testlinter1'', ''testlinter2'']',
\Available Linters: ['testlinter1', 'testlinter2']\n \ ' Linter Variables:',
\ Enabled Linters: ['testlinter1', 'testlinter2']\n \ '',
\ Linter Variables:\n \ 'let g:ale_testft2_testlinter2_bar = {''x'': ''y''}',
\\n \ 'let g:ale_testft2_testlinter2_foo = 123',
\let g:ale_testft2_testlinter2_bar = {'x': 'y'}\n \ 'let g:ale_testft_testlinter1_bar = [''abc'']',
\let g:ale_testft2_testlinter2_foo = 123\n \ 'let g:ale_testft_testlinter1_foo = ''abc''',
\let g:ale_testft_testlinter1_bar = ['abc']\n \] + g:globals_lines + g:command_header)
\let g:ale_testft_testlinter1_foo = 'abc'"
\ . g:globals_string . g:command_header, g:output
Given testft.testft2 (Empty buffer with two filetypes): Given testft.testft2 (Empty buffer with two filetypes):
Execute (ALEInfo should buffer-local linter variables): Execute (ALEInfo should buffer-local linter variables):
@ -195,18 +208,16 @@ Execute (ALEInfo should buffer-local linter variables):
call ale#linter#Define('testft', g:testlinter1) call ale#linter#Define('testft', g:testlinter1)
call ale#linter#Define('testft2', g:testlinter2) call ale#linter#Define('testft2', g:testlinter2)
redir => g:output
silent ALEInfo call CheckInfo([
redir END \ ' Current Filetype: testft.testft2',
AssertEqual "\n \ 'Available Linters: [''testlinter1'', ''testlinter2'']',
\ Current Filetype: testft.testft2\n \ ' Enabled Linters: [''testlinter1'', ''testlinter2'']',
\Available Linters: ['testlinter1', 'testlinter2']\n \ ' Linter Variables:',
\ Enabled Linters: ['testlinter1', 'testlinter2']\n \ '',
\ Linter Variables:\n \ 'let g:ale_testft2_testlinter2_foo = 123',
\\n \ 'let b:ale_testft2_testlinter2_foo = 456',
\let g:ale_testft2_testlinter2_foo = 123\n \] + g:globals_lines + g:command_header)
\let b:ale_testft2_testlinter2_foo = 456"
\ . g:globals_string . g:command_header, g:output
Given testft.testft2 (Empty buffer with two filetypes): Given testft.testft2 (Empty buffer with two filetypes):
Execute (ALEInfo should output linter aliases): Execute (ALEInfo should output linter aliases):
@ -218,21 +229,19 @@ Execute (ALEInfo should output linter aliases):
call ale#linter#Define('testft', g:testlinter1) call ale#linter#Define('testft', g:testlinter1)
call ale#linter#Define('testft2', g:testlinter2) call ale#linter#Define('testft2', g:testlinter2)
redir => g:output
silent ALEInfo call CheckInfo([
redir END \ ' Current Filetype: testft.testft2',
AssertEqual "\n \ 'Available Linters: [''testlinter1'', ''testlinter2'']',
\ Current Filetype: testft.testft2\n \ ' Linter Aliases:',
\Available Linters: ['testlinter1', 'testlinter2']\n \ '''testlinter1'' -> [''testftalias1'', ''testftalias2'']',
\ Linter Aliases:\n \ '''testlinter2'' -> [''testftalias3'', ''testftalias4'']',
\ 'testlinter1' -> ['testftalias1', 'testftalias2']\n \ ' Enabled Linters: [''testlinter1'', ''testlinter2'']',
\ 'testlinter2' -> ['testftalias3', 'testftalias4']\n \ ' Linter Variables:',
\ Enabled Linters: ['testlinter1', 'testlinter2']\n \ '',
\ Linter Variables:\n \ 'let g:ale_testft2_testlinter2_foo = 123',
\\n \ 'let b:ale_testft2_testlinter2_foo = 456',
\let g:ale_testft2_testlinter2_foo = 123\n \] + g:globals_lines + g:command_header)
\let b:ale_testft2_testlinter2_foo = 456"
\ . g:globals_string . g:command_header, g:output
Given testft.testft2 (Empty buffer with two filetypes): Given testft.testft2 (Empty buffer with two filetypes):
Execute (ALEInfo should return command history): Execute (ALEInfo should return command history):
@ -245,21 +254,18 @@ Execute (ALEInfo should return command history):
call ale#linter#Define('testft', g:testlinter1) call ale#linter#Define('testft', g:testlinter1)
call ale#linter#Define('testft2', g:testlinter2) call ale#linter#Define('testft2', g:testlinter2)
redir => g:output
silent ALEInfo call CheckInfo([
redir END
AssertEqual
\ join([
\ '',
\ ' Current Filetype: testft.testft2', \ ' Current Filetype: testft.testft2',
\ 'Available Linters: [''testlinter1'', ''testlinter2'']', \ 'Available Linters: [''testlinter1'', ''testlinter2'']',
\ ' Enabled Linters: [''testlinter1'', ''testlinter2'']', \ ' Enabled Linters: [''testlinter1'', ''testlinter2'']',
\ ' Linter Variables:', \ ' Linter Variables:',
\ g:globals_string . g:command_header, \ '',
\ '(started) ''first command''', \] + g:globals_lines + g:command_header + [
\ '(started) [''/bin/bash'', ''\c'', ''last command'']', \ '',
\ ], "\n"), \ '(started) ''first command''',
\ g:output \ '(started) [''/bin/bash'', ''\c'', ''last command'']',
\])
Given testft.testft2 (Empty buffer with two filetypes): Given testft.testft2 (Empty buffer with two filetypes):
Execute (ALEInfo command history should print exit codes correctly): Execute (ALEInfo command history should print exit codes correctly):
@ -272,21 +278,18 @@ Execute (ALEInfo command history should print exit codes correctly):
call ale#linter#Define('testft', g:testlinter1) call ale#linter#Define('testft', g:testlinter1)
call ale#linter#Define('testft2', g:testlinter2) call ale#linter#Define('testft2', g:testlinter2)
redir => g:output
silent ALEInfo call CheckInfo([
redir END
AssertEqual
\ join([
\ '',
\ ' Current Filetype: testft.testft2', \ ' Current Filetype: testft.testft2',
\ 'Available Linters: [''testlinter1'', ''testlinter2'']', \ 'Available Linters: [''testlinter1'', ''testlinter2'']',
\ ' Enabled Linters: [''testlinter1'', ''testlinter2'']', \ ' Enabled Linters: [''testlinter1'', ''testlinter2'']',
\ ' Linter Variables:', \ ' Linter Variables:',
\ g:globals_string . g:command_header, \ '',
\ '(finished - exit code 0) ''first command''', \] + g:globals_lines + g:command_header + [
\ '(finished - exit code 1) [''/bin/bash'', ''\c'', ''last command'']', \ '',
\ ], "\n"), \ '(finished - exit code 0) ''first command''',
\ g:output \ '(finished - exit code 1) [''/bin/bash'', ''\c'', ''last command'']',
\])
Given testft.testft2 (Empty buffer with two filetypes): Given testft.testft2 (Empty buffer with two filetypes):
Execute (ALEInfo command history should print command output if logging is on): Execute (ALEInfo command history should print command output if logging is on):
@ -320,33 +323,29 @@ Execute (ALEInfo command history should print command output if logging is on):
call ale#linter#Define('testft', g:testlinter1) call ale#linter#Define('testft', g:testlinter1)
call ale#linter#Define('testft2', g:testlinter2) call ale#linter#Define('testft2', g:testlinter2)
redir => g:output
silent ALEInfo call CheckInfo([
redir END
AssertEqual
\ join([
\ '',
\ ' Current Filetype: testft.testft2', \ ' Current Filetype: testft.testft2',
\ 'Available Linters: [''testlinter1'', ''testlinter2'']', \ 'Available Linters: [''testlinter1'', ''testlinter2'']',
\ ' Enabled Linters: [''testlinter1'', ''testlinter2'']', \ ' Enabled Linters: [''testlinter1'', ''testlinter2'']',
\ ' Linter Variables:', \ ' Linter Variables:',
\ g:globals_string . g:command_header, \ '',
\ '(finished - exit code 0) ''first command''', \] + g:globals_lines + g:command_header + [
\ '', \ '',
\ '<<<OUTPUT STARTS>>>', \ '(finished - exit code 0) ''first command''',
\ 'some', \ '',
\ 'first command output', \ '<<<OUTPUT STARTS>>>',
\ '<<<OUTPUT ENDS>>>', \ 'some',
\ '', \ 'first command output',
\ '(finished - exit code 1) [''/bin/bash'', ''\c'', ''last command'']', \ '<<<OUTPUT ENDS>>>',
\ '', \ '',
\ '<<<OUTPUT STARTS>>>', \ '(finished - exit code 1) [''/bin/bash'', ''\c'', ''last command'']',
\ 'different second command output', \ '',
\ '<<<OUTPUT ENDS>>>', \ '<<<OUTPUT STARTS>>>',
\ '', \ 'different second command output',
\ '(finished - exit code 0) ''command with no output''', \ '<<<OUTPUT ENDS>>>',
\ '', \ '',
\ '<<<NO OUTPUT RETURNED>>>', \ '(finished - exit code 0) ''command with no output''',
\ '', \ '',
\ ], "\n"), \ '<<<NO OUTPUT RETURNED>>>',
\ g:output \])

View File

@ -1,9 +1,12 @@
Given unite (A Unite.vim file): Before:
anything let g:ale_buffer_info = {}
After: After:
let g:ale_buffer_info = {} let g:ale_buffer_info = {}
Given unite (A Unite.vim file):
anything
Execute(Running ALE on a blacklisted file shouldn't change anything): Execute(Running ALE on a blacklisted file shouldn't change anything):
call ale#Lint() call ale#Lint()
call ale#engine#WaitForJobs(2000) call ale#engine#WaitForJobs(2000)