Get more command callback tests to pass on Windows

This commit is contained in:
w0rp 2017-10-05 22:31:00 +01:00
parent 25045641fb
commit 47577564a2
8 changed files with 124 additions and 73 deletions

View File

@ -7,36 +7,51 @@ Before:
call ale#test#SetDirectory('/testplugin/test/command_callback') call ale#test#SetDirectory('/testplugin/test/command_callback')
call ale#test#SetFilename('../ruby_fixtures/valid_rails_app/db/test.rb') call ale#test#SetFilename('../ruby_fixtures/valid_rails_app/db/test.rb')
let b:args = '--silent -f json'
\ . ' --output-file ' . (has('win32') ? '%t' : '/dev/stdout')
let b:app_path = ale#path#Winify(g:dir . '/../ruby_fixtures/valid_rails_app')
let b:suffix = has('win32') ? '; type %t' : ''
After: After:
Restore Restore
unlet! b:args
unlet! b:app_path
unlet! b:suffix
call ale#test#RestoreDirectory() call ale#test#RestoreDirectory()
Execute(Executable should default to rails_best_practices): Execute(Executable should default to rails_best_practices):
AssertEqual AssertEqual
\ '''rails_best_practices'' --silent -f json --output-file /dev/stdout ' \ ale#Escape('rails_best_practices')
\ . ale#Escape(simplify(g:dir . '/../ruby_fixtures/valid_rails_app')), \ . ' ' . b:args
\ . ' ' . ale#Escape(b:app_path)
\ . b:suffix,
\ ale_linters#ruby#rails_best_practices#GetCommand(bufnr('')) \ ale_linters#ruby#rails_best_practices#GetCommand(bufnr(''))
Execute(Should be able to set a custom executable): Execute(Should be able to set a custom executable):
let g:ale_ruby_rails_best_practices_executable = 'bin/rails_best_practices' let g:ale_ruby_rails_best_practices_executable = 'bin/rails_best_practices'
AssertEqual AssertEqual
\ '''bin/rails_best_practices'' --silent -f json --output-file /dev/stdout ' \ ale#Escape('bin/rails_best_practices')
\ . ale#Escape(simplify(g:dir . '/../ruby_fixtures/valid_rails_app')), \ . ' ' . b:args
\ . ' ' . ale#Escape(b:app_path)
\ . b:suffix,
\ ale_linters#ruby#rails_best_practices#GetCommand(bufnr('')) \ ale_linters#ruby#rails_best_practices#GetCommand(bufnr(''))
Execute(Setting bundle appends 'exec rails_best_practices'): Execute(Setting bundle appends 'exec rails_best_practices'):
let g:ale_ruby_rails_best_practices_executable = 'path to/bundle' let g:ale_ruby_rails_best_practices_executable = 'path to/bundle'
AssertEqual AssertEqual
\ '''path to/bundle'' exec rails_best_practices --silent -f json --output-file /dev/stdout ' \ ale#Escape('path to/bundle') . ' exec rails_best_practices'
\ . ale#Escape(simplify(g:dir . '/../ruby_fixtures/valid_rails_app')), \ . ' ' . b:args
\ . ' ' . ale#Escape(b:app_path)
\ . b:suffix,
\ ale_linters#ruby#rails_best_practices#GetCommand(bufnr('')) \ ale_linters#ruby#rails_best_practices#GetCommand(bufnr(''))
Execute(Command callback should be empty when not in a valid Rails app): Execute(Command callback should be empty when not in a valid Rails app):
call ale#test#SetFilename('../ruby_fixtures/not_a_rails_app/test.rb') call ale#test#SetFilename('../ruby_fixtures/not_a_rails_app/test.rb')
AssertEqual AssertEqual
\ '', \ '',
\ ale_linters#ruby#rails_best_practices#GetCommand(bufnr('')) \ ale_linters#ruby#rails_best_practices#GetCommand(bufnr(''))

View File

@ -10,24 +10,30 @@ Before:
After: After:
Restore Restore
call ale#linter#Reset()
call ale#test#RestoreDirectory() call ale#test#RestoreDirectory()
Execute(Executable should default to rubocop): Execute(Executable should default to rubocop):
AssertEqual AssertEqual
\ '''rubocop'' --format json --force-exclusion --stdin ' \ ale#Escape('rubocop')
\ . ale#Escape(g:dir . '/dummy.rb'), \ . ' --format json --force-exclusion --stdin '
\ . ale#Escape(ale#path#Winify(g:dir . '/dummy.rb')),
\ ale_linters#ruby#rubocop#GetCommand(bufnr('')) \ ale_linters#ruby#rubocop#GetCommand(bufnr(''))
Execute(Should be able to set a custom executable): Execute(Should be able to set a custom executable):
let g:ale_ruby_rubocop_executable = 'bin/rubocop' let g:ale_ruby_rubocop_executable = 'bin/rubocop'
AssertEqual AssertEqual
\ '''bin/rubocop'' --format json --force-exclusion --stdin ' \ ale#Escape('bin/rubocop')
\ . ale#Escape(g:dir . '/dummy.rb'), \ . ' --format json --force-exclusion --stdin '
\ . ale#Escape(ale#path#Winify(g:dir . '/dummy.rb')),
\ ale_linters#ruby#rubocop#GetCommand(bufnr('')) \ ale_linters#ruby#rubocop#GetCommand(bufnr(''))
Execute(Setting bundle appends 'exec rubocop'): Execute(Setting bundle appends 'exec rubocop'):
let g:ale_ruby_rubocop_executable = 'path to/bundle' let g:ale_ruby_rubocop_executable = 'path to/bundle'
AssertEqual AssertEqual
\ '''path to/bundle'' exec rubocop --format json --force-exclusion --stdin ' \ ale#Escape('path to/bundle') . ' exec rubocop'
\ . ale#Escape(g:dir . '/dummy.rb'), \ . ' --format json --force-exclusion --stdin '
\ . ale#Escape(ale#path#Winify(g:dir . '/dummy.rb')),
\ ale_linters#ruby#rubocop#GetCommand(bufnr('')) \ ale_linters#ruby#rubocop#GetCommand(bufnr(''))

