Make some temporary file tests more reliable

This commit is contained in:
w0rp 2017-04-12 23:17:55 +01:00
parent 0ce46fe7c8
commit ceb910e78c
1 changed files with 17 additions and 12 deletions

View File

@ -1,22 +1,25 @@
Before:
let g:command = 'echo test'
let g:filename = tempname()
let g:directory = tempname()
let g:preserved_directory = tempname()
let g:filename = ''
let g:directory = ''
let g:preserved_directory = ''
function! TestCommandCallback(buffer) abort
" We are registering a temporary file, so we should delete it.
let g:filename = tempname()
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.
let g:directory = tempname()
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.
let g:preserved_directory = tempname()
call mkdir(g:preserved_directory)
call writefile(['foo'], g:preserved_directory . '/bar')
call ale#engine#ManageFile(a:buffer, g:preserved_directory)
@ -36,7 +39,9 @@ Before:
\})
After:
call delete(g:preserved_directory, 'rf')
if !empty(g:preserved_directory)
call delete(g:preserved_directory, 'rf')
endif
unlet! g:command
unlet! g:filename
@ -57,9 +62,9 @@ Execute(ALE should delete managed files/directories appropriately after linting)
call ale#Lint()
call ale#engine#WaitForJobs(2000)
Assert !filereadable(g:filename), 'The tempoary file was not deleted'
Assert !isdirectory(g:directory), 'The tempoary directory was not deleted'
Assert isdirectory(g:preserved_directory), 'The tempoary directory was not kept'
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'
Execute(ALE should delete managed files even if no command is run):
AssertEqual 'foobar', &filetype
@ -69,17 +74,17 @@ Execute(ALE should delete managed files even if no command is run):
call ale#Lint()
call ale#engine#WaitForJobs(2000)
Assert !filereadable(g:filename), 'The tempoary file was not deleted'
Assert !isdirectory(g:directory), 'The tempoary directory was not deleted'
Assert isdirectory(g:preserved_directory), 'The tempoary directory was not kept'
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'
Execute(ALE should delete managed files when the buffer is removed):
call ale#engine#InitBufferInfo(bufnr('%'))
call TestCommandCallback(bufnr('%'))
call ale#cleanup#Buffer(bufnr('%'))
Assert !filereadable(g:filename), 'The tempoary file was not deleted'
Assert !isdirectory(g:directory), 'The tempoary directory was not deleted'
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 tempoary directory was not kept'
Execute(ALE should create and delete directories for ale#engine#CreateDirectory()):