mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-21 02:22:13 +08:00
Fix #315 Implement the read_buffer option
This commit is contained in:
139
test/test_engine_invocation.vader
Normal file
139
test/test_engine_invocation.vader
Normal file
@@ -0,0 +1,139 @@
|
||||
Before:
|
||||
function! CollectResults(buffer, output)
|
||||
return []
|
||||
endfunction
|
||||
|
||||
function! FirstChainFunction(buffer)
|
||||
return 'first'
|
||||
endfunction
|
||||
|
||||
function! SecondChainFunction(buffer, output)
|
||||
" We'll skip this command
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! ThirdChainFunction(buffer, output)
|
||||
return 'third'
|
||||
endfunction
|
||||
|
||||
function! FourthChainFunction(buffer, output)
|
||||
return 'fourth'
|
||||
endfunction
|
||||
|
||||
let g:linter = {
|
||||
\ 'name': 'testlinter',
|
||||
\ 'callback': 'CollectResults',
|
||||
\ 'executable': 'echo',
|
||||
\ 'command_chain': [
|
||||
\ {'callback': 'FirstChainFunction'},
|
||||
\ {'callback': 'SecondChainFunction'},
|
||||
\ {'callback': 'ThirdChainFunction'},
|
||||
\ {'callback': 'FourthChainFunction'},
|
||||
\ ],
|
||||
\ 'read_buffer': 1,
|
||||
\}
|
||||
|
||||
function! ProcessIndex(chain_index)
|
||||
return ale#engine#ProcessChain(347, g:linter, a:chain_index, [])
|
||||
endfunction
|
||||
|
||||
After:
|
||||
delfunction CollectResults
|
||||
delfunction FirstChainFunction
|
||||
delfunction SecondChainFunction
|
||||
delfunction ThirdChainFunction
|
||||
delfunction ProcessIndex
|
||||
unlet! g:linter
|
||||
unlet! g:result
|
||||
|
||||
Execute(Engine invocation should return the command for the first item correctly):
|
||||
let g:result = ProcessIndex(0)
|
||||
|
||||
AssertEqual 'first', g:result.command
|
||||
AssertEqual 1, g:result.next_chain_index
|
||||
|
||||
Execute(Engine invocation should return the command for the second item correctly):
|
||||
let g:result = ProcessIndex(1)
|
||||
|
||||
AssertEqual 'third', g:result.command
|
||||
AssertEqual 3, g:result.next_chain_index
|
||||
|
||||
Execute(Engine invocation should return the command for the fourth item correctly):
|
||||
let g:result = ProcessIndex(3)
|
||||
|
||||
AssertEqual 'fourth', g:result.command
|
||||
AssertEqual 4, g:result.next_chain_index
|
||||
|
||||
Execute(Engine invocation should return the command for a single callback correctly):
|
||||
unlet g:linter.command_chain
|
||||
let g:linter.command_callback = 'FirstChainFunction'
|
||||
|
||||
let g:result = ProcessIndex(0)
|
||||
|
||||
AssertEqual 'first', g:result.command
|
||||
|
||||
Execute(Engine invocation should return the command for a command string correctly):
|
||||
unlet g:linter.command_chain
|
||||
let g:linter.command = 'foo bar'
|
||||
|
||||
let g:result = ProcessIndex(0)
|
||||
|
||||
AssertEqual 'foo bar', g:result.command
|
||||
|
||||
Execute(Engine invocation should process read_buffer correctly for simple commands):
|
||||
unlet g:linter.command_chain
|
||||
let g:linter.command = 'foo bar'
|
||||
let g:linter.read_buffer = 0
|
||||
|
||||
let g:result = ProcessIndex(0)
|
||||
|
||||
AssertEqual 'foo bar', g:result.command
|
||||
AssertEqual 0, g:result.read_buffer
|
||||
|
||||
let g:linter.command_callback = 'FirstChainFunction'
|
||||
unlet g:linter.command
|
||||
|
||||
let g:result = ProcessIndex(0)
|
||||
|
||||
AssertEqual 'first', g:result.command
|
||||
AssertEqual 0, g:result.read_buffer
|
||||
|
||||
Execute(Engine invocation should allow read_buffer to be enabled for a command in the middle of a chain):
|
||||
let g:linter.command_chain[2].read_buffer = 1
|
||||
|
||||
let g:result = ProcessIndex(2)
|
||||
|
||||
AssertEqual g:result.command, 'third'
|
||||
AssertEqual g:result.read_buffer, 1
|
||||
|
||||
Execute(Engine invocation should allow read_buffer to be disabled for the end of a chain):
|
||||
let g:linter.command_chain[3].read_buffer = 0
|
||||
|
||||
let g:result = ProcessIndex(3)
|
||||
|
||||
AssertEqual g:result.command, 'fourth'
|
||||
AssertEqual g:result.read_buffer, 0
|
||||
|
||||
Execute(Engine invocation should not use read_buffer from earlier items in a chain):
|
||||
let g:linter.command_chain[1].read_buffer = 1
|
||||
|
||||
let g:result = ProcessIndex(1)
|
||||
|
||||
AssertEqual g:result.command, 'third'
|
||||
AssertEqual g:result.read_buffer, 0
|
||||
|
||||
Execute(Engine invocation should allow the output_stream setting to be changed in the middle of a chain):
|
||||
let g:linter.command_chain[2].output_stream = 'both'
|
||||
|
||||
let g:result = ProcessIndex(2)
|
||||
|
||||
AssertEqual g:result.command, 'third'
|
||||
AssertEqual g:result.output_stream, 'both'
|
||||
|
||||
Execute(Engine invocation should not use output_stream from earlier items in a chain):
|
||||
let g:linter.command_chain[1].output_stream = 'both'
|
||||
|
||||
let g:result = ProcessIndex(1)
|
||||
|
||||
AssertEqual g:result.command, 'third'
|
||||
AssertEqual g:result.output_stream, 'stdout'
|
||||
@@ -234,3 +234,52 @@ Execute(PreProcess should complain when conflicting command options are used):
|
||||
|
||||
AssertThrows call ale#linter#PreProcess(g:linter)
|
||||
AssertEqual 'Only one of `command`, `command_callback`, or `command_chain` should be set', g:vader_exception
|
||||
|
||||
Execute(PreProcess should process the read_buffer option correctly):
|
||||
let g:linter = {
|
||||
\ 'name': 'x',
|
||||
\ 'callback': 'x',
|
||||
\ 'executable': 'x',
|
||||
\ 'command_chain': [{'callback': 'foo'}, {'callback': 'bar'}],
|
||||
\ 'read_buffer': '0',
|
||||
\}
|
||||
|
||||
AssertThrows call ale#linter#PreProcess(g:linter)
|
||||
AssertEqual '`read_buffer` must be `0` or `1`', g:vader_exception
|
||||
|
||||
let g:linter.read_buffer = 0
|
||||
|
||||
call ale#linter#PreProcess(g:linter)
|
||||
|
||||
let g:linter.read_buffer = 1
|
||||
|
||||
call ale#linter#PreProcess(g:linter)
|
||||
|
||||
unlet g:linter.read_buffer
|
||||
let g:linter.command_chain[0].read_buffer = '0'
|
||||
|
||||
AssertThrows call ale#linter#PreProcess(g:linter)
|
||||
AssertEqual 'The `command_chain` item 0 value for `read_buffer` must be `0` or `1`', g:vader_exception
|
||||
|
||||
let g:linter.command_chain[0].read_buffer = 0
|
||||
|
||||
call ale#linter#PreProcess(g:linter)
|
||||
|
||||
let g:linter.command_chain[1].read_buffer = '0'
|
||||
|
||||
AssertThrows call ale#linter#PreProcess(g:linter)
|
||||
AssertEqual 'The `command_chain` item 1 value for `read_buffer` must be `0` or `1`', g:vader_exception
|
||||
|
||||
let g:linter.command_chain[1].read_buffer = 1
|
||||
|
||||
call ale#linter#PreProcess(g:linter)
|
||||
|
||||
Execute(PreProcess should set a default value for read_buffer):
|
||||
let g:linter = {
|
||||
\ 'name': 'x',
|
||||
\ 'callback': 'x',
|
||||
\ 'executable': 'x',
|
||||
\ 'command': 'x',
|
||||
\}
|
||||
|
||||
AssertEqual ale#linter#PreProcess(g:linter).read_buffer, 1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Before:
|
||||
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:testlinter1 = {'name': 'testlinter1', 'executable': 'testlinter1', 'command': 'testlinter1', 'callback': 'testCB1', 'output_stream': 'stdout', 'read_buffer': 1}
|
||||
let g:testlinter2 = {'name': 'testlinter2', 'executable': 'testlinter2', 'command': 'testlinter2', 'callback': 'testCB2', 'output_stream': 'stdout', 'read_buffer': 0}
|
||||
|
||||
call ale#linter#Reset()
|
||||
let g:ale_linters = {}
|
||||
@@ -40,4 +40,4 @@ Then (Linters for dot-seperated filetypes should be properly handled):
|
||||
AssertEqual [g:testlinter1, g:testlinter2], ale#linter#Get('testft1.testft2')
|
||||
|
||||
Execute (Try to load a linter from disk):
|
||||
AssertEqual [{'name': 'testlinter', 'output_stream': 'stdout', 'executable': 'testlinter', 'command': 'testlinter', 'callback': 'testCB'}], ale#linter#Get('testft')
|
||||
AssertEqual [{'name': 'testlinter', 'output_stream': 'stdout', 'executable': 'testlinter', 'command': 'testlinter', 'callback': 'testCB', 'read_buffer': 1}], ale#linter#Get('testft')
|
||||
|
||||
Reference in New Issue
Block a user