Fix some random test issues for Windows

This commit is contained in:
w0rp 2017-09-11 00:47:27 +01:00
parent cb8a140141
commit b6a487ccf9
13 changed files with 141 additions and 93 deletions

View File

@ -0,0 +1,59 @@
Before:
Save g:ale_perl_perlcritic_profile
Save g:ale_perl_perlcritic_options
Save g:ale_perl_perlcritic_executable
Save g:ale_perl_perlcritic_showrules
unlet! g:ale_perl_perlcritic_options
unlet! g:ale_perl_perlcritic_executable
unlet! g:ale_perl_perlcritic_showrules
let g:ale_perl_perlcritic_profile = ''
runtime ale_linters/perl/perlcritic.vim
call ale#test#SetDirectory('/testplugin/test/command_callback')
call ale#test#SetFilename('test.pl')
After:
Restore
unlet! b:ale_perl_perlcritic_profile
unlet! b:ale_perl_perlcritic_options
unlet! b:ale_perl_perlcritic_executable
unlet! b:ale_perl_perlcritic_showrules
unlet! b:readme_path
call ale#test#RestoreDirectory()
call ale#linter#Reset()
Execute(The command should be correct with g:ale_perl_perlcritic_showrules off):
let b:ale_perl_perlcritic_showrules = 0
AssertEqual
\ ale#Escape('perlcritic') . ' --verbose ''%l:%c %m\n'' --nocolor',
\ ale_linters#perl#perlcritic#GetCommand(bufnr(''))
Execute(The command should be correct with g:ale_perl_perlcritic_showrules on):
let b:ale_perl_perlcritic_showrules = 1
AssertEqual
\ ale#Escape('perlcritic') . ' --verbose ''%l:%c %m [%p]\n'' --nocolor',
\ ale_linters#perl#perlcritic#GetCommand(bufnr(''))
Execute(The command search for the profile file when set):
let b:ale_perl_perlcritic_profile = 'README.md'
let b:readme_path = ale#path#Winify(expand('%:p:h:h:h') . '/README.md')
AssertEqual
\ ale#Escape('perlcritic') . ' --verbose ''%l:%c %m\n'' --nocolor'
\ . ' --profile ' . ale#Escape(b:readme_path),
\ ale_linters#perl#perlcritic#GetCommand(bufnr(''))
Execute(Extra options should be set appropriately):
let b:ale_perl_perlcritic_options = 'beep boop'
AssertEqual
\ ale#Escape('perlcritic') . ' --verbose ''%l:%c %m\n'' --nocolor'
\ . ' beep boop',
\ ale_linters#perl#perlcritic#GetCommand(bufnr(''))

View File

@ -10,7 +10,11 @@ Before:
" Temporarily set the shell to /bin/sh, if it isn't already set that way. " Temporarily set the shell to /bin/sh, if it isn't already set that way.
" This will make it so the test works when running it directly. " This will make it so the test works when running it directly.
let g:current_shell = &shell let g:current_shell = &shell
let &shell = '/bin/sh'
if !has('win32')
let &shell = '/bin/sh'
endif
let g:history = [] let g:history = []
let g:ale_buffer_info = {} let g:ale_buffer_info = {}
let g:ale_max_buffer_history_size = 20 let g:ale_max_buffer_history_size = 20
@ -27,8 +31,10 @@ Before:
call ale#linter#Define('foobar', { call ale#linter#Define('foobar', {
\ 'name': 'testlinter', \ 'name': 'testlinter',
\ 'callback': 'CollectResults', \ 'callback': 'CollectResults',
\ 'executable': 'echo', \ 'executable': has('win32') ? 'cmd' : 'echo',
\ 'command': '/bin/sh -c ''echo command history test''', \ 'command': has('win32')
\ ? 'echo command history test'
\ : '/bin/sh -c ''echo command history test''',
\ 'read_buffer': 0, \ 'read_buffer': 0,
\}) \})
@ -65,7 +71,13 @@ Execute(History should be set when commands are run):
AssertEqual 1, len(g:history) AssertEqual 1, len(g:history)
AssertEqual sort(['status', 'exit_code', 'job_id', 'command']), sort(keys(g:history[0])) AssertEqual sort(['status', 'exit_code', 'job_id', 'command']), sort(keys(g:history[0]))
AssertEqual ['/bin/sh', '-c', '/bin/sh -c ''echo command history test'''], g:history[0].command
if has('win32')
AssertEqual 'cmd /c echo command history test', g:history[0].command
else
AssertEqual ['/bin/sh', '-c', '/bin/sh -c ''echo command history test'''], g:history[0].command
endif
AssertEqual 'finished', g:history[0].status AssertEqual 'finished', g:history[0].status
AssertEqual 0, g:history[0].exit_code AssertEqual 0, g:history[0].exit_code
" The Job ID will change each time, but we can check the type. " The Job ID will change each time, but we can check the type.
@ -125,6 +137,8 @@ Given foobar(Some file with an imaginary filetype):
c c
Execute(The history should be updated when fixers are run): Execute(The history should be updated when fixers are run):
call ale#test#SetFilename('dummy.txt')
let b:ale_fixers = {'foobar': ['TestFixer']} let b:ale_fixers = {'foobar': ['TestFixer']}
let b:ale_enabled = 0 let b:ale_enabled = 0
let g:ale_run_synchronously = 1 let g:ale_run_synchronously = 1
@ -132,4 +146,9 @@ Execute(The history should be updated when fixers are run):
ALEFix ALEFix
AssertEqual ['finished'], map(copy(b:ale_history), 'v:val.status') AssertEqual ['finished'], map(copy(b:ale_history), 'v:val.status')
AssertEqual '/bin/sh -c echo foo ', split(join(b:ale_history[0].command), '<')[0]
if has('win32')
AssertEqual 'cmd /c echo foo ', split(b:ale_history[0].command, '<')[0]
else
AssertEqual '/bin/sh -c echo foo ', split(join(b:ale_history[0].command), '<')[0]
endif

