Skip to content

Commit

Permalink
#2132 - Implement feature tests with ale#Has
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rp committed Apr 7, 2019
1 parent 3bebcb5 commit e85eb82
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion ale_linters/elixir/elixir_ls.vim
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ale_linters/haml/hamllint.vim
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ale_linters/ruby/rails_best_practices.vim
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ale_linters/slim/slimlint.vim
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions autoload/ale.vim
Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions 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')
Expand Down
2 changes: 0 additions & 2 deletions test/fixers/test_prettier_fixer_callback.vader
Expand Up @@ -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')

Expand Down
7 changes: 7 additions & 0 deletions 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')
1 change: 0 additions & 1 deletion test/test_eslint_executable_detection.vader
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion test/test_jsonlint_executable_detection.vader
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion test/test_swiftlint_executable_detection.vader
Expand Up @@ -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

Expand Down

0 comments on commit e85eb82

Please sign in to comment.