Get more of the tests to pass on Windows

This commit is contained in:
w0rp 2017-10-23 01:26:31 +01:00
parent c4579e1809
commit 231398dddc
11 changed files with 105 additions and 48 deletions

View File

@ -2,20 +2,30 @@
" Description: Functions for working with Gradle projects. " Description: Functions for working with Gradle projects.
let s:script_path = fnamemodify(resolve(expand('<sfile>:p')), ':h') let s:script_path = fnamemodify(resolve(expand('<sfile>:p')), ':h')
let s:init_path = has('win32')
\ ? s:script_path . '\gradle\init.gradle'
\ : s:script_path . '/gradle/init.gradle'
function! ale#gradle#GetInitPath() abort
return s:init_path
endfunction
" Given a buffer number, find a Gradle project root. " Given a buffer number, find a Gradle project root.
function! ale#gradle#FindProjectRoot(buffer) abort function! ale#gradle#FindProjectRoot(buffer) abort
let l:gradlew_path = ale#path#FindNearestFile(a:buffer, 'gradlew') let l:gradlew_path = ale#path#FindNearestFile(a:buffer, 'gradlew')
if !empty(l:gradlew_path) if !empty(l:gradlew_path)
return fnamemodify(l:gradlew_path, ':h') return fnamemodify(l:gradlew_path, ':h')
endif endif
let l:settings_path = ale#path#FindNearestFile(a:buffer, 'settings.gradle') let l:settings_path = ale#path#FindNearestFile(a:buffer, 'settings.gradle')
if !empty(l:settings_path) if !empty(l:settings_path)
return fnamemodify(l:settings_path, ':h') return fnamemodify(l:settings_path, ':h')
endif endif
let l:build_path = ale#path#FindNearestFile(a:buffer, 'build.gradle') let l:build_path = ale#path#FindNearestFile(a:buffer, 'build.gradle')
if !empty(l:build_path) if !empty(l:build_path)
return fnamemodify(l:build_path, ':h') return fnamemodify(l:build_path, ':h')
endif endif
@ -28,6 +38,7 @@ endfunction
" command. Returns an empty string if cannot find the executable. " command. Returns an empty string if cannot find the executable.
function! ale#gradle#FindExecutable(buffer) abort function! ale#gradle#FindExecutable(buffer) abort
let l:gradlew_path = ale#path#FindNearestFile(a:buffer, 'gradlew') let l:gradlew_path = ale#path#FindNearestFile(a:buffer, 'gradlew')
if !empty(l:gradlew_path) if !empty(l:gradlew_path)
return l:gradlew_path return l:gradlew_path
endif endif
@ -47,7 +58,9 @@ function! ale#gradle#BuildClasspathCommand(buffer) abort
if !empty(l:executable) && !empty(l:project_root) if !empty(l:executable) && !empty(l:project_root)
return ale#path#CdString(l:project_root) return ale#path#CdString(l:project_root)
\ . l:executable . ' -I ' . s:script_path . '/gradle/init.gradle -q printClasspath' \ . ale#Escape(l:executable)
\ . ' -I ' . ale#Escape(s:init_path)
\ . ' -q printClasspath'
endif endif
return '' return ''

View File

@ -35,6 +35,6 @@ Execute(The .packages file should be set if detected):
AssertEqual AssertEqual
\ ale#Escape('dartanalyzer') \ ale#Escape('dartanalyzer')
\ . ' --packages ' . ale#Escape(g:dir . '/dart_paths/.packages') \ . ' --packages ' . ale#Escape(ale#path#Winify(g:dir . '/dart_paths/.packages'))
\ . ' %t', \ . ' %t',
\ ale_linters#dart#dartanalyzer#GetCommand(bufnr('')) \ ale_linters#dart#dartanalyzer#GetCommand(bufnr(''))

View File

