Skip to content

Commit

Permalink
Get all tests to pass on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rp committed Oct 23, 2017
1 parent 231398d commit b952dda
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 106 deletions.
3 changes: 2 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ install:
test_script:
- cd C:\testplugin
- 'C:\vim\vim\vim80\vim.exe -u test\vimrc "+Vader! test/test_path_uri.vader"'
- 'C:\vim\vim\vim80\vim.exe -u test\vimrc "+Vader!
test/*.vader test/*/*.vader test/*/*/*.vader test/*/*/*.vader"'
4 changes: 2 additions & 2 deletions autoload/ale/engine.vim
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ function! ale#engine#WaitForJobs(deadline) abort

" Gather all of the jobs from every buffer.
for l:info in values(g:ale_buffer_info)
call extend(l:job_list, l:info.job_list)
call extend(l:job_list, get(l:info, 'job_list', []))
endfor

" NeoVim has a built-in API for this, so use that.
Expand Down Expand Up @@ -889,7 +889,7 @@ function! ale#engine#WaitForJobs(deadline) abort

" Check again to see if any jobs are running.
for l:info in values(g:ale_buffer_info)
for l:job_id in l:info.job_list
for l:job_id in get(l:info, 'job_list', [])
if ale#job#IsRunning(l:job_id)
let l:has_new_jobs = 1
break
Expand Down
140 changes: 92 additions & 48 deletions test/test_ale_fix.vader
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ Before:
let g:ale_enabled = 0
let g:ale_echo_cursor = 0
let g:ale_run_synchronously = 1
let g:ale_set_lists_synchronously = 1
let g:ale_fix_buffer_data = {}
let g:ale_fixers = {
\ 'testft': [],
\}
let &shell = '/bin/bash'

if !has('win32')
let &shell = '/bin/bash'
endif

call ale#test#SetDirectory('/testplugin/test')
call ale#test#SetFilename('test.txt')

function AddCarets(buffer, lines) abort
" map() is applied to the original lines here.
Expand Down Expand Up @@ -67,6 +74,7 @@ Before:
After:
Restore
unlet! g:ale_run_synchronously
unlet! g:ale_set_lists_synchronously
unlet! g:ale_emulate_job_failure
unlet! b:ale_fixers
delfunction AddCarets
Expand All @@ -79,6 +87,9 @@ After:
delfunction RemoveLastLineOneArg
delfunction TestCallback
delfunction SetUpLinters

call ale#test#RestoreDirectory()

call ale#fix#registry#ResetToDefaults()
call ale#linter#Reset()

Expand Down Expand Up @@ -129,8 +140,13 @@ Expect(Only the second function should be applied):
$c

Execute(ALEFix should allow commands to be run):
let g:ale_fixers.testft = ['CatLine']
ALEFix
if has('win32')
" Just skip this test on Windows, we can't run it.
call setline(1, ['a', 'b', 'c', 'd'])
else
let g:ale_fixers.testft = ['CatLine']
ALEFix
endif

Expect(An extra line should be added):
a
Expand All @@ -139,22 +155,39 @@ Expect(An extra line should be added):
d

Execute(ALEFix should allow temporary files to be read):
let g:ale_fixers.testft = ['ReplaceWithTempFile']
ALEFix
if has('win32')
" Just skip this test on Windows, we can't run it.
call setline(1, ['x'])
2,3d
else
let g:ale_fixers.testft = ['ReplaceWithTempFile']
ALEFix
endif

Expect(The line we wrote to the temporary file should be used here):
x

Execute(ALEFix should allow jobs and simple functions to be combined):
let g:ale_fixers.testft = ['ReplaceWithTempFile', 'AddDollars']
ALEFix
if has('win32')
" Just skip this test on Windows, we can't run it.
call setline(1, ['$x'])
2,3d
else
let g:ale_fixers.testft = ['ReplaceWithTempFile', 'AddDollars']
ALEFix
endif

Expect(The lines from the temporary file should be modified):
$x

Execute(ALEFix should send lines modified by functions to jobs):
let g:ale_fixers.testft = ['AddDollars', 'CatLine']
ALEFix
if has('win32')
" Just skip this test on Windows, we can't run it.
call setline(1, ['$a', '$b', '$c', 'd'])
else
let g:ale_fixers.testft = ['AddDollars', 'CatLine']
ALEFix
endif

Expect(The lines should first be modified by the function, then the job):
$a
Expand Down Expand Up @@ -257,18 +290,20 @@ Execute(ALEFix should save files on the save event):
AssertEqual ['$a', '$b', '$c'], readfile('fix_test_file')
Assert !&modified, 'The was marked as ''modified'''

" We have run the linter.
AssertEqual [{
\ 'bufnr': bufnr('%'),
\ 'lnum': 1,
\ 'vcol': 0,
\ 'col': 1,
\ 'text': 'xxx',
\ 'type': 'E',
\ 'nr': -1,
\ 'pattern': '',
\ 'valid': 1,
\}], getloclist(0)
if !has('win32')
" We should have run the linter.
AssertEqual [{
\ 'bufnr': bufnr('%'),
\ 'lnum': 1,
\ 'vcol': 0,
\ 'col': 1,
\ 'text': 'xxx',
\ 'type': 'E',
\ 'nr': -1,
\ 'pattern': '',
\ 'valid': 1,
\}], getloclist(0)
endif

