diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_cleanup.vader | 6 | ||||
-rw-r--r-- | test/test_temporary_file_management.vader | 83 |
2 files changed, 86 insertions, 3 deletions
diff --git a/test/test_cleanup.vader b/test/test_cleanup.vader index ec2b38aa..23e5bcf0 100644 --- a/test/test_cleanup.vader +++ b/test/test_cleanup.vader @@ -2,8 +2,8 @@ Before: let g:buffer = bufnr('%') let g:ale_buffer_info = { - \ g:buffer : {}, - \ 10347: {}, + \ g:buffer : {'temporary_file_list': [], 'temporary_directory_list': []}, + \ 10347: {'temporary_file_list': [], 'temporary_directory_list': []}, \} After: @@ -12,4 +12,4 @@ After: Execute('ALE globals should be cleared when the buffer is closed.'): :q! - AssertEqual {10347: {}}, g:ale_buffer_info + AssertEqual {10347: {'temporary_file_list': [], 'temporary_directory_list': []}}, g:ale_buffer_info diff --git a/test/test_temporary_file_management.vader b/test/test_temporary_file_management.vader new file mode 100644 index 00000000..17a375e1 --- /dev/null +++ b/test/test_temporary_file_management.vader @@ -0,0 +1,83 @@ +Before: + let g:command = 'echo test' + let g:filename = tempname() + let g:directory = tempname() + let g:preserved_directory = tempname() + + function! TestCommandCallback(buffer) abort + " We are registering a temporary file, so we should delete it. + 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. + 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. + 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', + \ 'executable': 'echo', + \ 'callback': 'TestCallback', + \ 'command_callback': 'TestCommandCallback', + \}) + +After: + call delete(g:preserved_directory, 'rf') + + 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 + + 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' + +Execute(ALE should delete managed files even if no command is run): + AssertEqual 'foobar', &filetype + + let g:command = '' + + 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' + +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 isdirectory(g:preserved_directory), 'The tempoary directory was not kept' |