@ -2,10 +2,18 @@ Before:
silent! cd /testplugin/test silent! cd /testplugin/test
silent file top/middle/bottom/dummy.txt silent file top/middle/bottom/dummy.txt
function! CheckTempFile(filename) abort
" Check every part of the temporary filename, except the random part.
AssertEqual fnamemodify(tempname(), ':h'), fnamemodify(a:filename, ':h:h')
AssertEqual 'dummy.txt', fnamemodify(a:filename, ':t')
endfunction
After: After:
unlet! g:result unlet! g:result
unlet! g:match unlet! g:match
delfunction CheckTempFile
Execute(FormatCommand should do nothing to basic command strings): Execute(FormatCommand should do nothing to basic command strings):
AssertEqual ['', 'awesome-linter do something'], ale#command#FormatCommand(bufnr('%'), 'awesome-linter do something', 0) AssertEqual ['', 'awesome-linter do something'], ale#command#FormatCommand(bufnr('%'), 'awesome-linter do something', 0)
@ -13,40 +21,57 @@ Execute(FormatCommand should handle %%, and ignore other percents):
AssertEqual ['', '% %%d %%f %x %'], ale#command#FormatCommand(bufnr('%'), '%% %%%d %%%f %x %', 0) AssertEqual ['', '% %%d %%f %x %'], ale#command#FormatCommand(bufnr('%'), '%% %%%d %%%f %x %', 0)
Execute(FormatCommand should convert %s to the current filename): Execute(FormatCommand should convert %s to the current filename):
AssertEqual ['', 'foo ' . shellescape(expand('%:p')) . ' bar ' . shellescape(expand('%:p'))], ale#command#FormatCommand(bufnr('%'), 'foo %s bar %s', 0) AssertEqual
\ [
\ '',
\ 'foo ' . ale#Escape(expand('%:p')) . ' bar ' . ale#Escape(expand('%:p'))
\ ],
\ ale#command#FormatCommand(bufnr('%'), 'foo %s bar %s', 0)
Execute(FormatCommand should convert %t to a new temporary filename): Execute(FormatCommand should convert %t to a new temporary filename):
let g:result = ale#command#FormatCommand(bufnr('%'), 'foo %t bar %t', 0) let g:result = ale#command#FormatCommand(bufnr('%'), 'foo %t bar %t', 0)
let g:match = matchlist(g:result[1], '\v^foo (''/tmp/[^'']*/dummy.txt'') bar (''/tmp/[^'']*/dummy.txt'')$')
call CheckTempFile(g:result[0])
let g:match = matchlist(g:result[1], '\v^foo (.*) bar (.*)$')
Assert !empty(g:match), 'No match found! Result was: ' . g:result[1] Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
" The first item of the result should be a temporary filename, and it should " The first item of the result should be a temporary filename, and it should
" be the same as the escaped name in the command string. " be the same as the escaped name in the command string.
AssertEqual shellescape(g:result[0]), g:match[1] AssertEqual ale#Escape(g:result[0]), g:match[1]
" The two temporary filenames formatted in should be the same. " The two temporary filenames formatted in should be the same.
AssertEqual g:match[1], g:match[2] AssertEqual g:match[1], g:match[2]
Execute(FormatCommand should let you combine %s and %t): Execute(FormatCommand should let you combine %s and %t):
let g:result = ale#command#FormatCommand(bufnr('%'), 'foo %t bar %s', 0) let g:result = ale#command#FormatCommand(bufnr('%'), 'foo %t bar %s', 0)
let g:match = matchlist(g:result[1], '\v^foo (''/tmp/.*/dummy.txt'') bar (''.*/dummy.txt'')$')
call CheckTempFile(g:result[0])
let g:match = matchlist(g:result[1], '\v^foo (.*) bar (.*)$')
Assert !empty(g:match), 'No match found! Result was: ' . g:result[1] Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
" The first item of the result should be a temporary filename, and it should " The first item of the result should be a temporary filename, and it should
" be the same as the escaped name in the command string. " be the same as the escaped name in the command string.
AssertEqual shellescape(g:result[0]), g:match[1] AssertEqual ale#Escape(g:result[0]), g:match[1]
" The second item should be equal to the original filename. " The second item should be equal to the original filename.
AssertEqual shellescape(expand('%:p')), g:match[2] AssertEqual ale#Escape(expand('%:p')), g:match[2]
Execute(EscapeCommandPart should escape all percent signs): Execute(EscapeCommandPart should escape all percent signs):
AssertEqual '%%s %%t %%%% %%s %%t %%%%', ale#engine#EscapeCommandPart('%s %t %% %s %t %%') AssertEqual '%%s %%t %%%% %%s %%t %%%%', ale#engine#EscapeCommandPart('%s %t %% %s %t %%')
Execute(EscapeCommandPart should pipe in temporary files appropriately): Execute(EscapeCommandPart should pipe in temporary files appropriately):
let g:result = ale#command#FormatCommand(bufnr('%'), 'foo bar', 1) let g:result = ale#command#FormatCommand(bufnr('%'), 'foo bar', 1)
let g:match = matchlist(g:result[1], '\v^foo bar \< (''/tmp/[^'']*/dummy.txt'')$')
call CheckTempFile(g:result[0])
let g:match = matchlist(g:result[1], '\v^foo bar \< (.*)$')
Assert !empty(g:match), 'No match found! Result was: ' . g:result[1] Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
AssertEqual shellescape(g:result[0]), g:match[1] AssertEqual ale#Escape(g:result[0]), g:match[1]
let g:result = ale#command#FormatCommand(bufnr('%'), 'foo bar %t', 1) let g:result = ale#command#FormatCommand(bufnr('%'), 'foo bar %t', 1)
let g:match = matchlist(g:result[1], '\v^foo bar (''/tmp/[^'']*/dummy.txt'')$')
call CheckTempFile(g:result[0])
let g:match = matchlist(g:result[1], '\v^foo bar (.*)$')
Assert !empty(g:match), 'No match found! Result was: ' . g:result[1] Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
AssertEqual shellescape(g:result[0]), g:match[1] AssertEqual ale#Escape(g:result[0]), g:match[1]