View File

@ -28,5 +28,5 @@ Execute(The project root should be detected correctly):
call ale#test#SetFilename('rust-rls-project/test.rs') call ale#test#SetFilename('rust-rls-project/test.rs')
AssertEqual AssertEqual
\ g:dir . '/rust-rls-project', \ ale#path#Winify(g:dir . '/rust-rls-project'),
\ ale_linters#rust#rls#GetProjectRoot(bufnr('')) \ ale_linters#rust#rls#GetProjectRoot(bufnr(''))

View File

@ -1,10 +1,16 @@
Before: Before:
Save g:ale_scala_scalastyle_options
Save g:ale_scalastyle_config_loc
unlet! g:ale_scala_scalastyle_options
unlet! g:ale_scalastyle_config_loc
runtime ale_linters/scala/scalastyle.vim runtime ale_linters/scala/scalastyle.vim
After: After:
Restore
call ale#linter#Reset() call ale#linter#Reset()
let g:ale_scala_scalastyle_options = ''
let g:ale_scalastyle_conf_loc = ''
Execute(Should return the correct default command): Execute(Should return the correct default command):
AssertEqual AssertEqual
@ -15,13 +21,16 @@ Execute(Should allow using a custom config file):
let g:ale_scalastyle_config_loc = '/dooper/config.xml' let g:ale_scalastyle_config_loc = '/dooper/config.xml'
AssertEqual AssertEqual
\ 'scalastyle --config ''/dooper/config.xml'' %t', \ 'scalastyle'
\ . ' --config ' . ale#Escape('/dooper/config.xml')
\ . ' %t',
\ ale_linters#scala#scalastyle#GetCommand(bufnr('')) \ ale_linters#scala#scalastyle#GetCommand(bufnr(''))
Execute(Should allow using custom options): Execute(Should allow using custom options):
let g:ale_scala_scalastyle_options = '--warnings false --quiet true' let g:ale_scala_scalastyle_options = '--warnings false --quiet true'
AssertEqual AssertEqual
\ 'scalastyle --config ''/dooper/config.xml'' --warnings false --quiet true %t', \ 'scalastyle'
\ . ' --warnings false --quiet true'
\ . ' %t',
\ ale_linters#scala#scalastyle#GetCommand(bufnr('')) \ ale_linters#scala#scalastyle#GetCommand(bufnr(''))

View File

