From e85eb824016a0ca4217d41cc2ec603ff22a3b74d Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 7 Apr 2019 15:34:39 +0100 Subject: [PATCH] #2132 - Implement feature tests with ale#Has --- ale_linters/elixir/elixir_ls.vim | 2 +- ale_linters/haml/hamllint.vim | 2 +- ale_linters/ruby/rails_best_practices.vim | 4 ++-- ale_linters/slim/slimlint.vim | 2 +- autoload/ale.vim | 15 ++++++++---- .../test_elixir_ls_command_callbacks.vader | 23 +++++++++---------- .../fixers/test_prettier_fixer_callback.vader | 2 -- test/test_ale_has.vader | 7 ++++++ test/test_eslint_executable_detection.vader | 1 - test/test_jsonlint_executable_detection.vader | 1 - .../test_swiftlint_executable_detection.vader | 1 - 11 files changed, 34 insertions(+), 26 deletions(-) create mode 100644 test/test_ale_has.vader diff --git a/ale_linters/elixir/elixir_ls.vim b/ale_linters/elixir/elixir_ls.vim index d5db7cd0..d5517de5 100644 --- a/ale_linters/elixir/elixir_ls.vim +++ b/ale_linters/elixir/elixir_ls.vim @@ -6,7 +6,7 @@ call ale#Set('elixir_elixir_ls_config', {}) function! ale_linters#elixir#elixir_ls#GetExecutable(buffer) abort let l:dir = ale#path#Simplify(ale#Var(a:buffer, 'elixir_elixir_ls_release')) - let l:cmd = ale#Has('win32') ? '\language_server.bat' : '/language_server.sh' + let l:cmd = has('win32') ? '\language_server.bat' : '/language_server.sh' return l:dir . l:cmd endfunction diff --git a/ale_linters/haml/hamllint.vim b/ale_linters/haml/hamllint.vim index 7d7278aa..9fcd999f 100644 --- a/ale_linters/haml/hamllint.vim +++ b/ale_linters/haml/hamllint.vim @@ -19,7 +19,7 @@ function! ale_linters#haml#hamllint#GetCommand(buffer) abort " See https://github.com/brigade/haml-lint/blob/master/lib/haml_lint/linter/rubocop.rb#L89 " HamlLint::Linter::RuboCop#rubocop_flags if !empty(l:rubocop_config_file_path) - if ale#Has('win32') + if has('win32') let l:prefix = 'set HAML_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config_file_path) . ' &&' else let l:prefix = 'HAML_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config_file_path) diff --git a/ale_linters/ruby/rails_best_practices.vim b/ale_linters/ruby/rails_best_practices.vim index 680cc364..a94fb671 100644 --- a/ale_linters/ruby/rails_best_practices.vim +++ b/ale_linters/ruby/rails_best_practices.vim @@ -30,8 +30,8 @@ function! ale_linters#ruby#rails_best_practices#GetCommand(buffer) abort endif let l:executable = ale#Var(a:buffer, 'ruby_rails_best_practices_executable') - let l:output_file = ale#Has('win32') ? '%t ' : '/dev/stdout ' - let l:cat_file = ale#Has('win32') ? '; type %t' : '' + let l:output_file = has('win32') ? '%t ' : '/dev/stdout ' + let l:cat_file = has('win32') ? '; type %t' : '' return ale#handlers#ruby#EscapeExecutable(l:executable, 'rails_best_practices') \ . ' --silent -f json --output-file ' . l:output_file diff --git a/ale_linters/slim/slimlint.vim b/ale_linters/slim/slimlint.vim index 1a4008ae..1b365e25 100644 --- a/ale_linters/slim/slimlint.vim +++ b/ale_linters/slim/slimlint.vim @@ -11,7 +11,7 @@ function! ale_linters#slim#slimlint#GetCommand(buffer) abort " " See https://github.com/sds/slim-lint/blob/master/lib/slim_lint/linter/README.md#rubocop if !empty(l:rubocop_config) - if ale#Has('win32') + if has('win32') let l:command = 'set SLIM_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config) . ' && ' . l:command else let l:command = 'SLIM_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config) . ' ' . l:command diff --git a/autoload/ale.vim b/autoload/ale.vim index bcb89095..cd106887 100644 --- a/autoload/ale.vim +++ b/autoload/ale.vim @@ -151,12 +151,19 @@ function! ale#Queue(delay, ...) abort endif endfunction -let g:ale_has_override = get(g:, 'ale_has_override', {}) +let s:current_ale_version = [2, 4, 0] -" Call has(), but check a global Dictionary so we can force flags on or off -" for testing purposes. +" A function used to check for ALE features in files outside of the project. function! ale#Has(feature) abort - return get(g:ale_has_override, a:feature, has(a:feature)) + let l:match = matchlist(a:feature, '\c\v^ale-(\d+)\.(\d+)(\.(\d+))?$') + + if !empty(l:match) + let l:version = [l:match[1] + 0, l:match[2] + 0, l:match[4] + 0] + + return ale#semver#GTE(s:current_ale_version, l:version) + endif + + return 0 endfunction " Given a buffer number and a variable name, look for that variable in the diff --git a/test/command_callback/test_elixir_ls_command_callbacks.vader b/test/command_callback/test_elixir_ls_command_callbacks.vader index ca785054..41a5bc34 100644 --- a/test/command_callback/test_elixir_ls_command_callbacks.vader +++ b/test/command_callback/test_elixir_ls_command_callbacks.vader @@ -1,25 +1,24 @@ Before: call ale#assert#SetUpLinterTest('elixir', 'elixir_ls') - let g:ale_has_override['win32'] = 0 - After: - let g:ale_has_override = {} - call ale#assert#TearDownLinterTest() -Execute(should set correct defaults (unix)): - AssertLinter 'elixir-ls/language_server.sh', 'elixir-ls/language_server.sh' - -Execute(should set correct defaults (win32)): - let g:ale_has_override['win32'] = 1 - - AssertLinter 'elixir-ls\language_server.bat', 'elixir-ls\language_server.bat' +Execute(should set correct defaults): + if has('win32') + AssertLinter 'elixir-ls\language_server.bat', 'elixir-ls\language_server.bat' + else + AssertLinter 'elixir-ls/language_server.sh', 'elixir-ls/language_server.sh' + endif Execute(should configure elixir-ls release location): let b:ale_elixir_elixir_ls_release = 'boo' - AssertLinter 'boo/language_server.sh', 'boo/language_server.sh' + if has('win32') + AssertLinter 'boo\language_server.bat', 'boo\language_server.bat' + else + AssertLinter 'boo/language_server.sh', 'boo/language_server.sh' + endif Execute(should set correct LSP values): call ale#test#SetFilename('elixir_paths/umbrella_project/apps/app1/lib/app.ex') diff --git a/test/fixers/test_prettier_fixer_callback.vader b/test/fixers/test_prettier_fixer_callback.vader index 02bae9c1..9be161ac 100644 --- a/test/fixers/test_prettier_fixer_callback.vader +++ b/test/fixers/test_prettier_fixer_callback.vader @@ -8,8 +8,6 @@ Before: After: call ale#assert#TearDownFixerTest() - let g:ale_has_override = {} - Execute(The prettier callback should return the correct default values): call ale#test#SetFilename('../prettier-test-files/testfile.js') diff --git a/test/test_ale_has.vader b/test/test_ale_has.vader new file mode 100644 index 00000000..eb1da039 --- /dev/null +++ b/test/test_ale_has.vader @@ -0,0 +1,7 @@ +Execute(Checks for versions below the current version should succeed): + AssertEqual 1, ale#Has('ale-2.4.0') + AssertEqual 1, ale#Has('ALE-2.2.1') + AssertEqual 1, ale#Has('ALE-1.0.0') + +Execute(Checks for newer versions should fail): + AssertEqual 0, ale#Has('ALE-20.0.0') diff --git a/test/test_eslint_executable_detection.vader b/test/test_eslint_executable_detection.vader index 0d12e665..5599576e 100644 --- a/test/test_eslint_executable_detection.vader +++ b/test/test_eslint_executable_detection.vader @@ -6,7 +6,6 @@ Before: runtime ale_linters/javascript/eslint.vim After: - let g:ale_has_override = {} let g:ale_javascript_eslint_executable = 'eslint' let g:ale_javascript_eslint_use_global = 0 diff --git a/test/test_jsonlint_executable_detection.vader b/test/test_jsonlint_executable_detection.vader index bd391b47..de52f846 100644 --- a/test/test_jsonlint_executable_detection.vader +++ b/test/test_jsonlint_executable_detection.vader @@ -4,7 +4,6 @@ Before: runtime ale_linters/json/jsonlint.vim After: - let g:ale_has_override = {} let g:ale_json_jsonlint_executable = 'jsonlint' let g:ale_json_jsonlint_use_global = 0 diff --git a/test/test_swiftlint_executable_detection.vader b/test/test_swiftlint_executable_detection.vader index a8e14c84..dfd4930b 100644 --- a/test/test_swiftlint_executable_detection.vader +++ b/test/test_swiftlint_executable_detection.vader @@ -6,7 +6,6 @@ Before: runtime ale_linters/swift/swiftlint.vim After: - let g:ale_has_override = {} let g:ale_swift_swiftlint_executable = 'swiftlint' let g:ale_swift_swiftlint_use_global = 0