View File

@ -10,8 +10,8 @@ Before:
call ale#linter#Define('foobar', { call ale#linter#Define('foobar', {
\ 'name': 'testlinter', \ 'name': 'testlinter',
\ 'callback': 'TestCallback', \ 'callback': 'TestCallback',
\ 'executable': 'cat', \ 'executable': has('win32') ? 'cmd' : 'cat',
\ 'command': 'cat %t', \ 'command': has('win32') ? 'type %t' : 'cat %t',
\}) \})
After: After:

View File

@ -3,10 +3,10 @@ Execute(Relative paths should be resolved correctly):
\ '/foo/bar/baz/whatever.txt', \ '/foo/bar/baz/whatever.txt',
\ ale#path#GetAbsPath('/foo/bar/xyz', '../baz/whatever.txt') \ ale#path#GetAbsPath('/foo/bar/xyz', '../baz/whatever.txt')
AssertEqual AssertEqual
\ '/foo/bar/xyz/whatever.txt', \ has('win32') ? '/foo/bar/xyz\whatever.txt' : '/foo/bar/xyz/whatever.txt',
\ ale#path#GetAbsPath('/foo/bar/xyz', './whatever.txt') \ ale#path#GetAbsPath('/foo/bar/xyz', './whatever.txt')
AssertEqual AssertEqual
\ '/foo/bar/xyz/whatever.txt', \ has('win32') ? '/foo/bar/xyz\whatever.txt' : '/foo/bar/xyz/whatever.txt',
\ ale#path#GetAbsPath('/foo/bar/xyz', 'whatever.txt') \ ale#path#GetAbsPath('/foo/bar/xyz', 'whatever.txt')
Execute(Absolute paths should be resolved correctly): Execute(Absolute paths should be resolved correctly):

View File

