Make every test set filenames and switch directories in the same way, and fix some missing escaping for the rubocop linter

This commit is contained in:
w0rp 2017-07-09 22:43:25 +01:00
parent b50a7318fb
commit 6a84605c57
22 changed files with 68 additions and 139 deletions

View File

@ -10,7 +10,7 @@ function! ale_linters#ruby#rubocop#GetCommand(buffer) abort
return ale#Escape(l:executable) . l:exec_args return ale#Escape(l:executable) . l:exec_args
\ . ' --format json --force-exclusion ' \ . ' --format json --force-exclusion '
\ . ale#Var(a:buffer, 'ruby_rubocop_options') \ . ale#Var(a:buffer, 'ruby_rubocop_options')
\ . ' --stdin ' . bufname(a:buffer) \ . ' --stdin ' . ale#Escape(expand('#' . a:buffer . ':p'))
endfunction endfunction
function! ale_linters#ruby#rubocop#Handle(buffer, lines) abort function! ale_linters#ruby#rubocop#Handle(buffer, lines) abort

View File

@ -25,8 +25,11 @@ endfunction
" When g:dir is defined, switch back to the directory we saved, and then " When g:dir is defined, switch back to the directory we saved, and then
" delete that variable. " delete that variable.
" "
" The filename will be reset to dummy.txt
"
" This function should be run in a Vader After: block. " This function should be run in a Vader After: block.
function! ale#test#RestoreDirectory() abort function! ale#test#RestoreDirectory() abort
call ale#test#SetFilename('dummy.txt')
silent execute 'cd ' . fnameescape(g:dir) silent execute 'cd ' . fnameescape(g:dir)
unlet! g:dir unlet! g:dir
endfunction endfunction

View File

@ -5,15 +5,12 @@ Before:
let g:ale_ruby_brakeman_options = '' let g:ale_ruby_brakeman_options = ''
silent! cd /testplugin/test/command_callback call ale#test#SetDirectory('/testplugin/test/command_callback')
let g:dir = getcwd()
After: After:
Restore Restore
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
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):

View File

@ -1,15 +1,9 @@
Before: Before:
runtime ale_linters/python/flake8.vim runtime ale_linters/python/flake8.vim
silent! execute 'cd /testplugin/test/command_callback' call ale#test#SetDirectory('/testplugin/test/command_callback')
let g:dir = getcwd()
After: After:
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
" Set the file to something else,
" or we'll cause issues when running other tests
silent file 'dummy.py'
unlet! g:dir
call ale#linter#Reset() call ale#linter#Reset()
let g:ale_python_flake8_executable = 'flake8' let g:ale_python_flake8_executable = 'flake8'
let g:ale_python_flake8_options = '' let g:ale_python_flake8_options = ''

View File

@ -7,17 +7,13 @@ Before:
runtime ale_linters/go/gometalinter.vim runtime ale_linters/go/gometalinter.vim
silent! cd /testplugin/test/command_callback call ale#test#SetDirectory('/testplugin/test/command_callback')
let g:dir = getcwd()
call ale#test#SetFilename('test.go') call ale#test#SetFilename('test.go')
After: After:
Restore Restore
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
unlet! g:dir
call ale#linter#Reset() call ale#linter#Reset()
Execute(The gometalinter callback should return the right defaults): Execute(The gometalinter callback should return the right defaults):

View File

@ -1,15 +1,9 @@
Before: Before:
runtime ale_linters/python/mypy.vim runtime ale_linters/python/mypy.vim
silent! execute 'cd /testplugin/test/command_callback' call ale#test#SetDirectory('/testplugin/test/command_callback')
let g:dir = getcwd()
After: After:
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
" Set the file to something else,
" or we'll cause issues when running other tests
silent file 'dummy.py'
unlet! g:dir
call ale#linter#Reset() call ale#linter#Reset()
let g:ale_python_mypy_executable = 'mypy' let g:ale_python_mypy_executable = 'mypy'
let g:ale_python_mypy_options = '' let g:ale_python_mypy_options = ''

View File

