2017-02-10 19:34:44 +00:00
|
|
|
Before:
|
2020-08-28 13:02:05 +00:00
|
|
|
Save g:ale_enabled
|
2017-09-08 20:38:51 +00:00
|
|
|
Save g:ale_set_lists_synchronously
|
|
|
|
Save g:ale_buffer_info
|
2018-01-17 18:08:17 +00:00
|
|
|
Save &shell
|
2017-09-08 20:38:51 +00:00
|
|
|
|
2020-08-28 13:02:05 +00:00
|
|
|
let g:ale_enabled = 1
|
2017-09-08 20:38:51 +00:00
|
|
|
let g:ale_buffer_info = {}
|
|
|
|
let g:ale_set_lists_synchronously = 1
|
|
|
|
|
2017-02-10 19:34:44 +00:00
|
|
|
function! TestCallback(buffer, output)
|
2017-09-08 20:38:51 +00:00
|
|
|
" Windows adds extra spaces to the text from echo.
|
2017-02-10 19:34:44 +00:00
|
|
|
return [{
|
|
|
|
\ 'lnum': 2,
|
|
|
|
\ 'col': 3,
|
2017-09-08 20:38:51 +00:00
|
|
|
\ 'text': substitute(a:output[0], ' *$', '', ''),
|
2017-06-07 22:12:45 +00:00
|
|
|
\}]
|
|
|
|
endfunction
|
|
|
|
function! TestCallback2(buffer, output)
|
|
|
|
return [{
|
|
|
|
\ 'lnum': 3,
|
|
|
|
\ 'col': 4,
|
2017-09-08 20:38:51 +00:00
|
|
|
\ 'text': substitute(a:output[0], ' *$', '', ''),
|
2017-02-10 19:34:44 +00:00
|
|
|
\}]
|
|
|
|
endfunction
|
|
|
|
|
2017-05-12 20:16:15 +00:00
|
|
|
" Running the command in another subshell seems to help here.
|
2017-02-10 19:34:44 +00:00
|
|
|
call ale#linter#Define('foobar', {
|
|
|
|
\ 'name': 'testlinter',
|
|
|
|
\ 'callback': 'TestCallback',
|
2017-09-08 20:38:51 +00:00
|
|
|
\ 'executable': has('win32') ? 'cmd' : 'echo',
|
|
|
|
\ 'command': has('win32') ? 'echo foo bar' : '/bin/sh -c ''echo foo bar''',
|
2017-02-10 19:34:44 +00:00
|
|
|
\})
|
|
|
|
|
|
|
|
After:
|
2017-09-08 20:38:51 +00:00
|
|
|
Restore
|
|
|
|
|
2018-07-11 12:46:13 +00:00
|
|
|
unlet! g:i
|
|
|
|
unlet! g:results
|
|
|
|
unlet! g:expected_results
|
|
|
|
|
2017-02-10 19:34:44 +00:00
|
|
|
delfunction TestCallback
|
2017-06-07 22:12:45 +00:00
|
|
|
delfunction TestCallback2
|
2018-06-28 12:53:49 +00:00
|
|
|
call ale#engine#Cleanup(bufnr(''))
|
2017-02-10 19:34:44 +00:00
|
|
|
call ale#linter#Reset()
|
|
|
|
|
|
|
|
Given foobar (Some imaginary filetype):
|
|
|
|
foo
|
|
|
|
bar
|
|
|
|
baz
|
|
|
|
|
|
|
|
Execute(Linters should run with the default options):
|
|
|
|
AssertEqual 'foobar', &filetype
|
|
|
|
|
2018-07-16 12:46:44 +00:00
|
|
|
let g:expected_results = [{
|
2017-02-10 19:34:44 +00:00
|
|
|
\ 'bufnr': bufnr('%'),
|
|
|
|
\ 'lnum': 2,
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'col': 3,
|
|
|
|
\ 'text': 'foo bar',
|
|
|
|
\ 'type': 'E',
|
|
|
|
\ 'nr': -1,
|
|
|
|
\ 'pattern': '',
|
|
|
|
\ 'valid': 1,
|
2018-07-16 12:46:44 +00:00
|
|
|
\ }]
|
|
|
|
|
2021-01-27 19:52:24 +00:00
|
|
|
" Try the test a few times over in NeoVim 0.3 or Windows or Vim 8.2,
|
2018-07-16 12:46:44 +00:00
|
|
|
" where tests fail randomly.
|
2021-01-27 19:52:24 +00:00
|
|
|
for g:i in range(has('nvim-0.3') || has('win32') || has('patch-8.2.2401') ? 5 : 1)
|
2018-10-29 11:29:12 +00:00
|
|
|
call ale#Queue(0, '')
|
2019-02-06 22:00:11 +00:00
|
|
|
call ale#test#WaitForJobs(2000)
|
2018-07-16 12:46:44 +00:00
|
|
|
|
2022-04-01 12:17:15 +00:00
|
|
|
let g:results = ale#test#GetLoclistWithoutNewerKeys()
|
2018-07-16 12:46:44 +00:00
|
|
|
|
|
|
|
if g:results == g:expected_results
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
AssertEqual g:expected_results, g:results
|
2017-06-07 22:12:45 +00:00
|
|
|
|
2018-01-17 18:08:17 +00:00
|
|
|
Execute(Linters should run in PowerShell too):
|
|
|
|
if has('win32')
|
|
|
|
set shell=powershell
|
|
|
|
|
|
|
|
AssertEqual 'foobar', &filetype
|
|
|
|
|
|
|
|
" Replace the callback to handle two lines.
|
|
|
|
function! TestCallback(buffer, output)
|
|
|
|
" Windows adds extra spaces to the text from echo.
|
|
|
|
return [
|
|
|
|
\ {
|
|
|
|
\ 'lnum': 1,
|
|
|
|
\ 'col': 3,
|
|
|
|
\ 'text': substitute(a:output[0], ' *$', '', ''),
|
|
|
|
\ },
|
|
|
|
\ {
|
|
|
|
\ 'lnum': 2,
|
|
|
|
\ 'col': 3,
|
|
|
|
\ 'text': substitute(a:output[1], ' *$', '', ''),
|
|
|
|
\ },
|
|
|
|
\]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Recreate the command string to use &&, which PowerShell does not support.
|
|
|
|
call ale#linter#Reset()
|
|
|
|
call ale#linter#Define('foobar', {
|
|
|
|
\ 'name': 'testlinter',
|
|
|
|
\ 'callback': 'TestCallback',
|
|
|
|
\ 'executable': 'cmd',
|
|
|
|
\ 'command': 'echo foo && echo bar',
|
|
|
|
\})
|
|
|
|
|
2018-10-29 11:29:12 +00:00
|
|
|
call ale#Queue(0, '')
|
2019-02-06 22:00:11 +00:00
|
|
|
call ale#test#WaitForJobs(4000)
|
2018-01-17 18:08:17 +00:00
|
|
|
|
|
|
|
AssertEqual [
|
|
|
|
\ {
|
|
|
|
\ 'bufnr': bufnr('%'),
|
|
|
|
\ 'lnum': 1,
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'col': 3,
|
|
|
|
\ 'text': 'foo',
|
|
|
|
\ 'type': 'E',
|
|
|
|
\ 'nr': -1,
|
|
|
|
\ 'pattern': '',
|
|
|
|
\ 'valid': 1,
|
|
|
|
\ },
|
|
|
|
\ {
|
|
|
|
\ 'bufnr': bufnr('%'),
|
|
|
|
\ 'lnum': 2,
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'col': 3,
|
|
|
|
\ 'text': 'bar',
|
|
|
|
\ 'type': 'E',
|
|
|
|
\ 'nr': -1,
|
|
|
|
\ 'pattern': '',
|
|
|
|
\ 'valid': 1,
|
|
|
|
\ },
|
2022-04-01 12:17:15 +00:00
|
|
|
\], ale#test#GetLoclistWithoutNewerKeys()
|
2018-01-17 18:08:17 +00:00
|
|
|
endif
|