From 231398dddc59b01bc83f5a333af1ae741d31ed51 Mon Sep 17 00:00:00 2001 From: w0rp Date: Mon, 23 Oct 2017 01:26:31 +0100 Subject: Get more of the tests to pass on Windows --- autoload/ale/gradle.vim | 15 +++++++- .../test_dartanalyzer_command_callback.vader | 2 +- test/test_format_command.vader | 45 +++++++++++++++++----- test/test_format_temporary_file_creation.vader | 4 +- test/test_get_abspath.vader | 4 +- test/test_gradle_build_classpath_command.vader | 39 +++++++++++-------- test/test_gradle_find_executable.vader | 24 +++++++----- test/test_gradle_find_project_root.vader | 6 +-- test/test_highlight_placement.vader | 2 +- test/test_history_saving.vader | 5 ++- test/test_lint_on_enter_when_file_changed.vader | 7 +++- 11 files changed, 105 insertions(+), 48 deletions(-) diff --git a/autoload/ale/gradle.vim b/autoload/ale/gradle.vim index 89b56a82..dc377fb9 100644 --- a/autoload/ale/gradle.vim +++ b/autoload/ale/gradle.vim @@ -2,20 +2,30 @@ " Description: Functions for working with Gradle projects. let s:script_path = fnamemodify(resolve(expand(':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. function! ale#gradle#FindProjectRoot(buffer) abort let l:gradlew_path = ale#path#FindNearestFile(a:buffer, 'gradlew') + if !empty(l:gradlew_path) return fnamemodify(l:gradlew_path, ':h') endif let l:settings_path = ale#path#FindNearestFile(a:buffer, 'settings.gradle') + if !empty(l:settings_path) return fnamemodify(l:settings_path, ':h') endif let l:build_path = ale#path#FindNearestFile(a:buffer, 'build.gradle') + if !empty(l:build_path) return fnamemodify(l:build_path, ':h') endif @@ -28,6 +38,7 @@ endfunction " command. Returns an empty string if cannot find the executable. function! ale#gradle#FindExecutable(buffer) abort let l:gradlew_path = ale#path#FindNearestFile(a:buffer, 'gradlew') + if !empty(l:gradlew_path) return l:gradlew_path endif @@ -47,7 +58,9 @@ function! ale#gradle#BuildClasspathCommand(buffer) abort if !empty(l:executable) && !empty(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 return '' diff --git a/test/command_callback/test_dartanalyzer_command_callback.vader b/test/command_callback/test_dartanalyzer_command_callback.vader index c26028de..dbd8290c 100644 --- a/test/command_callback/test_dartanalyzer_command_callback.vader +++ b/test/command_callback/test_dartanalyzer_command_callback.vader @@ -35,6 +35,6 @@ Execute(The .packages file should be set if detected): AssertEqual \ ale#Escape('dartanalyzer') - \ . ' --packages ' . ale#Escape(g:dir . '/dart_paths/.packages') + \ . ' --packages ' . ale#Escape(ale#path#Winify(g:dir . '/dart_paths/.packages')) \ . ' %t', \ ale_linters#dart#dartanalyzer#GetCommand(bufnr('')) diff --git a/test/test_format_command.vader b/test/test_format_command.vader index 156ced9b..f6143a5a 100644 --- a/test/test_format_command.vader +++ b/test/test_format_command.vader @@ -2,10 +2,18 @@ Before: silent! cd /testplugin/test 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: unlet! g:result unlet! g:match + delfunction CheckTempFile + Execute(FormatCommand should do nothing to basic command strings): 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) 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): 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] " 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. - 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. AssertEqual g:match[1], g:match[2] Execute(FormatCommand should let you combine %s and %t): 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] " 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. - 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. - AssertEqual shellescape(expand('%:p')), g:match[2] + AssertEqual ale#Escape(expand('%:p')), g:match[2] Execute(EscapeCommandPart should escape all percent signs): AssertEqual '%%s %%t %%%% %%s %%t %%%%', ale#engine#EscapeCommandPart('%s %t %% %s %t %%') Execute(EscapeCommandPart should pipe in temporary files appropriately): 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] - 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: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] - AssertEqual shellescape(g:result[0]), g:match[1] + AssertEqual ale#Escape(g:result[0]), g:match[1] diff --git a/test/test_format_temporary_file_creation.vader b/test/test_format_temporary_file_creation.vader index 0639c593..1afaba30 100644 --- a/test/test_format_temporary_file_creation.vader +++ b/test/test_format_temporary_file_creation.vader @@ -10,8 +10,8 @@ Before: call ale#linter#Define('foobar', { \ 'name': 'testlinter', \ 'callback': 'TestCallback', - \ 'executable': 'cat', - \ 'command': 'cat %t', + \ 'executable': has('win32') ? 'cmd' : 'cat', + \ 'command': has('win32') ? 'type %t' : 'cat %t', \}) After: diff --git a/test/test_get_abspath.vader b/test/test_get_abspath.vader index 2def3773..5f813804 100644 --- a/test/test_get_abspath.vader +++ b/test/test_get_abspath.vader @@ -3,10 +3,10 @@ Execute(Relative paths should be resolved correctly): \ '/foo/bar/baz/whatever.txt', \ ale#path#GetAbsPath('/foo/bar/xyz', '../baz/whatever.txt') 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') 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') Execute(Absolute paths should be resolved correctly): diff --git a/test/test_gradle_build_classpath_command.vader b/test/test_gradle_build_classpath_command.vader index 84135268..c31dc698 100644 --- a/test/test_gradle_build_classpath_command.vader +++ b/test/test_gradle_build_classpath_command.vader @@ -1,37 +1,44 @@ Before: + Save $PATH + Save $PATHEXT + + let $PATHEXT = '.' + call ale#test#SetDirectory('/testplugin/test') 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: + Restore + + unlet! g:gradle_init_path + unlet! g:command_tail + call ale#test#RestoreDirectory() call ale#linter#Reset() - let $PATH = g:ale_gradle_path Execute(Should return 'gradlew' command if project includes gradle wapper): 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 - \ "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('')) 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') - let $PATH .= ':' . 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' + let $PATH .= (has('win32') ? ';' : ':') + \ . ale#path#Winify(g:dir . '/gradle-test-files') 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('')) Execute(Should return empty string if gradle cannot be executed): diff --git a/test/test_gradle_find_executable.vader b/test/test_gradle_find_executable.vader index 2ae2b464..054c21a8 100644 --- a/test/test_gradle_find_executable.vader +++ b/test/test_gradle_find_executable.vader @@ -1,31 +1,37 @@ Before: + Save $PATH + Save $PATHEXT + + " Count the gradle executable without .exe as executable on Windows + let $PATHEXT = '.' + call ale#test#SetDirectory('/testplugin/test') runtime ale_linters/kotlin/kotlinc.vim - let g:ale_gradle_path = $PATH After: + Restore + call ale#test#RestoreDirectory() call ale#linter#Reset() - let $PATH = g:ale_gradle_path - + Execute(Should return 'gradlew' if found in parent directory): call ale#test#SetFilename('gradle-test-files/wrapped-project/src/main/kotlin/dummy.kt') AssertEqual - \ g:dir . '/gradle-test-files/wrapped-project/gradlew', + \ ale#path#Winify(g:dir . '/gradle-test-files/wrapped-project/gradlew'), \ ale#gradle#FindExecutable(bufnr('')) 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') - let $PATH .= ':' . g:dir . '/gradle-test-files' - + let $PATH .= (has('win32') ? ';': ':') . ale#path#Winify(g:dir . '/gradle-test-files') + AssertEqual - \ 'gradle', + \ 'gradle', \ ale#gradle#FindExecutable(bufnr('')) 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') - + AssertEqual - \ '', + \ '', \ ale#gradle#FindExecutable(bufnr('')) diff --git a/test/test_gradle_find_project_root.vader b/test/test_gradle_find_project_root.vader index bd1b8d7d..87af1109 100644 --- a/test/test_gradle_find_project_root.vader +++ b/test/test_gradle_find_project_root.vader @@ -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') AssertEqual - \ g:dir . '/gradle-test-files/wrapped-project', + \ ale#path#Winify(g:dir . '/gradle-test-files/wrapped-project'), \ ale#gradle#FindProjectRoot(bufnr('')) 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') AssertEqual - \ g:dir . '/gradle-test-files/settings-gradle-project', + \ ale#path#Winify(g:dir . '/gradle-test-files/settings-gradle-project'), \ ale#gradle#FindProjectRoot(bufnr('')) 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') AssertEqual - \ g:dir . '/gradle-test-files/build-gradle-project', + \ ale#path#Winify(g:dir . '/gradle-test-files/build-gradle-project'), \ ale#gradle#FindProjectRoot(bufnr('')) Execute(Should return empty string if gradle files are not found in parent directory): diff --git a/test/test_highlight_placement.vader b/test/test_highlight_placement.vader index c1909c4f..de8decc1 100644 --- a/test/test_highlight_placement.vader +++ b/test/test_highlight_placement.vader @@ -36,7 +36,7 @@ Before: call ale#linter#Define('testft', { \ 'name': 'x', - \ 'executable': 'echo', + \ 'executable': has('win32') ? 'cmd': 'echo', \ 'command': 'echo', \ 'callback': 'GenerateResults', \}) diff --git a/test/test_history_saving.vader b/test/test_history_saving.vader index dc7ce0d7..020ceb53 100644 --- a/test/test_history_saving.vader +++ b/test/test_history_saving.vader @@ -67,7 +67,10 @@ Execute(History should be set when commands are run): call ale#Lint() 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 sort(['status', 'exit_code', 'job_id', 'command']), sort(keys(g:history[0])) diff --git a/test/test_lint_on_enter_when_file_changed.vader b/test/test_lint_on_enter_when_file_changed.vader index 4d4f19cc..d2b38e04 100644 --- a/test/test_lint_on_enter_when_file_changed.vader +++ b/test/test_lint_on_enter_when_file_changed.vader @@ -2,9 +2,12 @@ Before: Save &filetype Save g:ale_buffer_info Save g:ale_lint_on_enter + Save g:ale_set_lists_synchronously + let g:buf = bufnr('') let g:ale_lint_on_enter = 1 let g:ale_run_synchronously = 1 + let g:ale_set_lists_synchronously = 1 function! TestCallback(buffer, output) return [{ @@ -17,8 +20,8 @@ Before: call ale#linter#Define('foobar', { \ 'name': 'testlinter', \ 'callback': 'TestCallback', - \ 'executable': 'true', - \ 'command': 'true', + \ 'executable': has('win32') ? 'cmd' : 'true', + \ 'command': has('win32') ? 'echo' : 'true', \}) After: -- cgit v1.2.3