View File

@ -1,10 +1,12 @@
Before: Before:
Save g:ale_run_synchronously Save g:ale_run_synchronously
Save g:ale_set_lists_synchronously
Save g:ale_buffer_info Save g:ale_buffer_info
Save g:ale_linters Save g:ale_linters
let g:ale_buffer_info = {} let g:ale_buffer_info = {}
let g:ale_run_synchronously = 1 let g:ale_run_synchronously = 1
let g:ale_set_lists_synchronously = 1
call ale#ResetLintFileMarkers() call ale#ResetLintFileMarkers()
let g:buffer_result = [ let g:buffer_result = [
@ -61,7 +63,7 @@ Before:
call ale#linter#Define('foobar', { call ale#linter#Define('foobar', {
\ 'name': 'lint_file_linter', \ 'name': 'lint_file_linter',
\ 'callback': 'LintFileCallback', \ 'callback': 'LintFileCallback',
\ 'executable': 'echo', \ 'executable': has('win32') ? 'cmd' : 'echo',
\ 'command': 'echo', \ 'command': 'echo',
\ 'lint_file': 1, \ 'lint_file': 1,
\}) \})
@ -69,7 +71,7 @@ Before:
call ale#linter#Define('foobar', { call ale#linter#Define('foobar', {
\ 'name': 'buffer_linter', \ 'name': 'buffer_linter',
\ 'callback': 'BufferCallback', \ 'callback': 'BufferCallback',
\ 'executable': 'echo', \ 'executable': has('win32') ? 'cmd' : 'echo',
\ 'command': 'echo', \ 'command': 'echo',
\ 'read_buffer': 0, \ 'read_buffer': 0,
\}) \})

View File

@ -47,7 +47,7 @@ Before:
call ale#linter#Define('foobar', { call ale#linter#Define('foobar', {
\ 'name': 'testlinter', \ 'name': 'testlinter',
\ 'callback': 'TestCallback', \ 'callback': 'TestCallback',
\ 'executable': 'true', \ 'executable': has('win32') ? 'cmd': 'true',
\ 'command': 'true', \ 'command': 'true',
\ 'read_buffer': 0, \ 'read_buffer': 0,
\}) \})

View File

