2017-02-11 15:16:08 +00:00
|
|
|
Before:
|
2018-05-28 16:38:14 +00:00
|
|
|
Save g:ale_buffer_info
|
|
|
|
|
|
|
|
let g:ale_buffer_info = {}
|
2017-05-31 09:01:41 +00:00
|
|
|
let g:ale_run_synchronously = 1
|
|
|
|
|
2017-02-11 15:16:08 +00:00
|
|
|
let g:command = 'echo test'
|
2017-04-12 22:17:55 +00:00
|
|
|
let g:filename = ''
|
|
|
|
let g:directory = ''
|
|
|
|
let g:preserved_directory = ''
|
2017-02-11 15:16:08 +00:00
|
|
|
|
|
|
|
function! TestCommandCallback(buffer) abort
|
|
|
|
" We are registering a temporary file, so we should delete it.
|
2017-04-12 22:17:55 +00:00
|
|
|
let g:filename = tempname()
|
2017-02-11 15:16:08 +00:00
|
|
|
call writefile(['foo'], g:filename)
|
|
|
|
call ale#engine#ManageFile(a:buffer, g:filename)
|
|
|
|
|
|
|
|
" We are registering this directory appropriately, so we should delete
|
|
|
|
" the whole thing.
|
2017-04-12 22:17:55 +00:00
|
|
|
let g:directory = tempname()
|
2017-02-11 15:16:08 +00:00
|
|
|
call mkdir(g:directory)
|
|
|
|
call writefile(['foo'], g:directory . '/bar')
|
|
|
|
call ale#engine#ManageDirectory(a:buffer, g:directory)
|
|
|
|
|
|
|
|
" We are registering this directory as temporary file, so we
|
|
|
|
" shouldn't delete it.
|
2017-04-12 22:17:55 +00:00
|
|
|
let g:preserved_directory = tempname()
|
2017-02-11 15:16:08 +00:00
|
|
|
call mkdir(g:preserved_directory)
|
|
|
|
call writefile(['foo'], g:preserved_directory . '/bar')
|
|
|
|
call ale#engine#ManageFile(a:buffer, g:preserved_directory)
|
|
|
|
|
|
|
|
return g:command
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! TestCallback(buffer, output) abort
|
|
|
|
return []
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('foobar', {
|
|
|
|
\ 'name': 'testlinter',
|
2017-09-08 20:51:49 +00:00
|
|
|
\ 'executable': has('win32') ? 'cmd' : 'echo',
|
2017-02-11 15:16:08 +00:00
|
|
|
\ 'callback': 'TestCallback',
|
|
|
|
\ 'command_callback': 'TestCommandCallback',
|
|
|
|
\})
|
|
|
|
|
|
|
|
After:
|
2018-05-28 16:38:14 +00:00
|
|
|
Restore
|
|
|
|
|
2017-04-12 22:17:55 +00:00
|
|
|
if !empty(g:preserved_directory)
|
|
|
|
call delete(g:preserved_directory, 'rf')
|
|
|
|
endif
|
2017-02-11 15:16:08 +00:00
|
|
|
|
2017-05-31 09:01:41 +00:00
|
|
|
unlet! g:ale_run_synchronously
|
2017-02-11 15:16:08 +00:00
|
|
|
unlet! g:command
|
|
|
|
unlet! g:filename
|
|
|
|
unlet! g:directory
|
|
|
|
unlet! g:preserved_directory
|
|
|
|
delfunction TestCommandCallback
|
|
|
|
delfunction TestCallback
|
|
|
|
call ale#linter#Reset()
|
|
|
|
|
|
|
|
Given foobar (Some imaginary filetype):
|
|
|
|
foo
|
|
|
|
bar
|
|
|
|
baz
|
|
|
|
|
|
|
|
Execute(ALE should delete managed files/directories appropriately after linting):
|
|
|
|
AssertEqual 'foobar', &filetype
|
|
|
|
|
2018-10-29 11:29:12 +00:00
|
|
|
call ale#Queue(0)
|
2017-02-11 15:16:08 +00:00
|
|
|
call ale#engine#WaitForJobs(2000)
|
|
|
|
|
2017-04-12 22:17:55 +00:00
|
|
|
Assert !filereadable(g:filename), 'The temporary file was not deleted'
|
|
|
|
Assert !isdirectory(g:directory), 'The temporary directory was not deleted'
|
|
|
|
Assert isdirectory(g:preserved_directory), 'The temporary directory was not kept'
|
2017-02-11 15:16:08 +00:00
|
|
|
|
|
|
|
Execute(ALE should delete managed files even if no command is run):
|
|
|
|
AssertEqual 'foobar', &filetype
|
|
|
|
|
|
|
|
let g:command = ''
|
|
|
|
|
2018-10-29 11:29:12 +00:00
|
|
|
call ale#Queue(0)
|
2017-02-11 15:16:08 +00:00
|
|
|
call ale#engine#WaitForJobs(2000)
|
|
|
|
|
2017-04-12 22:17:55 +00:00
|
|
|
Assert !filereadable(g:filename), 'The temporary file was not deleted'
|
|
|
|
Assert !isdirectory(g:directory), 'The temporary directory was not deleted'
|
|
|
|
Assert isdirectory(g:preserved_directory), 'The temporary directory was not kept'
|
2017-02-11 15:16:08 +00:00
|
|
|
|
|
|
|
Execute(ALE should delete managed files when the buffer is removed):
|
|
|
|
call ale#engine#InitBufferInfo(bufnr('%'))
|
|
|
|
call TestCommandCallback(bufnr('%'))
|
2017-07-07 22:47:41 +00:00
|
|
|
call ale#engine#Cleanup(bufnr('%'))
|
2017-02-11 15:16:08 +00:00
|
|
|
|
2017-04-12 22:17:55 +00:00
|
|
|
Assert !filereadable(g:filename), 'The temporary file was not deleted'
|
|
|
|
Assert !isdirectory(g:directory), 'The temporary directory was not deleted'
|
2017-02-11 15:16:08 +00:00
|
|
|
Assert isdirectory(g:preserved_directory), 'The tempoary directory was not kept'
|
2017-03-31 19:14:53 +00:00
|
|
|
|
|
|
|
Execute(ALE should create and delete directories for ale#engine#CreateDirectory()):
|
|
|
|
call ale#engine#InitBufferInfo(bufnr('%'))
|
|
|
|
|
|
|
|
let b:dir = ale#engine#CreateDirectory(bufnr('%'))
|
|
|
|
let b:dir2 = ale#engine#CreateDirectory(bufnr('%'))
|
|
|
|
|
|
|
|
Assert isdirectory(b:dir), 'The directory was not created'
|
|
|
|
|
|
|
|
" We should get the correct file permissions.
|
|
|
|
" We want to ensure that the directory is not readable by 'other'
|
2017-09-08 20:51:49 +00:00
|
|
|
if has('unix')
|
|
|
|
AssertEqual 'rwxr-x---', getfperm(b:dir)
|
|
|
|
endif
|
2017-03-31 19:14:53 +00:00
|
|
|
|
|
|
|
" The two directories shouldn't be the same.
|
|
|
|
AssertNotEqual b:dir2, b:dir
|
|
|
|
|
2017-07-07 22:47:41 +00:00
|
|
|
call ale#engine#Cleanup(bufnr('%'))
|
2017-03-31 19:14:53 +00:00
|
|
|
|
|
|
|
Assert !isdirectory(b:dir), 'The directory was not deleted'
|
|
|
|
Assert !isdirectory(b:dir2), 'The second directory was not deleted'
|
2018-05-28 16:38:14 +00:00
|
|
|
|
|
|
|
Execute(ale#engine#ManageFile should add the file even if the buffer info hasn't be set yet):
|
|
|
|
let g:ale_buffer_info = {}
|
|
|
|
call ale#engine#ManageFile(bufnr(''), '/foo/bar')
|
|
|
|
AssertEqual
|
|
|
|
\ ['/foo/bar'],
|
|
|
|
\ g:ale_buffer_info[bufnr('')].temporary_file_list
|
|
|
|
|
|
|
|
Execute(ale#engine#ManageDirectory should add the directory even if the buffer info hasn't be set yet):
|
|
|
|
let g:ale_buffer_info = {}
|
|
|
|
call ale#engine#ManageDirectory(bufnr(''), '/foo/bar')
|
|
|
|
AssertEqual
|
|
|
|
\ ['/foo/bar'],
|
|
|
|
\ g:ale_buffer_info[bufnr('')].temporary_directory_list
|