@ -1,37 +1,44 @@
Before: Before:
Save $PATH
Save $PATHEXT
let $PATHEXT = '.'
call ale#test#SetDirectory('/testplugin/test') call ale#test#SetDirectory('/testplugin/test')
runtime ale_linters/kotlin/kotlinc.vim runtime ale_linters/kotlin/kotlinc.vim
let g:ale_gradle_path = $PATH
let g:command_tail = ' -I ' . ale#Escape(ale#gradle#GetInitPath())
\ . ' -q printClasspath'
let g:gradle_init_path = ale#path#Winify(g:dir . '../../autoload/ale/gradle/init.gradle')
After: After:
Restore
unlet! g:gradle_init_path
unlet! g:command_tail
call ale#test#RestoreDirectory() call ale#test#RestoreDirectory()
call ale#linter#Reset() call ale#linter#Reset()
let $PATH = g:ale_gradle_path
Execute(Should return 'gradlew' command if project includes gradle wapper): Execute(Should return 'gradlew' command if project includes gradle wapper):
call ale#test#SetFilename('gradle-test-files/wrapped-project/src/main/kotlin/dummy.kt') call ale#test#SetFilename('gradle-test-files/wrapped-project/src/main/kotlin/dummy.kt')
let g:project_root = '/testplugin/test/gradle-test-files/wrapped-project'
let g:gradle_executable = '/testplugin/test/gradle-test-files/wrapped-project/gradlew'
let g:gradle_init_path = '/testplugin/autoload/ale/gradle/init.gradle'
let g:gradle_options = '-I ' . g:gradle_init_path . ' -q printClasspath'
AssertEqual AssertEqual
\ "cd '" . g:project_root . "' && " . g:gradle_executable . " " . g:gradle_options, \ 'cd ' . ale#Escape(ale#path#Winify(g:dir . '/gradle-test-files/wrapped-project'))
\ . ' && ' . ale#Escape(ale#path#Winify(g:dir . '/gradle-test-files/wrapped-project/gradlew'))
\ . g:command_tail,
\ ale#gradle#BuildClasspathCommand(bufnr('')) \ ale#gradle#BuildClasspathCommand(bufnr(''))
Execute(Should return 'gradle' command if project does not include gradle wapper): Execute(Should return 'gradle' command if project does not include gradle wapper):
call ale#test#SetFilename('gradle-test-files/unwrapped-project/src/main/kotlin/dummy.kt') call ale#test#SetFilename('gradle-test-files/unwrapped-project/src/main/kotlin/dummy.kt')
let $PATH .= ':' . g:dir . '/gradle-test-files' let $PATH .= (has('win32') ? ';' : ':')
\ . ale#path#Winify(g:dir . '/gradle-test-files')
let g:project_root = '/testplugin/test/gradle-test-files/unwrapped-project'
let g:gradle_executable = 'gradle'
let g:gradle_init_path = '/testplugin/autoload/ale/gradle/init.gradle'
let g:gradle_options = '-I ' . g:gradle_init_path . ' -q printClasspath'
AssertEqual AssertEqual
\ "cd '" . g:project_root . "' && " . g:gradle_executable . " " . g:gradle_options, \ 'cd ' . ale#Escape(ale#path#Winify(g:dir . '/gradle-test-files/unwrapped-project'))
\ . ' && ' . ale#Escape('gradle')
\ . g:command_tail,
\ ale#gradle#BuildClasspathCommand(bufnr('')) \ ale#gradle#BuildClasspathCommand(bufnr(''))
Execute(Should return empty string if gradle cannot be executed): Execute(Should return empty string if gradle cannot be executed):

View File

@ -1,31 +1,37 @@
Before: Before:
Save $PATH
Save $PATHEXT
" Count the gradle executable without .exe as executable on Windows
let $PATHEXT = '.'
call ale#test#SetDirectory('/testplugin/test') call ale#test#SetDirectory('/testplugin/test')
runtime ale_linters/kotlin/kotlinc.vim runtime ale_linters/kotlin/kotlinc.vim
let g:ale_gradle_path = $PATH
After: After:
Restore
call ale#test#RestoreDirectory() call ale#test#RestoreDirectory()
call ale#linter#Reset() call ale#linter#Reset()
let $PATH = g:ale_gradle_path
Execute(Should return 'gradlew' if found in parent directory): Execute(Should return 'gradlew' if found in parent directory):
call ale#test#SetFilename('gradle-test-files/wrapped-project/src/main/kotlin/dummy.kt') call ale#test#SetFilename('gradle-test-files/wrapped-project/src/main/kotlin/dummy.kt')
AssertEqual AssertEqual
\ g:dir . '/gradle-test-files/wrapped-project/gradlew', \ ale#path#Winify(g:dir . '/gradle-test-files/wrapped-project/gradlew'),
\ ale#gradle#FindExecutable(bufnr('')) \ ale#gradle#FindExecutable(bufnr(''))
Execute(Should return 'gradle' if 'gradlew' not found in parent directory): Execute(Should return 'gradle' if 'gradlew' not found in parent directory):
call ale#test#SetFilename('gradle-test-files/unwrapped-project/src/main/kotlin/dummy.kt') call ale#test#SetFilename('gradle-test-files/unwrapped-project/src/main/kotlin/dummy.kt')
let $PATH .= ':' . g:dir . '/gradle-test-files' let $PATH .= (has('win32') ? ';': ':') . ale#path#Winify(g:dir . '/gradle-test-files')
AssertEqual AssertEqual
\ 'gradle', \ 'gradle',
\ ale#gradle#FindExecutable(bufnr('')) \ ale#gradle#FindExecutable(bufnr(''))
Execute(Should return empty string if 'gradlew' not in parent directory and gradle not in path): Execute(Should return empty string if 'gradlew' not in parent directory and gradle not in path):
call ale#test#SetFilename('gradle-test-files/unwrapped-project/src/main/kotlin/dummy.kt') call ale#test#SetFilename('gradle-test-files/unwrapped-project/src/main/kotlin/dummy.kt')
AssertEqual AssertEqual
\ '', \ '',
\ ale#gradle#FindExecutable(bufnr('')) \ ale#gradle#FindExecutable(bufnr(''))

