Fix some escaping and make some tests set filenames consistently
This commit is contained in:
parent
ab534c2995
commit
dab6f39eb0
7 changed files with 71 additions and 32 deletions
|
@ -40,7 +40,7 @@ function! ale_linters#ruby#brakeman#GetCommand(buffer) abort
|
||||||
|
|
||||||
return 'brakeman -f json -q '
|
return 'brakeman -f json -q '
|
||||||
\ . ale#Var(a:buffer, 'ruby_brakeman_options')
|
\ . ale#Var(a:buffer, 'ruby_brakeman_options')
|
||||||
\ . ' -p ' . l:rails_root
|
\ . ' -p ' . ale#Escape(l:rails_root)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:FindRailsRoot(buffer) abort
|
function! s:FindRailsRoot(buffer) abort
|
||||||
|
|
19
autoload/ale/test.vim
Normal file
19
autoload/ale/test.vim
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
" Author: w0rp <devw0rp@gmail.com>
|
||||||
|
" Description: Functions for making testing ALE easier.
|
||||||
|
"
|
||||||
|
" This file should not typically be loaded during the normal execution of ALE.
|
||||||
|
|
||||||
|
" Change the filename for the current buffer using a relative path to
|
||||||
|
" the script without running autocmd commands.
|
||||||
|
"
|
||||||
|
" If a g:dir variable is set, it will be used as the path to the directory
|
||||||
|
" containing the test file.
|
||||||
|
function! ale#test#SetFilename(path) abort
|
||||||
|
let l:dir = get(g:, 'dir', '')
|
||||||
|
|
||||||
|
if empty(l:dir)
|
||||||
|
let l:dir = getcwd()
|
||||||
|
endif
|
||||||
|
|
||||||
|
silent noautocmd execute 'file ' . fnameescape(simplify(l:dir . '/' . a:path))
|
||||||
|
endfunction
|
|
@ -1,26 +1,42 @@
|
||||||
Before:
|
Before:
|
||||||
|
Save g:ale_ruby_brakeman_options
|
||||||
|
|
||||||
runtime ale_linters/ruby/brakeman.vim
|
runtime ale_linters/ruby/brakeman.vim
|
||||||
|
|
||||||
|
let g:ale_ruby_brakeman_options = ''
|
||||||
|
|
||||||
|
silent! cd /testplugin/test/command_callback
|
||||||
|
let g:dir = getcwd()
|
||||||
|
|
||||||
After:
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
|
silent execute 'cd ' . fnameescape(g:dir)
|
||||||
|
unlet! g:dir
|
||||||
|
|
||||||
call ale#linter#Reset()
|
call ale#linter#Reset()
|
||||||
|
|
||||||
Execute(The brakeman command callback should detect absence of a valid Rails app):
|
Execute(The brakeman command callback should detect absence of a valid Rails app):
|
||||||
cd /testplugin/test/ruby_fixtures/not_a_rails_app/
|
call ale#test#SetFilename('../ruby_fixtures/not_a_rails_app/test.rb')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ '',
|
\ '',
|
||||||
\ ale_linters#ruby#brakeman#GetCommand(bufnr(''))
|
\ ale_linters#ruby#brakeman#GetCommand(bufnr(''))
|
||||||
|
|
||||||
Execute(The brakeman command callback should find a valid Rails app root):
|
Execute(The brakeman command callback should find a valid Rails app root):
|
||||||
cd /testplugin/test/ruby_fixtures/valid_rails_app/db/
|
call ale#test#SetFilename('../ruby_fixtures/valid_rails_app/db/test.rb')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'brakeman -f json -q -p /testplugin/test/ruby_fixtures/valid_rails_app',
|
\ 'brakeman -f json -q -p '
|
||||||
|
\ . ale#Escape(simplify(g:dir . '/../ruby_fixtures/valid_rails_app')),
|
||||||
\ ale_linters#ruby#brakeman#GetCommand(bufnr(''))
|
\ ale_linters#ruby#brakeman#GetCommand(bufnr(''))
|
||||||
|
|
||||||
Execute(The brakeman command callback should include configured options):
|
Execute(The brakeman command callback should include configured options):
|
||||||
cd /testplugin/test/ruby_fixtures/valid_rails_app/db/
|
call ale#test#SetFilename('../ruby_fixtures/valid_rails_app/db/test.rb')
|
||||||
|
|
||||||
let g:ale_ruby_brakeman_options = '--combobulate'
|
let g:ale_ruby_brakeman_options = '--combobulate'
|
||||||
|
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'brakeman -f json -q --combobulate -p /testplugin/test/ruby_fixtures/valid_rails_app',
|
\ 'brakeman -f json -q --combobulate -p '
|
||||||
|
\ . ale#Escape(simplify(g:dir . '/../ruby_fixtures/valid_rails_app')),
|
||||||
\ ale_linters#ruby#brakeman#GetCommand(bufnr(''))
|
\ ale_linters#ruby#brakeman#GetCommand(bufnr(''))
|
||||||
|
|
|
@ -5,36 +5,43 @@ Before:
|
||||||
After:
|
After:
|
||||||
silent execute 'cd ' . fnameescape(b:dir)
|
silent execute 'cd ' . fnameescape(b:dir)
|
||||||
unlet! b:dir
|
unlet! b:dir
|
||||||
|
|
||||||
call ale#linter#Reset()
|
call ale#linter#Reset()
|
||||||
|
|
||||||
Execute(The default C cppcheck command should be correct):
|
Execute(The default C cppcheck command should be correct):
|
||||||
runtime ale_linters/c/cppcheck.vim
|
runtime ale_linters/c/cppcheck.vim
|
||||||
|
|
||||||
|
call ale#test#SetFilename('cppcheck_paths/two/foo.cpp')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'cppcheck -q --language=c --enable=style %t',
|
\ 'cppcheck -q --language=c --enable=style %t',
|
||||||
\ ale_linters#c#cppcheck#GetCommand(bufnr(''))
|
\ ale_linters#c#cppcheck#GetCommand(bufnr(''))
|
||||||
|
|
||||||
Execute(cppcheck for C should detect compile_commands.json files):
|
Execute(cppcheck for C should detect compile_commands.json files):
|
||||||
runtime ale_linters/c/cppcheck.vim
|
runtime ale_linters/c/cppcheck.vim
|
||||||
cd cppcheck_paths/one
|
|
||||||
|
call ale#test#SetFilename('cppcheck_paths/one/foo.cpp')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'cd ' . shellescape(b:dir . '/cppcheck_paths/one') . ' && '
|
\ 'cd ' . ale#Escape(b:dir . '/cppcheck_paths/one') . ' && '
|
||||||
\ . 'cppcheck -q --language=c --project=compile_commands.json --enable=style %t',
|
\ . 'cppcheck -q --language=c --project=compile_commands.json --enable=style %t',
|
||||||
\ ale_linters#c#cppcheck#GetCommand(bufnr(''))
|
\ ale_linters#c#cppcheck#GetCommand(bufnr(''))
|
||||||
|
|
||||||
Execute(The default C++ cppcheck command should be correct):
|
Execute(The default C++ cppcheck command should be correct):
|
||||||
runtime ale_linters/cpp/cppcheck.vim
|
runtime ale_linters/cpp/cppcheck.vim
|
||||||
|
|
||||||
|
call ale#test#SetFilename('cppcheck_paths/two/foo.cpp')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'cppcheck -q --language=c++ --enable=style %t',
|
\ 'cppcheck -q --language=c++ --enable=style %t',
|
||||||
\ ale_linters#cpp#cppcheck#GetCommand(bufnr(''))
|
\ ale_linters#cpp#cppcheck#GetCommand(bufnr(''))
|
||||||
|
|
||||||
Execute(cppcheck for C++ should detect compile_commands.json files):
|
Execute(cppcheck for C++ should detect compile_commands.json files):
|
||||||
runtime ale_linters/cpp/cppcheck.vim
|
runtime ale_linters/cpp/cppcheck.vim
|
||||||
cd cppcheck_paths/one
|
|
||||||
|
call ale#test#SetFilename('cppcheck_paths/one/foo.cpp')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'cd ' . shellescape(b:dir . '/cppcheck_paths/one') . ' && '
|
\ 'cd ' . ale#Escape(b:dir . '/cppcheck_paths/one') . ' && '
|
||||||
\ . 'cppcheck -q --language=c++ --project=compile_commands.json --enable=style %t',
|
\ . 'cppcheck -q --language=c++ --project=compile_commands.json --enable=style %t',
|
||||||
\ ale_linters#cpp#cppcheck#GetCommand(bufnr(''))
|
\ ale_linters#cpp#cppcheck#GetCommand(bufnr(''))
|
||||||
|
|
0
test/phpcs-test-files/project-with-phpcs/foo/test.php
Normal file
0
test/phpcs-test-files/project-with-phpcs/foo/test.php
Normal file
0
test/phpcs-test-files/project-without-phpcs/foo/test.php
Normal file
0
test/phpcs-test-files/project-without-phpcs/foo/test.php
Normal file
|
@ -1,5 +1,9 @@
|
||||||
Before:
|
Before:
|
||||||
|
Save g:ale_php_phpcs_executable
|
||||||
|
Save g:ale_php_phpcs_use_global
|
||||||
|
|
||||||
let g:ale_php_phpcs_executable = 'phpcs_test'
|
let g:ale_php_phpcs_executable = 'phpcs_test'
|
||||||
|
let g:ale_php_phpcs_use_global = 0
|
||||||
|
|
||||||
silent! cd /testplugin/test
|
silent! cd /testplugin/test
|
||||||
let g:dir = getcwd()
|
let g:dir = getcwd()
|
||||||
|
@ -7,39 +11,32 @@ Before:
|
||||||
runtime ale_linters/php/phpcs.vim
|
runtime ale_linters/php/phpcs.vim
|
||||||
|
|
||||||
After:
|
After:
|
||||||
let g:ale_php_phpcs_executable = 'phpcs'
|
Restore
|
||||||
let g:ale_php_phpcs_use_global = 0
|
|
||||||
|
|
||||||
silent execute 'cd ' . g:dir
|
silent execute 'cd ' . fnameescape(g:dir)
|
||||||
unlet! g:dir
|
unlet! g:dir
|
||||||
|
|
||||||
call ale#linter#Reset()
|
call ale#linter#Reset()
|
||||||
|
|
||||||
Execute(project with phpcs should use local by default):
|
Execute(project with phpcs should use local by default):
|
||||||
silent noautocmd new phpcs-test-files/project-with-phpcs/vendor/bin/phpcs
|
call ale#test#SetFilename('phpcs-test-files/project-with-phpcs/foo/test.php')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ g:dir . '/phpcs-test-files/project-with-phpcs/vendor/bin/phpcs',
|
\ g:dir . '/phpcs-test-files/project-with-phpcs/vendor/bin/phpcs',
|
||||||
\ ale_linters#php#phpcs#GetExecutable(bufnr(''))
|
\ ale_linters#php#phpcs#GetExecutable(bufnr(''))
|
||||||
|
|
||||||
:q
|
|
||||||
|
|
||||||
Execute(use-global should override local detection):
|
Execute(use-global should override local detection):
|
||||||
let g:ale_php_phpcs_use_global = 1
|
let g:ale_php_phpcs_use_global = 1
|
||||||
|
|
||||||
silent noautocmd new phpcs-test-files/project-with-phpcs/vendor/bin/phpcs
|
call ale#test#SetFilename('phpcs-test-files/project-with-phpcs/foo/test.php')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'phpcs_test',
|
\ 'phpcs_test',
|
||||||
\ ale_linters#php#phpcs#GetExecutable(bufnr(''))
|
\ ale_linters#php#phpcs#GetExecutable(bufnr(''))
|
||||||
|
|
||||||
:q
|
|
||||||
|
|
||||||
Execute(project without phpcs should use global):
|
Execute(project without phpcs should use global):
|
||||||
silent noautocmd new phpcs-test-files/project-without-phpcs/vendor/bin/phpcs
|
call ale#test#SetFilename('phpcs-test-files/project-without-phpcs/foo/test.php')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'phpcs_test',
|
\ 'phpcs_test',
|
||||||
\ ale_linters#php#phpcs#GetExecutable(bufnr(''))
|
\ ale_linters#php#phpcs#GetExecutable(bufnr(''))
|
||||||
|
|
||||||
:q
|
|
||||||
|
|
Reference in a new issue