@ -9,8 +9,7 @@ After:
Restore Restore
unlet! g:default_command unlet! g:default_command
unlet! b:conf
let g:ale_has_override = {}
call ale#linter#Reset() call ale#linter#Reset()
call ale#test#RestoreDirectory() call ale#test#RestoreDirectory()
@ -21,15 +20,20 @@ Execute(The default command should be correct):
Execute(The command should have the .rubocop.yml prepended as an env var if one exists): Execute(The command should have the .rubocop.yml prepended as an env var if one exists):
call ale#test#SetFilename('../slimlint-test-files/subdir/file.slim') call ale#test#SetFilename('../slimlint-test-files/subdir/file.slim')
AssertEqual let b:conf = ale#path#Winify(g:dir . '/../slimlint-test-files/.rubocop.yml')
\ 'SLIM_LINT_RUBOCOP_CONF=''/testplugin/test/slimlint-test-files/.rubocop.yml'' ' . g:default_command,
\ ale_linters#slim#slimlint#GetCommand(bufnr(''))
Execute(The command should have the .rubocop.yml prepended as an env var if one exists on win32): if has('win32')
call ale#test#SetFilename('../slimlint-test-files/subdir/file.slim') " Windows uses 'set var=... && command'
AssertEqual
let g:ale_has_override['win32'] = 1 \ 'set SLIM_LINT_RUBOCOP_CONF='
\ . ale#Escape(b:conf)
AssertEqual \ . ' && ' . g:default_command,
\ 'set SLIM_LINT_RUBOCOP_CONF=''/testplugin/test/slimlint-test-files/.rubocop.yml'' && ' . g:default_command, \ ale_linters#slim#slimlint#GetCommand(bufnr(''))
\ ale_linters#slim#slimlint#GetCommand(bufnr('')) else
" Unix uses 'var=... command'
AssertEqual
\ 'SLIM_LINT_RUBOCOP_CONF='
\ . ale#Escape(b:conf)
\ . ' ' . g:default_command,
\ ale_linters#slim#slimlint#GetCommand(bufnr(''))
endif

View File

@ -19,8 +19,6 @@ After:
unlet! b:executable unlet! b:executable
let g:ale_has_override = {}
call ale#test#SetFilename('test.txt') call ale#test#SetFilename('test.txt')
call ale#test#RestoreDirectory() call ale#test#RestoreDirectory()
@ -29,45 +27,36 @@ After:
Execute(bin/cmd.js paths should be preferred): Execute(bin/cmd.js paths should be preferred):
call ale#test#SetFilename('standard-test-files/with-cmd/testfile.js') call ale#test#SetFilename('standard-test-files/with-cmd/testfile.js')
let b:executable = g:dir let b:executable = ale#path#Winify(
\ . '/standard-test-files/with-cmd/node_modules/standard/bin/cmd.js' \ g:dir
\ . '/standard-test-files/with-cmd/node_modules/standard/bin/cmd.js'
\)
AssertEqual AssertEqual
\ b:executable, \ b:executable,
\ ale_linters#javascript#standard#GetExecutable(bufnr('')) \ ale_linters#javascript#standard#GetExecutable(bufnr(''))
AssertEqual AssertEqual
\ ale#Escape(b:executable) . ' --stdin %s', \ (has('win32') ? 'node.exe ' : '')
\ . ale#Escape(b:executable)
\ . ' --stdin %s',
\ ale_linters#javascript#standard#GetCommand(bufnr('')) \ ale_linters#javascript#standard#GetCommand(bufnr(''))
Execute(.bin directories should be used too): Execute(.bin directories should be used too):
call ale#test#SetFilename('standard-test-files/with-bin/testfile.js') call ale#test#SetFilename('standard-test-files/with-bin/testfile.js')
let b:executable = g:dir let b:executable = ale#path#Winify(
\ . '/standard-test-files/with-bin/node_modules/.bin/standard' \ g:dir
\ . '/standard-test-files/with-bin/node_modules/.bin/standard'
\)
AssertEqual AssertEqual
\ b:executable, \ b:executable,
\ ale_linters#javascript#standard#GetExecutable(bufnr('')) \ ale_linters#javascript#standard#GetExecutable(bufnr(''))
AssertEqual AssertEqual
\ ale#Escape(b:executable) . ' --stdin %s', \ ale#Escape(b:executable)
\ ale_linters#javascript#standard#GetCommand(bufnr('')) \ . ' --stdin %s',
Execute(.js files should be executed with node on Windows):
let g:ale_has_override['win32'] = 1
call ale#test#SetFilename('standard-test-files/with-cmd/testfile.js')
let b:executable = g:dir
\ . '/standard-test-files/with-cmd/node_modules/standard/bin/cmd.js'
AssertEqual
\ b:executable,
\ ale_linters#javascript#standard#GetExecutable(bufnr(''))
AssertEqual
\ ale#Escape('node.exe') . ' ' . ale#Escape(b:executable) . ' --stdin %s',
\ ale_linters#javascript#standard#GetCommand(bufnr('')) \ ale_linters#javascript#standard#GetCommand(bufnr(''))
Execute(The global executable should be used otherwise): Execute(The global executable should be used otherwise):

View File

