summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-02-04 18:30:30 +0000
committerw0rp <devw0rp@gmail.com>2017-02-04 18:30:30 +0000
commit829f87bc6a63cd442c7e2bf55870faa8804668a4 (patch)
tree5886ed67def110fb58b1515f03545e8f1c9e15bd /test
parent97131262abf31de883bcb65835ed6842f66bbd3b (diff)
downloadale-829f87bc6a63cd442c7e2bf55870faa8804668a4.zip
Fix #124 Finish implementing command chaining, and make it work for DMD
Diffstat (limited to 'test')
-rw-r--r--test/test_command_chain.vader61
-rw-r--r--test/test_linter_defintion_processing.vader88
2 files changed, 149 insertions, 0 deletions
diff --git a/test/test_command_chain.vader b/test/test_command_chain.vader
new file mode 100644
index 00000000..f471e159
--- /dev/null
+++ b/test/test_command_chain.vader
@@ -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
diff --git a/test/test_linter_defintion_processing.vader b/test/test_linter_defintion_processing.vader
index 52d40530..4b5c6a76 100644
--- a/test/test_linter_defintion_processing.vader
+++ b/test/test_linter_defintion_processing.vader
@@ -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