@ -7,17 +7,14 @@ Before:
let g:ale_pug_puglint_executable = 'pug-lint' let g:ale_pug_puglint_executable = 'pug-lint'
let g:ale_pug_puglint_use_global = 0 let g:ale_pug_puglint_use_global = 0
silent! cd /testplugin/test/command_callback call ale#test#SetDirectory('/testplugin/test/command_callback')
let g:dir = getcwd()
runtime ale_linters/pug/puglint.vim runtime ale_linters/pug/puglint.vim
After: After:
Restore Restore
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
unlet! g:dir
call ale#linter#Reset() call ale#linter#Reset()
Execute(puglint should detect local executables and package.json): Execute(puglint should detect local executables and package.json):

View File

@ -1,16 +1,11 @@
Before: Before:
runtime ale_linters/python/pylint.vim runtime ale_linters/python/pylint.vim
silent! execute 'cd /testplugin/test/command_callback' call ale#test#SetDirectory('/testplugin/test/command_callback')
let g:dir = getcwd()
let b:command_tail = ' --output-format text --msg-template="{path}:{line}:{column}: {msg_id} ({symbol}) {msg}" --reports n %s' let b:command_tail = ' --output-format text --msg-template="{path}:{line}:{column}: {msg_id} ({symbol}) {msg}" --reports n %s'
After: After:
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
" Set the file to something else,
" or we'll cause issues when running other tests
silent file 'dummy.py'
unlet! g:dir
call ale#linter#Reset() call ale#linter#Reset()
let g:ale_python_pylint_executable = 'pylint' let g:ale_python_pylint_executable = 'pylint'
let g:ale_python_pylint_options = '' let g:ale_python_pylint_options = ''

View File

