#2132 - Implement feature tests with ale#Has

This commit is contained in:
w0rp 2019-04-07 15:34:39 +01:00
parent 3bebcb5d48
commit e85eb82401
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
11 changed files with 34 additions and 26 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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')

View File

@ -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')

7
test/test_ale_has.vader Normal file
View File

@ -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')

View File

@ -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

View File

@ -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

View File

@ -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