@ -30,7 +30,12 @@ Execute(The yaml swaglint command callback should allow a global installation to
Execute(The yaml swaglint command callback should allow a local installation to be used): Execute(The yaml swaglint command callback should allow a local installation to be used):
call ale#test#SetFilename('swaglint_paths/docs/swagger.yaml') call ale#test#SetFilename('swaglint_paths/docs/swagger.yaml')
AssertEqual g:dir . '/swaglint_paths/node_modules/.bin/swaglint',
AssertEqual
\ ale#path#Winify(g:dir . '/swaglint_paths/node_modules/.bin/swaglint'),
\ ale_linters#yaml#swaglint#GetExecutable(bufnr('')) \ ale_linters#yaml#swaglint#GetExecutable(bufnr(''))
AssertEqual g:dir . '/swaglint_paths/node_modules/.bin/swaglint -r compact --stdin',
AssertEqual
\ ale#path#Winify(g:dir . '/swaglint_paths/node_modules/.bin/swaglint')
\ . ' -r compact --stdin',
\ ale_linters#yaml#swaglint#GetCommand(bufnr('')) \ ale_linters#yaml#swaglint#GetCommand(bufnr(''))

View File

@ -11,9 +11,17 @@ Before:
function! GetCommand(buffer) abort function! GetCommand(buffer) abort
call ale#engine#InitBufferInfo(a:buffer) call ale#engine#InitBufferInfo(a:buffer)
let l:result = ale_linters#thrift#thrift#GetCommand(a:buffer) let l:command = ale_linters#thrift#thrift#GetCommand(a:buffer)
call ale#engine#Cleanup(a:buffer) call ale#engine#Cleanup(a:buffer)
return l:result
let l:split_command = split(l:command)
let l:index = index(l:split_command, '-out')
if l:index >= 0
let l:split_command[l:index + 1] = 'TEMP'
endif
return join(l:split_command)
endfunction endfunction
runtime ale_linters/thrift/thrift.vim runtime ale_linters/thrift/thrift.vim
@ -34,28 +42,43 @@ Execute(The executable should be configurable):
AssertEqual 'foobar', ale_linters#thrift#thrift#GetExecutable(bufnr('')) AssertEqual 'foobar', ale_linters#thrift#thrift#GetExecutable(bufnr(''))
Execute(The executable should be used in the command): Execute(The executable should be used in the command):
Assert GetCommand(bufnr('%')) =~# "^'thrift'" AssertEqual
\ ale#Escape('thrift') . ' --gen cpp -strict -out TEMP %t',
\ GetCommand(bufnr('%'))
let b:ale_thrift_thrift_executable = 'foobar' let b:ale_thrift_thrift_executable = 'foobar'
Assert GetCommand(bufnr('%')) =~# "^'foobar'" AssertEqual
\ ale#Escape('foobar') . ' --gen cpp -strict -out TEMP %t',
\ GetCommand(bufnr('%'))
Execute(The list of generators should be configurable): Execute(The list of generators should be configurable):
Assert GetCommand(bufnr('%')) =~# '--gen cpp'
let b:ale_thrift_thrift_generators = ['java', 'py:dynamic'] let b:ale_thrift_thrift_generators = ['java', 'py:dynamic']
Assert GetCommand(bufnr('%')) =~# '--gen java --gen py:dynamic'
AssertEqual
\ ale#Escape('thrift') . ' --gen java --gen py:dynamic -strict -out TEMP %t',
\ GetCommand(bufnr('%'))
let b:ale_thrift_thrift_generators = [] let b:ale_thrift_thrift_generators = []
Assert GetCommand(bufnr('%')) =~# '--gen cpp'
AssertEqual
\ ale#Escape('thrift') . ' --gen cpp -strict -out TEMP %t',
\ GetCommand(bufnr('%'))
Execute(The list of include paths should be configurable): Execute(The list of include paths should be configurable):
Assert GetCommand(bufnr('%')) !~# '-I'
let b:ale_thrift_thrift_includes = ['included/path'] let b:ale_thrift_thrift_includes = ['included/path']
Assert GetCommand(bufnr('%')) =~# '-I included/path'
AssertEqual
\ ale#Escape('thrift')
\ . ' --gen cpp'
\ . ' -I included/path'
\ . ' -strict -out TEMP %t',
\ GetCommand(bufnr('%'))
Execute(The string of compiler options should be configurable): Execute(The string of compiler options should be configurable):
Assert GetCommand(bufnr('%')) =~# '-strict'
let b:ale_thrift_thrift_options = '-strict --allow-64bit-consts' let b:ale_thrift_thrift_options = '-strict --allow-64bit-consts'
Assert GetCommand(bufnr('%')) =~# '-strict --allow-64bit-consts'
AssertEqual
\ ale#Escape('thrift')
\ . ' --gen cpp -strict --allow-64bit-consts'
\ . ' -out TEMP %t',
\ GetCommand(bufnr('%'))