@ -2,12 +2,14 @@ Before:
Save g:ale_set_loclist Save g:ale_set_loclist
Save g:ale_set_quickfix Save g:ale_set_quickfix
Save g:ale_buffer_info Save g:ale_buffer_info
Save g:ale_set_lists_synchronously
let g:ale_buffer_info = {} let g:ale_buffer_info = {}
let g:ale_set_loclist = 0 let g:ale_set_loclist = 0
let g:ale_set_quickfix = 0 let g:ale_set_quickfix = 0
let g:ale_set_lists_synchronously = 1
silent! cd /testplugin/test call ale#test#SetDirectory('/testplugin/test')
After: After:
Restore Restore
@ -15,6 +17,8 @@ After:
call setloclist(0, []) call setloclist(0, [])
call setqflist([]) call setqflist([])
call ale#test#RestoreDirectory()
Execute(The loclist titles should be set appropriately): Execute(The loclist titles should be set appropriately):
silent noautocmd file foo silent noautocmd file foo
@ -37,7 +41,9 @@ Execute(The loclist titles should be set appropriately):
\}], getloclist(0) \}], getloclist(0)
if !has('nvim') if !has('nvim')
AssertEqual {'title': getcwd() . '/foo'}, getloclist(0, {'title': ''}) AssertEqual
\ {'title': ale#path#Winify(getcwd() . '/foo')},
\ getloclist(0, {'title': ''})
endif endif
Execute(The quickfix titles should be set appropriately): Execute(The quickfix titles should be set appropriately):
@ -65,5 +71,7 @@ Execute(The quickfix titles should be set appropriately):
\}], getqflist() \}], getqflist()
if !has('nvim') if !has('nvim')
AssertEqual {'title': getcwd() . '/foo'}, getqflist({'title': ''}) AssertEqual
\ {'title': ale#path#Winify(getcwd() . '/foo')},
\ getqflist({'title': ''})
endif endif

View File

@ -7,7 +7,9 @@ After:
Execute(We should be able to find a configuration file further up): Execute(We should be able to find a configuration file further up):
call ale#test#SetFilename('top/middle/bottom/dummy.txt') call ale#test#SetFilename('top/middle/bottom/dummy.txt')
AssertEqual expand('%:p:h:h:h:h') . '/top/example.ini', ale#path#FindNearestFile(bufnr('%'), 'example.ini') AssertEqual
\ ale#path#Winify(expand('%:p:h:h:h:h') . '/top/example.ini'),
\ ale#path#FindNearestFile(bufnr('%'), 'example.ini')
Execute(We shouldn't find anything for files which don't match): Execute(We shouldn't find anything for files which don't match):
AssertEqual '', ale#path#FindNearestFile(bufnr('%'), 'cantfindthis') AssertEqual '', ale#path#FindNearestFile(bufnr('%'), 'cantfindthis')

View File

@ -1,34 +1,47 @@
Before:
function! CheckPath(path) abort
return ale#path#IsBufferPath(bufnr(''), ale#path#Winify(a:path))
endfunction
After:
delfunction CheckPath
Execute(ale#path#IsBufferPath should match simple relative paths): Execute(ale#path#IsBufferPath should match simple relative paths):
call ale#test#SetFilename('app/foo.txt') call ale#test#SetFilename('app/foo.txt')
Assert ale#path#IsBufferPath(bufnr(''), 'app/foo.txt'), 'No match for foo.txt' Assert CheckPath('app/foo.txt'), 'No match for foo.txt'
Assert !ale#path#IsBufferPath(bufnr(''), 'app/bar.txt'), 'Bad match for bar.txt' Assert !CheckPath('app/bar.txt'), 'Bad match for bar.txt'
Execute(ale#path#IsBufferPath should match relative paths with dots): Execute(ale#path#IsBufferPath should match relative paths with dots):
call ale#test#SetFilename('app/foo.txt') call ale#test#SetFilename('app/foo.txt')
Assert ale#path#IsBufferPath(bufnr(''), '../../app/foo.txt'), 'No match for ../../app/foo.txt' " Skip these checks on Windows.
if !has('win32')
Assert CheckPath('../../app/foo.txt'), 'No match for ../../app/foo.txt'
endif
Execute(ale#path#IsBufferPath should match absolute paths): Execute(ale#path#IsBufferPath should match absolute paths):
silent file! foo.txt silent file! foo.txt
Assert ale#path#IsBufferPath(bufnr(''), getcwd() . '/foo.txt'), 'No match for foo.txt' Assert CheckPath(getcwd() . '/foo.txt'), 'No match for foo.txt'
Assert !ale#path#IsBufferPath(bufnr(''), getcwd() . '/bar.txt'), 'Bad match for bar.txt' Assert !CheckPath(getcwd() . '/bar.txt'), 'Bad match for bar.txt'
Execute(ale#path#IsBufferPath should match paths beginning with ./): Execute(ale#path#IsBufferPath should match paths beginning with ./):
silent file! foo.txt silent file! foo.txt
Assert ale#path#IsBufferPath(bufnr(''), './foo.txt'), 'No match for ./foo.txt' if !has('win32')
Assert ale#path#IsBufferPath(bufnr(''), './foo.txt'), 'No match for ./foo.txt'
endif
Execute(ale#path#IsBufferPath should match if our path ends with the test path): Execute(ale#path#IsBufferPath should match if our path ends with the test path):
silent file! foo/bar/baz.txt silent file! foo/bar/baz.txt
Assert ale#path#IsBufferPath(bufnr(''), 'bar/baz.txt'), 'No match for bar/baz.txt' Assert CheckPath('bar/baz.txt'), 'No match for bar/baz.txt'
Execute(ale#path#IsBufferPath should match paths with redundant slashes): Execute(ale#path#IsBufferPath should match paths with redundant slashes):
silent file! foo.txt silent file! foo.txt
Assert ale#path#IsBufferPath(bufnr(''), getcwd() . '////foo.txt'), 'No match for foo.txt' Assert CheckPath(getcwd() . '////foo.txt'), 'No match for foo.txt'
Execute(ale#path#IsBufferPath should accept various names for stdin): Execute(ale#path#IsBufferPath should accept various names for stdin):
Assert ale#path#IsBufferPath(bufnr(''), '-') Assert ale#path#IsBufferPath(bufnr(''), '-')
@ -39,6 +52,9 @@ Execute(ale#path#IsBufferPath should accept various names for stdin):
Execute(ale#path#IsBufferPath should match files in /tmp): Execute(ale#path#IsBufferPath should match files in /tmp):
call ale#test#SetFilename('app/test.ts') call ale#test#SetFilename('app/test.ts')
Assert ale#path#IsBufferPath(bufnr(''), '../../../../../../../../tmp/vG0hKyD/1/test.ts') " Skip these checks on Windows.
Assert ale#path#IsBufferPath(bufnr(''), '/tmp/vG0hKyD/1/test.ts') if !has('win32')
Assert ale#path#IsBufferPath(bufnr(''), '/run/user/1000/vG0hKyD/1/test.ts') Assert ale#path#IsBufferPath(bufnr(''), '../../../../../../../../tmp/vG0hKyD/1/test.ts')
Assert ale#path#IsBufferPath(bufnr(''), '/tmp/vG0hKyD/1/test.ts')
Assert ale#path#IsBufferPath(bufnr(''), '/run/user/1000/vG0hKyD/1/test.ts')
endif

View File

@ -2,6 +2,8 @@ After:
let g:ale_has_override = {} let g:ale_has_override = {}
Execute(ale#path#Upwards should return the correct path components for Unix): Execute(ale#path#Upwards should return the correct path components for Unix):
let g:ale_has_override = {'win32': 0}
" Absolute paths should include / on the end. " Absolute paths should include / on the end.
AssertEqual AssertEqual
\ ['/foo/bar/baz', '/foo/bar', '/foo', '/'], \ ['/foo/bar/baz', '/foo/bar', '/foo', '/'],

View File

@ -1,62 +0,0 @@
" NOTE: We use the 'b:' forms below to ensure that we're properly using
" ale#Var()
Given perl:
#!/usr/bin/env perl
use v5.10;
say 'Hi there!';
Before:
Save g:ale_perl_perlcritic_profile
Save g:ale_perl_perlcritic_options
Save g:ale_perl_perlcritic_executable
Save g:ale_perl_perlcritic_showrules
silent! unlet g:ale_perl_perlcritic_options
silent! unlet g:ale_perl_perlcritic_executable
silent! unlet g:ale_perl_perlcritic_showrules
let g:ale_perl_perlcritic_profile = ''
" enable loading inside test container
silent! cd /testplugin
source ale_linters/perl/perlcritic.vim
After:
Restore
silent! unlet b:ale_perl_perlcritic_profile
silent! unlet b:ale_perl_perlcritic_options
silent! unlet b:ale_perl_perlcritic_executable
silent! unlet b:ale_perl_perlcritic_showrules
Execute(no g:ale_perl_perlcritic_showrules):
let b:ale_perl_perlcritic_showrules = 0
AssertEqual
\ "'perlcritic' --verbose '". '%l:%c %m\n' . "' --nocolor",
\ ale_linters#perl#perlcritic#GetCommand(bufnr(''))
Execute(yes g:ale_perl_perlcritic_showrules):
let b:ale_perl_perlcritic_showrules = 1
AssertEqual
\ "'perlcritic' --verbose '". '%l:%c %m [%p]\n' . "' --nocolor",
\ ale_linters#perl#perlcritic#GetCommand(bufnr(''))
Execute(set g:ale_perl_perlcritic_profile):
let b:ale_perl_perlcritic_profile = 'README.md'
Assert
\ ale_linters#perl#perlcritic#GetCommand(bufnr(''))
\ =~# "--profile '.*/README.md'"
Execute(g:ale_perl_perlcritic_options):
let b:ale_perl_perlcritic_options = 'beep boop'
AssertEqual
\ "'perlcritic' --verbose '". '%l:%c %m\n' . "' --nocolor beep boop",
\ ale_linters#perl#perlcritic#GetCommand(bufnr(''))

View File

@ -19,7 +19,7 @@ Execute(project with phpcs should use local by default):
call ale#test#SetFilename('phpcs-test-files/project-with-phpcs/foo/test.php') call ale#test#SetFilename('phpcs-test-files/project-with-phpcs/foo/test.php')
AssertEqual AssertEqual
\ g:dir . '/phpcs-test-files/project-with-phpcs/vendor/bin/phpcs', \ ale#path#Winify(g:dir . '/phpcs-test-files/project-with-phpcs/vendor/bin/phpcs'),
\ ale_linters#php#phpcs#GetExecutable(bufnr('')) \ ale_linters#php#phpcs#GetExecutable(bufnr(''))
Execute(use-global should override local detection): Execute(use-global should override local detection):

View File

@ -9,6 +9,7 @@ After:
Execute(sh should be used when the shell is fish): Execute(sh should be used when the shell is fish):
" Set something else, so we will replace that too. " Set something else, so we will replace that too.
let &shellcmdflag = '-f' let &shellcmdflag = '-f'
let g:ale_has_override = {'win32': 0}
let &shell = 'fish' let &shell = 'fish'
@ -25,13 +26,13 @@ Execute(sh should be used when the shell is fish):
Execute(Other shells should be used when set): Execute(Other shells should be used when set):
let &shell = '/bin/bash' let &shell = '/bin/bash'
let &shellcmdflag = '-c' let &shellcmdflag = '-c'
let g:ale_has_override = {'win32': 0}
AssertEqual ['/bin/bash', '-c', 'foobar'], ale#job#PrepareCommand('foobar') AssertEqual ['/bin/bash', '-c', 'foobar'], ale#job#PrepareCommand('foobar')
Execute(cmd /c as a string should be used on Windows): Execute(cmd /c as a string should be used on Windows):
let &shell = 'who cares' let &shell = 'who cares'
let &shellcmdflag = 'whatever' let &shellcmdflag = 'whatever'
let g:ale_has_override = {'win32': 1} let g:ale_has_override = {'win32': 1}
AssertEqual 'cmd /c foobar', ale#job#PrepareCommand('foobar') AssertEqual 'cmd /c foobar', ale#job#PrepareCommand('foobar')

View File

@ -8,10 +8,10 @@ Execute(We should be able to find the local version of a file):
call ale#test#SetFilename('top/middle/bottom/dummy.txt') call ale#test#SetFilename('top/middle/bottom/dummy.txt')
AssertEqual AssertEqual
\ expand('%:p:h:h:h:h') . '/top/example.ini', \ ale#path#Winify(expand('%:p:h:h:h:h') . '/top/example.ini'),
\ ale#path#ResolveLocalPath(bufnr('%'), 'example.ini', '/global/config.ini') \ ale#path#ResolveLocalPath(bufnr('%'), 'example.ini', '/global/config.ini')
Execute(We shouldn't find anything for files which don't match): Execute(We shouldn't find anything for files which don't match):
AssertEqual AssertEqual
\ '/global/config.ini', \ '/global/config.ini',
\ ale#path#ResolveLocalPath(bufnr('%'), 'missing.ini', '/global/config.ini') \ ale#path#ResolveLocalPath(bufnr('%'), 'missing.ini', '/global/config.ini')

View File

@ -15,7 +15,7 @@ Before:
call ale#linter#Define('foobar', { call ale#linter#Define('foobar', {
\ 'name': 'testlinter', \ 'name': 'testlinter',
\ 'callback': 'TestCallback', \ 'callback': 'TestCallback',
\ 'executable': 'true', \ 'executable': has('win32') ? 'cmd' : 'true',
\ 'command': 'true', \ 'command': 'true',
\ 'read_buffer': 0, \ 'read_buffer': 0,
\}) \})
@ -35,8 +35,9 @@ Given foobar (Some file):
Execute(The loclist shouldn't be cleared when opening the loclist): Execute(The loclist shouldn't be cleared when opening the loclist):
call ale#Lint() call ale#Lint()
sleep 1ms
AssertEqual 1, len(getloclist(0)) AssertEqual 1, len(getloclist(0)), 'The loclist was never set'
" The cleanup function is called when the loclist window is closed. " The cleanup function is called when the loclist window is closed.
" If some cleanup is done for this buffer, for which nothing is wrong, " If some cleanup is done for this buffer, for which nothing is wrong,
@ -45,4 +46,4 @@ Execute(The loclist shouldn't be cleared when opening the loclist):
:lopen :lopen
:q :q
AssertEqual 1, len(getloclist(0)) AssertEqual 1, len(getloclist(0)), 'The loclist was cleared'