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
\ . ' --format json --force-exclusion '
\ . ale#Var(a:buffer, 'ruby_rubocop_options')
\ . ' --stdin ' . bufname(a:buffer)
\ . ' --stdin ' . ale#Escape(expand('#' . a:buffer . ':p'))
endfunction
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
" delete that variable.
"
" The filename will be reset to dummy.txt
"
" This function should be run in a Vader After: block.
function! ale#test#RestoreDirectory() abort
call ale#test#SetFilename('dummy.txt')
silent execute 'cd ' . fnameescape(g:dir)
unlet! g:dir
endfunction

View File

@ -5,15 +5,12 @@ Before:
let g:ale_ruby_brakeman_options = ''
silent! cd /testplugin/test/command_callback
let g:dir = getcwd()
call ale#test#SetDirectory('/testplugin/test/command_callback')
After:
Restore
silent execute 'cd ' . fnameescape(g:dir)
unlet! g:dir
call ale#test#RestoreDirectory()
call ale#linter#Reset()
Execute(The brakeman command callback should detect absence of a valid Rails app):

View File

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

View File

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

View File

@ -1,15 +1,9 @@
Before:
runtime ale_linters/python/mypy.vim
silent! execute 'cd /testplugin/test/command_callback'
let g:dir = getcwd()
call ale#test#SetDirectory('/testplugin/test/command_callback')
After:
silent execute 'cd ' . fnameescape(g:dir)
" Set the file to something else,
" or we'll cause issues when running other tests
silent file 'dummy.py'
unlet! g:dir
call ale#test#RestoreDirectory()
call ale#linter#Reset()
let g:ale_python_mypy_executable = 'mypy'
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_use_global = 0
silent! cd /testplugin/test/command_callback
let g:dir = getcwd()
call ale#test#SetDirectory('/testplugin/test/command_callback')
runtime ale_linters/pug/puglint.vim
After:
Restore
silent execute 'cd ' . fnameescape(g:dir)
unlet! g:dir
call ale#test#RestoreDirectory()
call ale#linter#Reset()
Execute(puglint should detect local executables and package.json):

View File

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

View File

@ -1,19 +1,33 @@
Before:
Save g:ale_ruby_rubocop_executable
let g:ale_ruby_rubocop_executable = 'rubocop'
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):
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(''))
Execute(Should be able to set a custom executable):
let g:ale_ruby_rubocop_executable = 'bin/rubocop'
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(''))
Execute(Setting bundle appends 'exec rubocop'):
let g:ale_ruby_rubocop_executable = 'path to/bundle'
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(''))

View File

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

View File

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

View File

@ -6,7 +6,7 @@ Before:
let g:ale_puppet_puppetlint_executable = 'xxxinvalid'
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 command_callback
let g:dir = getcwd()
@ -14,11 +14,7 @@ Before:
After:
Restore
silent execute 'cd ' . fnameescape(g:dir)
" Set the file to something else,
" or we'll cause issues when running other tests
silent file 'dummy.pp'
unlet! g:dir
call ale#test#RestoreDirectory()
Execute(The puppetlint callback should return the correct default values):
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.
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 command_callback
let g:dir = getcwd()
@ -12,11 +12,7 @@ Before:
After:
Restore
silent execute 'cd ' . fnameescape(g:dir)
" Set the file to something else,
" or we'll cause issues when running other tests
silent file 'dummy.rb'
unlet! g:dir
call ale#test#RestoreDirectory()
Execute(The rubocop callback should return the correct default values):
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.
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 command_callback
let g:dir = getcwd()
@ -12,11 +12,7 @@ Before:
After:
Restore
silent execute 'cd ' . fnameescape(g:dir)
" Set the file to something else,
" or we'll cause issues when running other tests
silent file 'dummy.py'
unlet! g:dir
call ale#test#RestoreDirectory()
Execute(The yapf callback should return the correct default values):
AssertEqual

View File

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

View File

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

View File

@ -1,13 +1,10 @@
Before:
runtime ale_linters/typescript/tslint.vim
silent! cd /testplugin/test/handler
let g:dir = getcwd()
call ale#test#SetDirectory('/testplugin/test/handler')
After:
silent execute 'cd ' . fnameescape(g:dir)
unlet! g:dir
call ale#test#RestoreDirectory()
call ale#linter#Reset()
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_clang_options
silent! cd /testplugin/test
let g:dir = getcwd()
call ale#test#SetDirectory('/testplugin/test')
let g:ale_c_gcc_options = ''
let g:ale_c_clang_options = ''
@ -15,8 +14,7 @@ Before:
After:
Restore
silent execute 'cd ' . fnameescape(g:dir)
unlet! g:dir
call ale#test#RestoreDirectory()
call ale#linter#Reset()
" Run this only once for this series of tests. The cleanup Execute step

View File

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

View File

@ -1,8 +1,7 @@
Before:
let g:ale_javascript_eslint_executable = 'eslint_d'
silent! cd /testplugin/test
let g:dir = getcwd()
call ale#test#SetDirectory('/testplugin/test')
runtime ale_linters/javascript/eslint.vim
@ -11,62 +10,50 @@ After:
let g:ale_javascript_eslint_executable = 'eslint'
let g:ale_javascript_eslint_use_global = 0
silent execute 'cd ' . g:dir
unlet! g:dir
call ale#test#RestoreDirectory()
call ale#linter#Reset()
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
\ g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js',
\ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
Execute(use-global should override create-react-app detection):
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
\ 'eslint_d',
\ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
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
\ g:dir . '/eslint-test-files/node_modules/.bin/eslint',
\ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
Execute(use-global should override other app directories):
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
\ 'eslint_d',
\ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
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
\ g:dir . '/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d',
\ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
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
" 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_executable = 'foodcritic'
silent! cd /testplugin/test
let g:dir = getcwd()
call ale#test#SetDirectory('/testplugin/test')
runtime ale_linters/chef/foodcritic.vim
After:
let g:ale_chef_foodcritic_options = ''
let g:ale_chef_foodcritic_executable = ''
silent execute 'cd ' . g:dir
unlet! g:dir
call ale#test#RestoreDirectory()
call ale#linter#Reset()
Execute(command line should be assembled correctly):
AssertEqual
\ 'foodcritic -t \~F011 %t',
\ 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_use_global = 0
silent! cd /testplugin/test
let g:dir = getcwd()
call ale#test#SetDirectory('/testplugin/test')
runtime ale_linters/php/phpcs.vim
After:
Restore
silent execute 'cd ' . fnameescape(g:dir)
unlet! g:dir
call ale#test#RestoreDirectory()
call ale#linter#Reset()
Execute(project with phpcs should use local by default):