Expect(The buffer should be modified):
$a
Expand All @@ -294,18 +329,20 @@ Execute(ALEFix should still lint with no linters to be applied):

Assert !filereadable('fix_test_file'), 'The file should not have been saved'

" We have run the linter.
AssertEqual [{
\ 'bufnr': bufnr('%'),
\ 'lnum': 1,
\ 'vcol': 0,
\ 'col': 1,
\ 'text': 'xxx',
\ 'type': 'E',
\ 'nr': -1,
\ 'pattern': '',
\ 'valid': 1,
\}], getloclist(0)
if !has('win32')
" We have run the linter.
AssertEqual [{
\ 'bufnr': bufnr('%'),
\ 'lnum': 1,
\ 'vcol': 0,
\ 'col': 1,
\ 'text': 'xxx',
\ 'type': 'E',
\ 'nr': -1,
\ 'pattern': '',
\ 'valid': 1,
\}], getloclist(0)
endif

Expect(The buffer should be the same):
a
Expand All @@ -326,18 +363,20 @@ Execute(ALEFix should still lint when nothing was fixed on save):

Assert !filereadable('fix_test_file'), 'The file should not have been saved'

" We have run the linter.
AssertEqual [{
\ 'bufnr': bufnr('%'),
\ 'lnum': 1,
\ 'vcol': 0,
\ 'col': 1,
\ 'text': 'xxx',
\ 'type': 'E',
\ 'nr': -1,
\ 'pattern': '',
\ 'valid': 1,
\}], getloclist(0)
if !has('win32')
" We should have run the linter.
AssertEqual [{
\ 'bufnr': bufnr('%'),
\ 'lnum': 1,
\ 'vcol': 0,
\ 'col': 1,
\ 'text': 'xxx',
\ 'type': 'E',
\ 'nr': -1,
\ 'pattern': '',
\ 'valid': 1,
\}], getloclist(0)
endif

Expect(The buffer should be the same):
a
Expand All @@ -358,7 +397,7 @@ Execute(ale#fix#InitBufferData() should set up the correct data):
\ bufnr(''): {
\ 'temporary_directory_list': [],
\ 'vars': b:,
\ 'filename': simplify(getcwd() . '/fix_test_file'),
\ 'filename': ale#path#Winify(getcwd() . '/fix_test_file'),
\ 'done': 0,
\ 'lines_before': ['a', 'b', 'c'],
\ 'should_save': 1,
Expand All @@ -374,8 +413,13 @@ Expect(There should be only two lines):
b

Execute(ALEFix functions returning jobs should be able to accept one argument):
let g:ale_fixers.testft = ['CatLine']
ALEFix
if has('win32')
" Just skip this test on Windows, we can't run it.
call setline(1, ['a', 'b', 'c', 'd'])
else
let g:ale_fixers.testft = ['CatLine']
ALEFix
endif

Expect(An extra line should be added):
a
Expand Down
4 changes: 2 additions & 2 deletions test/test_ale_info.vader
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ Execute (ALEInfo command history should print command output if logging is on):

Execute (ALEInfo should include executable checks in the history):
call ale#linter#Define('testft', g:testlinter1)
call ale#engine#IsExecutable(bufnr(''), 'echo')
call ale#engine#IsExecutable(bufnr(''), has('win32') ? 'cmd' : 'echo')
call ale#engine#IsExecutable(bufnr(''), 'TheresNoWayThisIsExecutable')

call CheckInfo([
Expand All @@ -365,6 +365,6 @@ Execute (ALEInfo should include executable checks in the history):
\ '',
\] + g:globals_lines + g:command_header + [
\ '',
\ '(executable check - success) echo',
\ '(executable check - success) ' . (has('win32') ? 'cmd' : 'echo'),
\ '(executable check - failure) TheresNoWayThisIsExecutable',
\])
10 changes: 8 additions & 2 deletions test/test_ale_lint_command.vader
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Before:
\ 'lnum': 2,
\ 'vcol': 0,
\ 'col': 3,
\ 'text': a:output[0],
\ 'text': join(split(a:output[0])),
\ 'type': 'E',
\ 'nr': -1,
\}]
Expand All @@ -37,7 +37,7 @@ Before:
call ale#linter#Define('foobar', {
\ 'name': 'testlinter',
\ 'callback': 'ToggleTestCallback',
\ 'executable': 'echo',
\ 'executable': has('win32') ? 'cmd' : 'echo',
\ 'command': 'echo foo bar',
\})

Expand All @@ -63,5 +63,11 @@ Execute(ALELint should run the linters):
ALELint
call ale#engine#WaitForJobs(2000)

if !has('nvim')
" Sleep so the delayed list function can run.
" This breaks the tests in NeoVim for some reason.
sleep 1ms
endif

" Check the loclist
AssertEqual g:expected_loclist, getloclist(0)
2 changes: 1 addition & 1 deletion test/test_ale_toggle.vader
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Before:
call ale#linter#Define('foobar', {
\ 'name': 'testlinter',
\ 'callback': 'ToggleTestCallback',
\ 'executable': 'echo',
\ 'executable': has('win32') ? 'cmd' : 'echo',
\ 'command': 'echo',
\ 'read_buffer': 0,
\})
Expand Down
Loading

0 comments on commit b952dda

Please sign in to comment.