diff options
author | w0rp <devw0rp@gmail.com> | 2018-10-29 18:28:28 +0000 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2018-10-29 18:28:28 +0000 |
commit | caac5c93d658c8ad05786194156a321e016d5ba0 (patch) | |
tree | 331f42c17491125fddacbbb33f60a3b3258da0ad /test | |
parent | 2846e862178e9a16e078799c28aa9d9d4a2ea505 (diff) | |
download | ale-caac5c93d658c8ad05786194156a321e016d5ba0.zip |
#2017 Add support for display results from other sources
Diffstat (limited to 'test')
-rw-r--r-- | test/fix/test_ale_fix.vader | 9 | ||||
-rw-r--r-- | test/test_alejobstarted_autocmd.vader | 11 | ||||
-rw-r--r-- | test/test_alelint_autocmd.vader | 11 | ||||
-rw-r--r-- | test/test_checkingbuffer_autocmd.vader | 6 | ||||
-rw-r--r-- | test/test_ignoring_linters.vader | 2 | ||||
-rw-r--r-- | test/test_linter_type_mapping.vader | 12 | ||||
-rw-r--r-- | test/test_loclist_corrections.vader | 45 | ||||
-rw-r--r-- | test/test_other_sources.vader | 153 | ||||
-rw-r--r-- | test/test_redundant_tsserver_rendering_avoided.vader | 2 | ||||
-rw-r--r-- | test/test_setting_problems_found_in_previous_buffers.vader | 4 |
10 files changed, 230 insertions, 25 deletions
diff --git a/test/fix/test_ale_fix.vader b/test/fix/test_ale_fix.vader index 67b8b212..539972a4 100644 --- a/test/fix/test_ale_fix.vader +++ b/test/fix/test_ale_fix.vader @@ -23,7 +23,7 @@ Before: autocmd! autocmd User ALEFixPre let g:pre_success = 1 autocmd User ALEFixPost let g:post_success = 1 - augroup end + augroup END if !has('win32') let &shell = '/bin/bash' @@ -180,7 +180,6 @@ After: unlet! g:ale_emulate_job_failure unlet! b:ale_fixers unlet! b:ale_fix_on_save - augroup! VaderTest delfunction AddCarets delfunction AddDollars delfunction DoNothing @@ -204,6 +203,12 @@ After: delfunction FixWithJSONPostProcessing delfunction JSONPostProcessor + augroup VaderTest + autocmd! + augroup END + + augroup! VaderTest + call ale#test#RestoreDirectory() call ale#fix#registry#ResetToDefaults() diff --git a/test/test_alejobstarted_autocmd.vader b/test/test_alejobstarted_autocmd.vader index 388e5439..6fa1ff8e 100644 --- a/test/test_alejobstarted_autocmd.vader +++ b/test/test_alejobstarted_autocmd.vader @@ -23,10 +23,11 @@ After: let g:ale_run_synchronously = 0 - try - augroup! VaderTest - catch - endtry + augroup VaderTest + autocmd! + augroup END + + augroup! VaderTest unlet! g:job_started_success @@ -38,7 +39,7 @@ Execute(Run a lint cycle with an actual job to check for ALEJobStarted): augroup VaderTest autocmd! autocmd User ALEJobStarted let g:job_started_success = 1 - augroup end + augroup END ALELint diff --git a/test/test_alelint_autocmd.vader b/test/test_alelint_autocmd.vader index 9a7a6a43..332cb36f 100644 --- a/test/test_alelint_autocmd.vader +++ b/test/test_alelint_autocmd.vader @@ -9,10 +9,11 @@ After: let g:ale_run_synchronously = 0 let g:ale_buffer_info = {} - try - augroup! VaderTest - catch - endtry + augroup VaderTest + autocmd! + augroup END + + augroup! VaderTest Given testft(An empty file): Execute(Run a lint cycle, and check that a variable is set in the autocmd): @@ -20,7 +21,7 @@ Execute(Run a lint cycle, and check that a variable is set in the autocmd): autocmd! autocmd User ALELintPre let g:pre_success = 1 autocmd User ALELintPost let g:post_success = 1 - augroup end + augroup END call ale#Queue(0) diff --git a/test/test_checkingbuffer_autocmd.vader b/test/test_checkingbuffer_autocmd.vader index 9e3a8188..9e642b15 100644 --- a/test/test_checkingbuffer_autocmd.vader +++ b/test/test_checkingbuffer_autocmd.vader @@ -31,7 +31,7 @@ After: augroup VaderTest autocmd! - augroup end + augroup END augroup! VaderTest @@ -40,7 +40,7 @@ Execute(ALELintPre should not return success on ale#engine#IsCheckingBuffer): augroup VaderTest autocmd! autocmd User ALELintPre let g:checking_buffer = ale#engine#IsCheckingBuffer(bufnr('')) ? 1 : 0 - augroup end + augroup END ALELint @@ -50,7 +50,7 @@ Execute(ALEJobStarted should return success on ale#engine#IsCheckingBuffer): augroup VaderTest autocmd! autocmd User ALEJobStarted let g:checking_buffer = ale#engine#IsCheckingBuffer(bufnr('')) ? 1 : 0 - augroup end + augroup END ALELint diff --git a/test/test_ignoring_linters.vader b/test/test_ignoring_linters.vader index f47c5e81..866f9e0d 100644 --- a/test/test_ignoring_linters.vader +++ b/test/test_ignoring_linters.vader @@ -108,7 +108,7 @@ Before: let g:run_linters_called = 1 endfunction - function! ale#engine#HandleLoclist(linter_name, buffer, loclist) abort + function! ale#engine#HandleLoclist(linter_name, buffer, loclist, from_other_source) abort let g:loclist = a:loclist endfunction diff --git a/test/test_linter_type_mapping.vader b/test/test_linter_type_mapping.vader index 0131b5f0..0ec22a56 100644 --- a/test/test_linter_type_mapping.vader +++ b/test/test_linter_type_mapping.vader @@ -16,7 +16,7 @@ Execute(It should be possible to remap errors to style errors): \ {'type': 'W', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'}, \ {'type': 'I', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'}, \ ], - \ ale#engine#FixLocList(bufnr(''), 'foo', [ + \ ale#engine#FixLocList(bufnr(''), 'foo', 0, [ \ {'type': 'E', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, \ {'type': 'E', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, \ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, @@ -35,7 +35,7 @@ Execute(It should be possible to remap errors to style errors with buffer-local \ {'type': 'W', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'}, \ {'type': 'I', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'}, \ ], - \ ale#engine#FixLocList(bufnr(''), 'foo', [ + \ ale#engine#FixLocList(bufnr(''), 'foo', 0, [ \ {'type': 'E', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, \ {'type': 'E', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, \ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, @@ -54,7 +54,7 @@ Execute(It should be possible to remap warnings to style warnings): \ {'type': 'W', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'}, \ {'type': 'I', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'}, \ ], - \ ale#engine#FixLocList(bufnr(''), 'foo', [ + \ ale#engine#FixLocList(bufnr(''), 'foo', 0, [ \ {'type': 'E', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, \ {'type': 'E', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, \ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, @@ -73,7 +73,7 @@ Execute(It should be possible to remap style errors to errors): \ {'type': 'W', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'}, \ {'type': 'I', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'}, \ ], - \ ale#engine#FixLocList(bufnr(''), 'foo', [ + \ ale#engine#FixLocList(bufnr(''), 'foo', 0, [ \ {'type': 'E', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, \ {'type': 'E', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, \ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, @@ -92,7 +92,7 @@ Execute(It should be possible to remap style warnings to warnings): \ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'}, \ {'type': 'I', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'}, \ ], - \ ale#engine#FixLocList(bufnr(''), 'foo', [ + \ ale#engine#FixLocList(bufnr(''), 'foo', 0, [ \ {'type': 'E', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, \ {'type': 'E', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, \ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, @@ -111,7 +111,7 @@ Execute(It should be possible to info problems to warnings): \ {'type': 'W', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'}, \ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'}, \ ], - \ ale#engine#FixLocList(bufnr(''), 'foo', [ + \ ale#engine#FixLocList(bufnr(''), 'foo', 0, [ \ {'type': 'E', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, \ {'type': 'E', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, \ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1}, diff --git a/test/test_loclist_corrections.vader b/test/test_loclist_corrections.vader index 48aa1f78..343620a5 100644 --- a/test/test_loclist_corrections.vader +++ b/test/test_loclist_corrections.vader @@ -41,6 +41,7 @@ Execute(FixLocList should set all the default values correctly): \ ale#engine#FixLocList( \ bufnr('%'), \ 'foobar', + \ 0, \ [{'text': 'a', 'lnum': 2}, {'text': 'b', 'lnum': 2}], \ ) @@ -61,6 +62,7 @@ Execute(FixLocList should use the values we supply): \ ale#engine#FixLocList( \ bufnr('%'), \ 'foobar', + \ 0, \ [{ \ 'text': 'a', \ 'lnum': 3, @@ -89,6 +91,7 @@ Execute(FixLocList should set items with lines beyond the end to the last line): \ ale#engine#FixLocList( \ bufnr('%'), \ 'foobar', + \ 0, \ [{'text': 'a', 'lnum': 11}], \ ) @@ -109,6 +112,7 @@ Execute(FixLocList should move line 0 to line 1): \ ale#engine#FixLocList( \ bufnr('%'), \ 'foobar', + \ 0, \ [{'text': 'a', 'lnum': 0}], \ ) @@ -130,6 +134,7 @@ Execute(FixLocList should convert line and column numbers correctly): \ ale#engine#FixLocList( \ bufnr('%'), \ 'foobar', + \ 0, \ [{'text': 'a', 'lnum': '010', 'col': '010'}], \ ) @@ -163,6 +168,7 @@ Execute(FixLocList should pass on end_col values): \ ale#engine#FixLocList( \ bufnr('%'), \ 'foobar', + \ 0, \ [ \ {'text': 'a', 'lnum': '010', 'col': '010', 'end_col': '012'}, \ {'text': 'a', 'lnum': '010', 'col': '011', 'end_col': 12}, @@ -200,6 +206,7 @@ Execute(FixLocList should pass on end_lnum values): \ ale#engine#FixLocList( \ bufnr('%'), \ 'foobar', + \ 0, \ [ \ {'text': 'a', 'lnum': '010', 'col': '010', 'end_col': '012', 'end_lnum': '013'}, \ {'text': 'a', 'lnum': '010', 'col': '011', 'end_col': 12, 'end_lnum': 13}, @@ -224,6 +231,7 @@ Execute(FixLocList should allow subtypes to be set): \ ale#engine#FixLocList( \ bufnr('%'), \ 'foobar', + \ 0, \ [{'text': 'a', 'lnum': 11, 'sub_type': 'style'}], \ ) @@ -285,6 +293,7 @@ Execute(FixLocList should accept filenames): \ ale#engine#FixLocList( \ bufnr('%'), \ 'foobar', + \ 0, \ [ \ {'text': 'a', 'lnum': 2, 'filename': expand('%:p')}, \ {'text': 'a', 'lnum': 3, 'filename': expand('%:p')}, @@ -322,6 +331,7 @@ Execute(FixLocList should interpret temporary filenames as being the current buf \ ale#engine#FixLocList( \ bufnr(''), \ 'foobar', + \ 0, \ [ \ {'text': 'a', 'lnum': 2, 'filename': b:temp_name}, \ {'text': 'a', 'lnum': 3, 'filename': substitute(b:temp_name, '\\', '/', 'g')}, @@ -346,9 +356,43 @@ Execute(The error code should be passed on): \ ale#engine#FixLocList( \ bufnr('%'), \ 'foobar', + \ 0, \ [{'text': 'a', 'lnum': 11, 'code': 'some-code'}], \ ) +Execute(FixLocList should mark problems as coming from other sources if requested): + AssertEqual + \ [ + \ { + \ 'text': 'a', + \ 'lnum': 2, + \ 'col': 0, + \ 'bufnr': bufnr('%'), + \ 'vcol': 0, + \ 'type': 'E', + \ 'nr': -1, + \ 'linter_name': 'foobar', + \ 'from_other_source': 1, + \ }, + \ { + \ 'text': 'b', + \ 'lnum': 2, + \ 'col': 0, + \ 'bufnr': bufnr('%'), + \ 'vcol': 0, + \ 'type': 'E', + \ 'nr': -1, + \ 'linter_name': 'foobar', + \ 'from_other_source': 1, + \ }, + \], + \ ale#engine#FixLocList( + \ bufnr('%'), + \ 'foobar', + \ 1, + \ [{'text': 'a', 'lnum': 2}, {'text': 'b', 'lnum': 2}], + \ ) + Given(A file with Japanese multi-byte text): はじめまして! -私はワープです。 @@ -367,6 +411,7 @@ Execute(character positions should be converted to byte positions): \ ale#engine#FixLocList( \ bufnr('%'), \ 'foobar', + \ 0, \ [ \ {'text': 'a', 'lnum': 1, 'col': 0, 'vcol': 1}, \ {'text': 'a', 'lnum': 1, 'col': 1, 'vcol': 1}, diff --git a/test/test_other_sources.vader b/test/test_other_sources.vader new file mode 100644 index 00000000..e6f9911c --- /dev/null +++ b/test/test_other_sources.vader @@ -0,0 +1,153 @@ +Before: + Save g:ale_buffer_info + Save g:ale_set_signs + Save g:ale_set_quickfix + Save g:ale_set_loclist + Save g:ale_set_highlights + Save g:ale_echo_cursor + + let g:ale_buffer_info = {} + let g:ale_run_synchronously = 1 + let g:ale_set_lists_synchronously = 1 + let g:ale_set_signs = 0 + let g:ale_set_quickfix = 0 + let g:ale_set_loclist = 1 + let g:ale_set_highlights = 0 + let g:ale_echo_cursor = 0 + + function! TestCallback(buffer, output) + return [] + endfunction + + call ale#linter#Define('foobar', { + \ 'name': 'testlinter', + \ 'callback': 'TestCallback', + \ 'executable': has('win32') ? 'cmd' : 'echo', + \ 'command': has('win32') ? 'echo foo bar' : '/bin/sh -c ''echo foo bar''', + \}) + +After: + Restore + + unlet! b:ale_linters + unlet! g:want_results_signaled + unlet! g:want_results_buffer_value + unlet! g:lint_pre_signaled + unlet! g:ale_run_synchronously + unlet! g:ale_set_lists_synchronously + + delfunction TestCallback + + augroup VaderTest + autocmd! + augroup END + + augroup! VaderTest + + call ale#linter#Reset() + call setloclist(0, []) + +Given foobar (Some imaginary filetype): +Execute(StartChecking should mark a buffer as being actively checked): + Assert !ale#engine#IsCheckingBuffer(bufnr('')) + + call ale#other_source#StartChecking(bufnr(''), 'other-source-linter') + + Assert ale#engine#IsCheckingBuffer(bufnr('')) + +Execute(ShowResults sould make a buffer inactive): + call ale#other_source#StartChecking(bufnr(''), 'other-source-linter') + call ale#other_source#StartChecking(bufnr(''), 'second-other-source-linter') + + call ale#other_source#ShowResults(bufnr(''), 'other-source-linter', []) + + Assert ale#engine#IsCheckingBuffer(bufnr('')) + + call ale#other_source#ShowResults(bufnr(''), 'second-other-source-linter', []) + + Assert !ale#engine#IsCheckingBuffer(bufnr('')) + +Execute(ShowResults should show results at any time): + call ale#other_source#ShowResults(bufnr(''), 'other-source-linter', [ + \ {'text': 'xyz', 'lnum': 1}, + \]) + + AssertEqual + \ [ + \ { + \ 'lnum': 1, + \ 'bufnr': bufnr(''), + \ 'col': 0, + \ 'valid': 1, + \ 'vcol': 0, + \ 'nr': -1, + \ 'type': 'E', + \ 'pattern': '', + \ 'text': 'xyz', + \ }, + \ ], + \ ale#test#GetLoclistWithoutModule() + + call ale#other_source#ShowResults(bufnr(''), 'other-source-linter', []) + + AssertEqual [], ale#test#GetLoclistWithoutModule() + +Execute(A regular lint cycle shouldn't clear results from other sources): + call ale#other_source#ShowResults(bufnr(''), 'other-source-linter', [ + \ {'text': 'xyz', 'lnum': 1}, + \]) + ALELint + + AssertEqual + \ [ + \ { + \ 'lnum': 1, + \ 'bufnr': bufnr(''), + \ 'col': 0, + \ 'valid': 1, + \ 'vcol': 0, + \ 'nr': -1, + \ 'type': 'E', + \ 'pattern': '', + \ 'text': 'xyz', + \ }, + \ ], + \ ale#test#GetLoclistWithoutModule() + +Execute(ALEWantResults should be signaled when a buffer is checked): + augroup VaderTest + autocmd! + autocmd User ALEWantResults let g:want_results_signaled = 1 + autocmd User ALELintPre let g:lint_pre_signaled = 1 + augroup END + + " Even when all linters are disabled, we should send the signal. + let b:ale_linters = [] + ALELint + + Assert get(g:, 'want_results_signaled') + Assert !get(g:, 'lint_pre_signaled') + +Execute(ALEWantResults should set a variable indicating which buffer is being checked): + augroup VaderTest + autocmd! + autocmd User ALEWantResults let g:want_results_buffer_value = g:ale_want_results_buffer + augroup END + + let b:ale_linters = [] + ALELint + + AssertEqual bufnr(''), g:want_results_buffer_value + +Execute(ALEWantResults should lead to an ALELintPre signal if another source responds): + augroup VaderTest + autocmd! + autocmd User ALEWantResults call ale#other_source#StartChecking(bufnr(''), 'other-source-linter') + autocmd User ALELintPre let g:lint_pre_signaled = 1 + augroup END + + " Even when all linters are disabled, we should send the signal. + let b:ale_linters = [] + ALELint + + Assert get(g:, 'lint_pre_signaled') diff --git a/test/test_redundant_tsserver_rendering_avoided.vader b/test/test_redundant_tsserver_rendering_avoided.vader index 41cbe5e0..a292b014 100644 --- a/test/test_redundant_tsserver_rendering_avoided.vader +++ b/test/test_redundant_tsserver_rendering_avoided.vader @@ -45,7 +45,7 @@ Before: let g:ale_buffer_info = {bufnr(''): {'loclist': []}} let g:ale_handle_loclist_called = 0 - function! ale#engine#HandleLoclist(linter_name, buffer, loclist) abort + function! ale#engine#HandleLoclist(linter_name, buffer, loclist, from_other_source) abort let g:ale_handle_loclist_called = 1 endfunction diff --git a/test/test_setting_problems_found_in_previous_buffers.vader b/test/test_setting_problems_found_in_previous_buffers.vader index 4604005a..36eeb4ca 100644 --- a/test/test_setting_problems_found_in_previous_buffers.vader +++ b/test/test_setting_problems_found_in_previous_buffers.vader @@ -9,14 +9,14 @@ Before: let g:ale_buffer_info = {} call ale#engine#InitBufferInfo(bufnr('') + 1) let g:ale_buffer_info[bufnr('') + 1].loclist = - \ ale#engine#FixLocList(bufnr('') + 1, 'linter_one', [ + \ ale#engine#FixLocList(bufnr('') + 1, 'linter_one', 0, [ \ {'lnum': 1, 'filename': expand('%:p'), 'text': 'foo'}, \ {'lnum': 2, 'filename': expand('%:p'), 'text': 'bar'}, \ {'lnum': 2, 'text': 'ignore this one'}, \ ]) call ale#engine#InitBufferInfo(bufnr('') + 2) let g:ale_buffer_info[bufnr('') + 2].loclist = - \ ale#engine#FixLocList(bufnr('') + 2, 'linter_one', [ + \ ale#engine#FixLocList(bufnr('') + 2, 'linter_one', 0, [ \ {'lnum': 1, 'filename': expand('%:p'), 'text': 'foo'}, \ {'lnum': 3, 'filename': expand('%:p'), 'text': 'baz'}, \ {'lnum': 5, 'text': 'ignore this one'}, |