View File

@ -10,21 +10,21 @@ Execute(Should return directory for 'gradlew' if found in parent directory):
call ale#test#SetFilename('gradle-test-files/wrapped-project/src/main/kotlin/dummy.kt') call ale#test#SetFilename('gradle-test-files/wrapped-project/src/main/kotlin/dummy.kt')
AssertEqual AssertEqual
\ g:dir . '/gradle-test-files/wrapped-project', \ ale#path#Winify(g:dir . '/gradle-test-files/wrapped-project'),
\ ale#gradle#FindProjectRoot(bufnr('')) \ ale#gradle#FindProjectRoot(bufnr(''))
Execute(Should return directory for 'settings.gradle' if found in parent directory): Execute(Should return directory for 'settings.gradle' if found in parent directory):
call ale#test#SetFilename('gradle-test-files/settings-gradle-project/src/main/kotlin/dummy.kt') call ale#test#SetFilename('gradle-test-files/settings-gradle-project/src/main/kotlin/dummy.kt')
AssertEqual AssertEqual
\ g:dir . '/gradle-test-files/settings-gradle-project', \ ale#path#Winify(g:dir . '/gradle-test-files/settings-gradle-project'),
\ ale#gradle#FindProjectRoot(bufnr('')) \ ale#gradle#FindProjectRoot(bufnr(''))
Execute(Should return directory for 'build.gradle' if found in parent directory): Execute(Should return directory for 'build.gradle' if found in parent directory):
call ale#test#SetFilename('gradle-test-files/build-gradle-project/src/main/kotlin/dummy.kt') call ale#test#SetFilename('gradle-test-files/build-gradle-project/src/main/kotlin/dummy.kt')
AssertEqual AssertEqual
\ g:dir . '/gradle-test-files/build-gradle-project', \ ale#path#Winify(g:dir . '/gradle-test-files/build-gradle-project'),
\ ale#gradle#FindProjectRoot(bufnr('')) \ ale#gradle#FindProjectRoot(bufnr(''))
Execute(Should return empty string if gradle files are not found in parent directory): Execute(Should return empty string if gradle files are not found in parent directory):

View File

@ -36,7 +36,7 @@ Before:
call ale#linter#Define('testft', { call ale#linter#Define('testft', {
\ 'name': 'x', \ 'name': 'x',
\ 'executable': 'echo', \ 'executable': has('win32') ? 'cmd': 'echo',
\ 'command': 'echo', \ 'command': 'echo',
\ 'callback': 'GenerateResults', \ 'callback': 'GenerateResults',
\}) \})

View File

@ -67,7 +67,10 @@ Execute(History should be set when commands are run):
call ale#Lint() call ale#Lint()
call ale#engine#WaitForJobs(2000) call ale#engine#WaitForJobs(2000)
let g:history = ale#history#Get(bufnr('')) let g:history = filter(
\ copy(ale#history#Get(bufnr(''))),
\ 'v:val.job_id isnot# ''executable''',
\)
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]))

View File

@ -2,9 +2,12 @@ Before:
Save &filetype Save &filetype
Save g:ale_buffer_info Save g:ale_buffer_info
Save g:ale_lint_on_enter Save g:ale_lint_on_enter
Save g:ale_set_lists_synchronously
let g:buf = bufnr('') let g:buf = bufnr('')
let g:ale_lint_on_enter = 1 let g:ale_lint_on_enter = 1
let g:ale_run_synchronously = 1 let g:ale_run_synchronously = 1
let g:ale_set_lists_synchronously = 1
function! TestCallback(buffer, output) function! TestCallback(buffer, output)
return [{ return [{
@ -17,8 +20,8 @@ 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': has('win32') ? 'echo' : 'true',
\}) \})
After: After: