Fix #124 Finish implementing command chaining, and make it work for DMD

This commit is contained in:
w0rp
2017-02-04 18:30:30 +00:00
parent 97131262ab
commit 829f87bc6a
6 changed files with 291 additions and 72 deletions

View File

@@ -0,0 +1,61 @@
Before:
let g:linter_output = []
let g:first_echo_called = 0
let g:second_echo_called = 0
let g:final_callback_called = 0
function! CollectResults(buffer, output)
let g:final_callback_called = 1
let g:linter_output = a:output
return []
endfunction
function! RunFirstEcho(buffer)
let g:first_echo_called = 1
return 'echo foo'
endfunction
function! RunSecondEcho(buffer, output)
let g:second_echo_called = 1
return 'echo bar'
endfunction
call ale#linter#Define('foobar', {
\ 'name': 'testlinter',
\ 'callback': 'CollectResults',
\ 'executable': 'echo',
\ 'command_chain': [
\ {
\ 'callback': 'RunFirstEcho',
\ 'output_stream': 'stdout',
\ },
\ {
\ 'callback': 'RunSecondEcho',
\ 'output_stream': 'stdout',
\ },
\ ],
\})
After:
unlet! g:first_echo_called
unlet! g:second_echo_called
unlet! g:final_callback_called
unlet! g:linter_output
let g:ale_buffer_info = {}
call ale#linter#Reset()
delfunction CollectResults
delfunction RunFirstEcho
delfunction RunSecondEcho
Given foobar (Some imaginary filetype):
anything
Execute(Check the results of running the chain):
AssertEqual 'foobar', &filetype
call ale#Lint()
call ale#engine#WaitForJobs(2000)
Assert g:first_echo_called, 'The first chain item was not called'
Assert g:second_echo_called, 'The second chain item was not called'
Assert g:final_callback_called, 'The final callback was not called'
AssertEqual ['bar'], g:linter_output

View File

@@ -1,3 +1,9 @@
Before:
let g:linter = {}
After:
unlet g:linter
Execute (PreProcess should throw when the linter object is not a Dictionary):
AssertThrows call ale#linter#PreProcess('')
AssertEqual 'The linter object must be a Dictionary', g:vader_exception
@@ -123,3 +129,85 @@ Execute (PreProcess should accept a 'both' output_stream):
\ 'command': 'echo',
\ 'output_stream': 'both',
\})
Execute(PreProcess should complain if the command_chain is not a List):
let g:linter = {
\ 'name': 'x',
\ 'callback': 'x',
\ 'executable': 'x',
\ 'command_chain': 'x',
\}
AssertThrows call ale#linter#PreProcess(g:linter)
AssertEqual '`command_chain` must be a List', g:vader_exception
Execute(PreProcess should complain if the command_chain is empty):
let g:linter = {
\ 'name': 'x',
\ 'callback': 'x',
\ 'executable': 'x',
\ 'command_chain': [],
\}
AssertThrows call ale#linter#PreProcess(g:linter)
AssertEqual '`command_chain` must contain at least one item', g:vader_exception
Execute(PreProcess should complain if the command_chain has no callback):
let g:linter = {
\ 'name': 'x',
\ 'callback': 'x',
\ 'executable': 'x',
\ 'command_chain': [{}],
\}
AssertThrows call ale#linter#PreProcess(g:linter)
AssertEqual 'The `command_chain` item 0 must define a `callback` function', g:vader_exception
Execute(PreProcess should complain if the command_chain callback is not a function):
let g:linter = {
\ 'name': 'x',
\ 'callback': 'x',
\ 'executable': 'x',
\ 'command_chain': [{'callback': 2}],
\}
AssertThrows call ale#linter#PreProcess(g:linter)
AssertEqual 'The `command_chain` item 0 must define a `callback` function', g:vader_exception
Execute(PreProcess should accept a chain with one callback):
let g:linter = {
\ 'name': 'x',
\ 'callback': 'x',
\ 'executable': 'x',
\ 'command_chain': [{'callback': 'foo'}],
\}
call ale#linter#PreProcess(g:linter)
Execute(PreProcess should complain about invalid output_stream values in the chain):
let g:linter = {
\ 'name': 'x',
\ 'callback': 'x',
\ 'executable': 'x',
\ 'command_chain': [{'callback': 'foo', 'output_stream': ''}],
\}
AssertThrows call ale#linter#PreProcess(g:linter)
AssertEqual "The `command_chain` item 0 `output_stream` flag must be 'stdout', 'stderr', or 'both'", g:vader_exception
Execute(PreProcess should complain about valid output_stream values in the chain):
let g:linter = {
\ 'name': 'x',
\ 'callback': 'x',
\ 'executable': 'x',
\ 'command_chain': [{'callback': 'foo', 'output_stream': 'stdout'}],
\}
call ale#linter#PreProcess(g:linter)
let g:linter.command_chain[0].output_stream = 'stderr'
call ale#linter#PreProcess(g:linter)
let g:linter.command_chain[0].output_stream = 'both'
call ale#linter#PreProcess(g:linter)
Execute(PreProcess should complain about invalid chain items at higher indices):
let g:linter = {
\ 'name': 'x',
\ 'callback': 'x',
\ 'executable': 'x',
\ 'command_chain': [{'callback': 'foo'}, {'callback': 123}],
\}
AssertThrows call ale#linter#PreProcess(g:linter)
AssertEqual 'The `command_chain` item 1 must define a `callback` function', g:vader_exception