diff --git a/ale_linters/ruby/rubocop.vim b/ale_linters/ruby/rubocop.vim index e78ccd1..5c1a60e 100644 --- a/ale_linters/ruby/rubocop.vim +++ b/ale_linters/ruby/rubocop.vim @@ -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 diff --git a/autoload/ale/test.vim b/autoload/ale/test.vim index 22cd51b..204b711 100644 --- a/autoload/ale/test.vim +++ b/autoload/ale/test.vim @@ -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 diff --git a/test/command_callback/test_brakeman_command_callback.vader b/test/command_callback/test_brakeman_command_callback.vader index 607aec6..b97c580 100644 --- a/test/command_callback/test_brakeman_command_callback.vader +++ b/test/command_callback/test_brakeman_command_callback.vader @@ -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): diff --git a/test/command_callback/test_flake8_command_callback.vader b/test/command_callback/test_flake8_command_callback.vader index 7c1f8c7..42afe65 100644 --- a/test/command_callback/test_flake8_command_callback.vader +++ b/test/command_callback/test_flake8_command_callback.vader @@ -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 = '' diff --git a/test/command_callback/test_gometalinter_command_callback.vader b/test/command_callback/test_gometalinter_command_callback.vader index dcaf03b..24c85ab 100644 --- a/test/command_callback/test_gometalinter_command_callback.vader +++ b/test/command_callback/test_gometalinter_command_callback.vader @@ -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): diff --git a/test/command_callback/test_mypy_command_callback.vader b/test/command_callback/test_mypy_command_callback.vader index 1914180..8df7193 100644 --- a/test/command_callback/test_mypy_command_callback.vader +++ b/test/command_callback/test_mypy_command_callback.vader @@ -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 = '' diff --git a/test/command_callback/test_puglint_command_callback.vader b/test/command_callback/test_puglint_command_callback.vader index 830d63b..6d18989 100644 --- a/test/command_callback/test_puglint_command_callback.vader +++ b/test/command_callback/test_puglint_command_callback.vader @@ -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): diff --git a/test/command_callback/test_pylint_command_callback.vader b/test/command_callback/test_pylint_command_callback.vader index 040c9ef..f8f44ab 100644 --- a/test/command_callback/test_pylint_command_callback.vader +++ b/test/command_callback/test_pylint_command_callback.vader @@ -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 = '' diff --git a/test/command_callback/test_rubocop_command_callback.vader b/test/command_callback/test_rubocop_command_callback.vader index db15180..a88d453 100644 --- a/test/command_callback/test_rubocop_command_callback.vader +++ b/test/command_callback/test_rubocop_command_callback.vader @@ -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('')) diff --git a/test/fixers/test_autopep8_fixer_callback.vader b/test/fixers/test_autopep8_fixer_callback.vader index 3b5b057..c8c0bd4 100644 --- a/test/fixers/test_autopep8_fixer_callback.vader +++ b/test/fixers/test_autopep8_fixer_callback.vader @@ -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 diff --git a/test/fixers/test_isort_fixer_callback.vader b/test/fixers/test_isort_fixer_callback.vader index 495f23c..437e276 100644 --- a/test/fixers/test_isort_fixer_callback.vader +++ b/test/fixers/test_isort_fixer_callback.vader @@ -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 diff --git a/test/fixers/test_puppetlint_fixer_callback.vader b/test/fixers/test_puppetlint_fixer_callback.vader index 398f61d..04a85e5 100644 --- a/test/fixers/test_puppetlint_fixer_callback.vader +++ b/test/fixers/test_puppetlint_fixer_callback.vader @@ -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') diff --git a/test/fixers/test_rubocop_fixer_callback.vader b/test/fixers/test_rubocop_fixer_callback.vader index 74160c7..e338353 100644 --- a/test/fixers/test_rubocop_fixer_callback.vader +++ b/test/fixers/test_rubocop_fixer_callback.vader @@ -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') diff --git a/test/fixers/test_yapf_fixer_callback.vader b/test/fixers/test_yapf_fixer_callback.vader index 0b88e4d..2653fd1 100644 --- a/test/fixers/test_yapf_fixer_callback.vader +++ b/test/fixers/test_yapf_fixer_callback.vader @@ -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 diff --git a/test/handler/test_cppcheck_handler.vader b/test/handler/test_cppcheck_handler.vader index 51efad4..f153b9b 100644 --- a/test/handler/test_cppcheck_handler.vader +++ b/test/handler/test_cppcheck_handler.vader @@ -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') diff --git a/test/handler/test_perl_handler.vader b/test/handler/test_perl_handler.vader index 3ada9aa..18c5d70 100644 --- a/test/handler/test_perl_handler.vader +++ b/test/handler/test_perl_handler.vader @@ -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): diff --git a/test/handler/test_tslint_handler.vader b/test/handler/test_tslint_handler.vader index 6da218b..ae87c52 100644 --- a/test/handler/test_tslint_handler.vader +++ b/test/handler/test_tslint_handler.vader @@ -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): diff --git a/test/test_c_import_paths.vader b/test/test_c_import_paths.vader index a9206ed..fbc3d56 100644 --- a/test/test_c_import_paths.vader +++ b/test/test_c_import_paths.vader @@ -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 diff --git a/test/test_csslint_config_detection.vader b/test/test_csslint_config_detection.vader index 7a78374..b4707dc 100644 --- a/test/test_csslint_config_detection.vader +++ b/test/test_csslint_config_detection.vader @@ -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 diff --git a/test/test_eslint_executable_detection.vader b/test/test_eslint_executable_detection.vader index 4f78736..30ae38d 100644 --- a/test/test_eslint_executable_detection.vader +++ b/test/test_eslint_executable_detection.vader @@ -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. diff --git a/test/test_foodcritic_command_callback.vader b/test/test_foodcritic_command_callback.vader index 32beb92..a5b02e4 100644 --- a/test/test_foodcritic_command_callback.vader +++ b/test/test_foodcritic_command_callback.vader @@ -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 - diff --git a/test/test_phpcs_executable_detection.vader b/test/test_phpcs_executable_detection.vader index 72b7af0..786d324 100644 --- a/test/test_phpcs_executable_detection.vader +++ b/test/test_phpcs_executable_detection.vader @@ -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):