mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-29 07:16:53 +08:00
Fix #1115 - Add support for wrapping all commands with an option
This commit is contained in:
@@ -581,8 +581,8 @@ Execute(Test fixing with chained callbacks):
|
||||
" The buffer shouldn't be piped in for earlier commands in the chain.
|
||||
AssertEqual
|
||||
\ [
|
||||
\ string(ale#job#PrepareCommand('echo echoline')),
|
||||
\ string(ale#job#PrepareCommand('echo echoline')),
|
||||
\ string(ale#job#PrepareCommand(bufnr(''), 'echo echoline')),
|
||||
\ string(ale#job#PrepareCommand(bufnr(''), 'echo echoline')),
|
||||
\ ],
|
||||
\ map(ale#history#Get(bufnr(''))[-2:-1], 'string(v:val.command)')
|
||||
|
||||
@@ -635,7 +635,7 @@ Execute(A temporary file shouldn't be piped into the command when disabled):
|
||||
ALEFix
|
||||
|
||||
AssertEqual
|
||||
\ string(ale#job#PrepareCommand('echo new line')),
|
||||
\ string(ale#job#PrepareCommand(bufnr(''), 'echo new line')),
|
||||
\ string(ale#history#Get(bufnr(''))[-1].command)
|
||||
|
||||
" Remove trailing whitespace for Windows.
|
||||
|
||||
@@ -4,35 +4,36 @@ Before:
|
||||
|
||||
After:
|
||||
Restore
|
||||
let g:ale_has_override = {}
|
||||
|
||||
Execute(sh should be used when the shell is fish):
|
||||
" Set something else, so we will replace that too.
|
||||
let &shellcmdflag = '-f'
|
||||
let g:ale_has_override = {'win32': 0}
|
||||
if !has('win32')
|
||||
" Set something else, so we will replace that too.
|
||||
let &shellcmdflag = '-f'
|
||||
let &shell = 'fish'
|
||||
|
||||
let &shell = 'fish'
|
||||
AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
|
||||
|
||||
AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand('foobar')
|
||||
let &shell = '/usr/bin/fish'
|
||||
|
||||
let &shell = '/usr/bin/fish'
|
||||
AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
|
||||
|
||||
AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand('foobar')
|
||||
let &shell = '/usr/local/bin/fish'
|
||||
|
||||
let &shell = '/usr/local/bin/fish'
|
||||
|
||||
AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand('foobar')
|
||||
AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
|
||||
endif
|
||||
|
||||
Execute(Other shells should be used when set):
|
||||
let &shell = '/bin/bash'
|
||||
let &shellcmdflag = '-c'
|
||||
let g:ale_has_override = {'win32': 0}
|
||||
if !has('win32')
|
||||
let &shell = '/bin/bash'
|
||||
let &shellcmdflag = '-c'
|
||||
|
||||
AssertEqual ['/bin/bash', '-c', 'foobar'], ale#job#PrepareCommand('foobar')
|
||||
AssertEqual ['/bin/bash', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
|
||||
endif
|
||||
|
||||
Execute(cmd /c as a string should be used on Windows):
|
||||
let &shell = 'who cares'
|
||||
let &shellcmdflag = 'whatever'
|
||||
let g:ale_has_override = {'win32': 1}
|
||||
if has('win32')
|
||||
let &shell = 'who cares'
|
||||
let &shellcmdflag = 'whatever'
|
||||
|
||||
AssertEqual 'cmd /c foobar', ale#job#PrepareCommand('foobar')
|
||||
AssertEqual 'cmd /c foobar', ale#job#PrepareCommand(bufnr(''), 'foobar')
|
||||
endif
|
||||
|
||||
48
test/test_wrap_comand.vader
Normal file
48
test/test_wrap_comand.vader
Normal file
@@ -0,0 +1,48 @@
|
||||
Before:
|
||||
Save g:ale_command_wrapper
|
||||
|
||||
let g:ale_command_wrapper = ''
|
||||
|
||||
function! TestCommand(expected_part, input) abort
|
||||
let l:expected = has('win32')
|
||||
\ ? 'cmd /c ' . a:expected_part
|
||||
\ : split(&shell) + split(&shellcmdflag) + [a:expected_part]
|
||||
|
||||
AssertEqual l:expected, ale#job#PrepareCommand(bufnr(''), a:input)
|
||||
endfunction
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
unlet! b:ale_command_wrapper
|
||||
|
||||
delfunction TestCommand
|
||||
|
||||
Execute(The command wrapper should work with a nice command):
|
||||
let b:ale_command_wrapper = 'nice -n 5'
|
||||
|
||||
call TestCommand('nice -n 5 foo bar', 'foo bar')
|
||||
|
||||
Execute(The command wrapper should work with a nice command with an explicit marker):
|
||||
let b:ale_command_wrapper = 'nice -n 5 %*'
|
||||
|
||||
call TestCommand('nice -n 5 foo bar', 'foo bar')
|
||||
|
||||
Execute(Wrappers with spread arguments in the middle should be suppported):
|
||||
let b:ale_command_wrapper = 'wrap %* --'
|
||||
|
||||
call TestCommand('wrap foo bar --', 'foo bar')
|
||||
|
||||
Execute(Wrappers with the command as one argument should be supported):
|
||||
let b:ale_command_wrapper = 'wrap -c %@ -x'
|
||||
|
||||
call TestCommand('wrap -c ' . ale#Escape('foo bar') . ' -x', 'foo bar')
|
||||
|
||||
Execute(&& and ; should be moved to the front):
|
||||
let b:ale_command_wrapper = 'wrap -c %@ -x'
|
||||
|
||||
call TestCommand('foo && bar; wrap -c ' . ale#Escape('baz') . ' -x', 'foo && bar;baz')
|
||||
|
||||
let b:ale_command_wrapper = 'nice -n 5'
|
||||
|
||||
call TestCommand('foo && bar; nice -n 5 baz -z', 'foo && bar;baz -z')
|
||||
Reference in New Issue
Block a user