mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-02 01:23:30 +08:00
Fix #124 Finish implementing command chaining, and make it work for DMD
This commit is contained in:
61
test/test_command_chain.vader
Normal file
61
test/test_command_chain.vader
Normal 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user