@ -1,19 +1,33 @@
Before: Before:
Save g:ale_ruby_rubocop_executable
let g:ale_ruby_rubocop_executable = 'rubocop'
runtime ale_linters/ruby/rubocop.vim runtime ale_linters/ruby/rubocop.vim
call ale#test#SetDirectory('/testplugin/test/command_callback')
call ale#test#SetFilename('dummy.rb')
After:
Restore
call ale#test#RestoreDirectory()
Execute(Executable should default to rubocop): Execute(Executable should default to rubocop):
AssertEqual AssertEqual
\ '''rubocop'' --format json --force-exclusion --stdin ''dummy.py''', \ '''rubocop'' --format json --force-exclusion --stdin '
\ . ale#Escape(g:dir . '/dummy.rb'),
\ ale_linters#ruby#rubocop#GetCommand(bufnr('')) \ ale_linters#ruby#rubocop#GetCommand(bufnr(''))
Execute(Should be able to set a custom executable): Execute(Should be able to set a custom executable):
let g:ale_ruby_rubocop_executable = 'bin/rubocop' let g:ale_ruby_rubocop_executable = 'bin/rubocop'
AssertEqual AssertEqual
\ '''bin/rubocop'' --format json --force-exclusion --stdin ''dummy.py''', \ '''bin/rubocop'' --format json --force-exclusion --stdin '
\ . ale#Escape(g:dir . '/dummy.rb'),
\ ale_linters#ruby#rubocop#GetCommand(bufnr('')) \ ale_linters#ruby#rubocop#GetCommand(bufnr(''))
Execute(Setting bundle appends 'exec rubocop'): Execute(Setting bundle appends 'exec rubocop'):
let g:ale_ruby_rubocop_executable = 'path to/bundle' let g:ale_ruby_rubocop_executable = 'path to/bundle'
AssertEqual AssertEqual
\ '''path to/bundle'' exec rubocop --format json --force-exclusion --stdin ''dummy.py''', \ '''path to/bundle'' exec rubocop --format json --force-exclusion --stdin '
\ . ale#Escape(g:dir . '/dummy.rb'),
\ ale_linters#ruby#rubocop#GetCommand(bufnr('')) \ ale_linters#ruby#rubocop#GetCommand(bufnr(''))

View File

@ -6,7 +6,7 @@ Before:
let g:ale_python_autopep8_executable = 'xxxinvalid' let g:ale_python_autopep8_executable = 'xxxinvalid'
let g:ale_python_autopep8_options = '' let g:ale_python_autopep8_options = ''
silent! execute 'cd /testplugin/test/command_callback' call ale#test#SetDirectory('/testplugin/test/fixers')
silent cd .. silent cd ..
silent cd command_callback silent cd command_callback
let g:dir = getcwd() let g:dir = getcwd()
@ -14,11 +14,7 @@ Before:
After: After:
Restore Restore
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
" Set the file to something else,
" or we'll cause issues when running other tests
silent file 'dummy.py'
unlet! g:dir
Execute(The autopep8 callback should return the correct default values): Execute(The autopep8 callback should return the correct default values):
AssertEqual AssertEqual

View File

@ -4,7 +4,7 @@ Before:
" Use an invalid global executable, so we don't match it. " Use an invalid global executable, so we don't match it.
let g:ale_python_isort_executable = 'xxxinvalid' let g:ale_python_isort_executable = 'xxxinvalid'
silent! execute 'cd /testplugin/test/command_callback' call ale#test#SetDirectory('/testplugin/test/fixers')
silent cd .. silent cd ..
silent cd command_callback silent cd command_callback
let g:dir = getcwd() let g:dir = getcwd()
@ -12,11 +12,7 @@ Before:
After: After:
Restore Restore
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
" Set the file to something else,
" or we'll cause issues when running other tests
silent file 'dummy.py'
unlet! g:dir
Execute(The isort callback should return the correct default values): Execute(The isort callback should return the correct default values):
AssertEqual AssertEqual

View File

@ -6,7 +6,7 @@ Before:
let g:ale_puppet_puppetlint_executable = 'xxxinvalid' let g:ale_puppet_puppetlint_executable = 'xxxinvalid'
let g:ale_puppet_puppetlint_options = '--invalid' let g:ale_puppet_puppetlint_options = '--invalid'
silent! execute 'cd /testplugin/test/command_callback' call ale#test#SetDirectory('/testplugin/test/fixers')
silent cd .. silent cd ..
silent cd command_callback silent cd command_callback
let g:dir = getcwd() let g:dir = getcwd()
@ -14,11 +14,7 @@ Before:
After: After:
Restore Restore
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
" Set the file to something else,
" or we'll cause issues when running other tests
silent file 'dummy.pp'
unlet! g:dir
Execute(The puppetlint callback should return the correct default values): Execute(The puppetlint callback should return the correct default values):
silent execute 'file ' . fnameescape(g:dir . '/puppet_paths/dummy.pp') silent execute 'file ' . fnameescape(g:dir . '/puppet_paths/dummy.pp')

View File

@ -4,7 +4,7 @@ Before:
" Use an invalid global executable, so we don't match it. " Use an invalid global executable, so we don't match it.
let g:ale_ruby_rubocop_executable = 'xxxinvalid' let g:ale_ruby_rubocop_executable = 'xxxinvalid'
silent! execute 'cd /testplugin/test/command_callback' call ale#test#SetDirectory('/testplugin/test/fixers')
silent cd .. silent cd ..
silent cd command_callback silent cd command_callback
let g:dir = getcwd() let g:dir = getcwd()
@ -12,11 +12,7 @@ Before:
After: After:
Restore Restore
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
" Set the file to something else,
" or we'll cause issues when running other tests
silent file 'dummy.rb'
unlet! g:dir
Execute(The rubocop callback should return the correct default values): Execute(The rubocop callback should return the correct default values):
call ale#test#SetFilename('ruby_paths/dummy.rb') call ale#test#SetFilename('ruby_paths/dummy.rb')

View File

@ -4,7 +4,7 @@ Before:
" Use an invalid global executable, so we don't match it. " Use an invalid global executable, so we don't match it.
let g:ale_python_yapf_executable = 'xxxinvalid' let g:ale_python_yapf_executable = 'xxxinvalid'
silent! execute 'cd /testplugin/test/command_callback' call ale#test#SetDirectory('/testplugin/test/fixers')
silent cd .. silent cd ..
silent cd command_callback silent cd command_callback
let g:dir = getcwd() let g:dir = getcwd()
@ -12,11 +12,7 @@ Before:
After: After:
Restore Restore
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
" Set the file to something else,
" or we'll cause issues when running other tests
silent file 'dummy.py'
unlet! g:dir
Execute(The yapf callback should return the correct default values): Execute(The yapf callback should return the correct default values):
AssertEqual AssertEqual

View File

@ -1,10 +1,8 @@
Before: Before:
silent! cd /testplugin/test/handler call ale#test#SetDirectory('/testplugin/test/handler')
let g:dir = getcwd()
After: After:
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
unlet! g:dir
Execute(Basic errors should be handled by cppcheck): Execute(Basic errors should be handled by cppcheck):
call ale#test#SetFilename('test.cpp') call ale#test#SetFilename('test.cpp')

View File

@ -1,13 +1,10 @@
Before: Before:
silent! cd /testplugin/test/handler call ale#test#SetDirectory('/testplugin/test/handler')
let g:dir = getcwd()
runtime ale_linters/perl/perl.vim runtime ale_linters/perl/perl.vim
After: After:
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
unlet! g:dir
call ale#linter#Reset() call ale#linter#Reset()
Execute(The Perl linter should ignore errors from other files): Execute(The Perl linter should ignore errors from other files):

View File

@ -1,13 +1,10 @@
Before: Before:
runtime ale_linters/typescript/tslint.vim runtime ale_linters/typescript/tslint.vim
silent! cd /testplugin/test/handler call ale#test#SetDirectory('/testplugin/test/handler')
let g:dir = getcwd()
After: After:
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
unlet! g:dir
call ale#linter#Reset() call ale#linter#Reset()
Execute(The tslint handler should parse lines correctly): Execute(The tslint handler should parse lines correctly):

View File

@ -4,8 +4,7 @@ Before:
Save g:ale_cpp_gcc_options Save g:ale_cpp_gcc_options
Save g:ale_cpp_clang_options Save g:ale_cpp_clang_options
silent! cd /testplugin/test call ale#test#SetDirectory('/testplugin/test')
let g:dir = getcwd()
let g:ale_c_gcc_options = '' let g:ale_c_gcc_options = ''
let g:ale_c_clang_options = '' let g:ale_c_clang_options = ''
@ -15,8 +14,7 @@ Before:
After: After:
Restore Restore
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
unlet! g:dir
call ale#linter#Reset() call ale#linter#Reset()
" Run this only once for this series of tests. The cleanup Execute step " Run this only once for this series of tests. The cleanup Execute step

View File

@ -1,17 +1,14 @@
Before: Before:
silent! cd /testplugin/test call ale#test#SetDirectory('/testplugin/test')
let g:dir = getcwd()
runtime ale_linters/css/csslint.vim runtime ale_linters/css/csslint.vim
After: After:
silent execute 'cd ' . g:dir call ale#test#RestoreDirectory()
unlet! g:dir
call ale#linter#Reset() call ale#linter#Reset()
Execute(--config should be set when the .csslintrc file is found): Execute(--config should be set when the .csslintrc file is found):
new csslint-test-files/some-app/subdir/testfile.js call ale#test#SetFilename('csslint-test-files/some-app/subdir/testfile.js')
AssertEqual AssertEqual
\ ( \ (
@ -21,10 +18,8 @@ Execute(--config should be set when the .csslintrc file is found):
\ ), \ ),
\ ale_linters#css#csslint#GetCommand(bufnr('')) \ ale_linters#css#csslint#GetCommand(bufnr(''))
:q
Execute(--config should not be used when no .csslintrc file exists): Execute(--config should not be used when no .csslintrc file exists):
new csslint-test-files/other-app/testfile.css call ale#test#SetFilename('csslint-test-files/other-app/testfile.css')
AssertEqual AssertEqual
\ ( \ (
@ -32,5 +27,3 @@ Execute(--config should not be used when no .csslintrc file exists):
\ . ' %t' \ . ' %t'
\ ), \ ),
\ ale_linters#css#csslint#GetCommand(bufnr('')) \ ale_linters#css#csslint#GetCommand(bufnr(''))
:q

View File

@ -1,8 +1,7 @@
Before: Before:
let g:ale_javascript_eslint_executable = 'eslint_d' let g:ale_javascript_eslint_executable = 'eslint_d'
silent! cd /testplugin/test call ale#test#SetDirectory('/testplugin/test')
let g:dir = getcwd()
runtime ale_linters/javascript/eslint.vim runtime ale_linters/javascript/eslint.vim
@ -11,62 +10,50 @@ After:
let g:ale_javascript_eslint_executable = 'eslint' let g:ale_javascript_eslint_executable = 'eslint'
let g:ale_javascript_eslint_use_global = 0 let g:ale_javascript_eslint_use_global = 0
silent execute 'cd ' . g:dir call ale#test#RestoreDirectory()
unlet! g:dir
call ale#linter#Reset() call ale#linter#Reset()
Execute(create-react-app directories should be detected correctly): Execute(create-react-app directories should be detected correctly):
silent noautocmd new eslint-test-files/react-app/subdir/testfile.js call ale#test#SetFilename('eslint-test-files/react-app/subdir/testfile.js')
AssertEqual AssertEqual
\ g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js', \ g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js',
\ ale#handlers#eslint#GetExecutable(bufnr('')) \ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
Execute(use-global should override create-react-app detection): Execute(use-global should override create-react-app detection):
let g:ale_javascript_eslint_use_global = 1 let g:ale_javascript_eslint_use_global = 1
silent noautocmd new eslint-test-files/react-app/subdir/testfile.js call ale#test#SetFilename('eslint-test-files/react-app/subdir/testfile.js')
AssertEqual AssertEqual
\ 'eslint_d', \ 'eslint_d',
\ ale#handlers#eslint#GetExecutable(bufnr('')) \ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
Execute(other app directories should be detected correctly): Execute(other app directories should be detected correctly):
silent noautocmd new eslint-test-files/other-app/subdir/testfile.js call ale#test#SetFilename('eslint-test-files/other-app/subdir/testfile.js')
AssertEqual AssertEqual
\ g:dir . '/eslint-test-files/node_modules/.bin/eslint', \ g:dir . '/eslint-test-files/node_modules/.bin/eslint',
\ ale#handlers#eslint#GetExecutable(bufnr('')) \ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
Execute(use-global should override other app directories): Execute(use-global should override other app directories):
let g:ale_javascript_eslint_use_global = 1 let g:ale_javascript_eslint_use_global = 1
silent noautocmd new eslint-test-files/other-app/subdir/testfile.js call ale#test#SetFilename('eslint-test-files/other-app/subdir/testfile.js')
AssertEqual AssertEqual
\ 'eslint_d', \ 'eslint_d',
\ ale#handlers#eslint#GetExecutable(bufnr('')) \ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
Execute(eslint_d should be detected correctly): Execute(eslint_d should be detected correctly):
silent noautocmd new eslint-test-files/app-with-eslint-d/testfile.js call ale#test#SetFilename('eslint-test-files/app-with-eslint-d/testfile.js')
AssertEqual AssertEqual
\ g:dir . '/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d', \ g:dir . '/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d',
\ ale#handlers#eslint#GetExecutable(bufnr('')) \ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
Execute(eslint.js executables should be run with node on Windows): Execute(eslint.js executables should be run with node on Windows):
silent noautocmd new eslint-test-files/react-app/subdir/testfile.js call ale#test#SetFilename('eslint-test-files/react-app/subdir/testfile.js')
let g:ale_has_override['win32'] = 1 let g:ale_has_override['win32'] = 1
" We have to execute the file with node. " We have to execute the file with node.

View File

@ -2,25 +2,17 @@ Before:
let g:ale_chef_foodcritic_options = '-t ~F011' let g:ale_chef_foodcritic_options = '-t ~F011'
let g:ale_chef_foodcritic_executable = 'foodcritic' let g:ale_chef_foodcritic_executable = 'foodcritic'
silent! cd /testplugin/test call ale#test#SetDirectory('/testplugin/test')
let g:dir = getcwd()
runtime ale_linters/chef/foodcritic.vim runtime ale_linters/chef/foodcritic.vim
After: After:
let g:ale_chef_foodcritic_options = '' let g:ale_chef_foodcritic_options = ''
let g:ale_chef_foodcritic_executable = '' let g:ale_chef_foodcritic_executable = ''
silent execute 'cd ' . g:dir call ale#test#RestoreDirectory()
unlet! g:dir
call ale#linter#Reset() call ale#linter#Reset()
Execute(command line should be assembled correctly): Execute(command line should be assembled correctly):
AssertEqual AssertEqual
\ 'foodcritic -t \~F011 %t', \ 'foodcritic -t \~F011 %t',
\ ale_linters#chef#foodcritic#GetCommand(bufnr('')) \ ale_linters#chef#foodcritic#GetCommand(bufnr(''))
:q

View File

@ -5,17 +5,14 @@ Before:
let g:ale_php_phpcs_executable = 'phpcs_test' let g:ale_php_phpcs_executable = 'phpcs_test'
let g:ale_php_phpcs_use_global = 0 let g:ale_php_phpcs_use_global = 0
silent! cd /testplugin/test call ale#test#SetDirectory('/testplugin/test')
let g:dir = getcwd()
runtime ale_linters/php/phpcs.vim runtime ale_linters/php/phpcs.vim
After: After:
Restore Restore
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
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):