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