]> git.madduck.net Git - etc/vim.git/blobdiff - .vim/bundle/ale/test/test_temporary_file_management.vader

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / test / test_temporary_file_management.vader
diff --git a/.vim/bundle/ale/test/test_temporary_file_management.vader b/.vim/bundle/ale/test/test_temporary_file_management.vader
new file mode 100644 (file)
index 0000000..bb73588
--- /dev/null
@@ -0,0 +1,146 @@
+Before:
+  Save g:ale_buffer_info
+
+  let g:ale_buffer_info = {}
+  let g:ale_run_synchronously = 1
+
+  let g:command = 'echo test'
+  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#command#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#command#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#command#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': has('win32') ? 'cmd' : 'echo',
+  \ 'callback': 'TestCallback',
+  \ 'command': function('TestCommandCallback'),
+  \})
+  call ale#command#ClearData()
+
+After:
+  Restore
+
+  if !empty(g:preserved_directory)
+    call delete(g:preserved_directory, 'rf')
+  endif
+
+  unlet! g:ale_run_synchronously
+  unlet! g:command
+  unlet! g:filename
+  unlet! g:directory
+  unlet! g:preserved_directory
+  delfunction TestCommandCallback
+  delfunction TestCallback
+  call ale#linter#Reset()
+  call ale#command#ClearData()
+
+Given foobar (Some imaginary filetype):
+  foo
+  bar
+  baz
+
+Execute(ALE should delete managed files/directories appropriately after linting):
+  AssertEqual 'foobar', &filetype
+
+  call ale#Queue(0)
+  call ale#test#FlushJobs()
+
+  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
+
+  let g:command = ''
+
+  call ale#Queue(0)
+  call ale#test#WaitForJobs(2000)
+
+  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#engine#Cleanup(bufnr('%'))
+
+  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#command#CreateDirectory()):
+  call ale#engine#InitBufferInfo(bufnr('%'))
+
+  let b:dir = ale#command#CreateDirectory(bufnr('%'))
+  let b:dir2 = ale#command#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'
+  if has('unix')
+    AssertEqual 'rwxr-x---', getfperm(b:dir)
+  endif
+
+  " The two directories shouldn't be the same.
+  AssertNotEqual b:dir2, b:dir
+
+  call ale#engine#Cleanup(bufnr('%'))
+
+  Assert !isdirectory(b:dir), 'The directory was not deleted'
+  Assert !isdirectory(b:dir2), 'The second directory was not deleted'
+
+Execute(ale#command#ManageFile should add the file even if the buffer info hasn't been set yet):
+  call ale#command#ManageFile(bufnr(''), '/foo/bar')
+
+  AssertEqual
+  \ {
+  \   bufnr(''): {
+  \     'jobs': {},
+  \     'file_list': ['/foo/bar'],
+  \     'directory_list': [],
+  \   },
+  \ },
+  \ ale#command#GetData()
+
+Execute(ale#command#ManageDirectory should add the directory even if the buffer info hasn't been set yet):
+  call ale#command#ManageDirectory(bufnr(''), '/foo/bar')
+
+  AssertEqual
+  \ {
+  \   bufnr(''): {
+  \     'jobs': {},
+  \     'file_list': [],
+  \     'directory_list': ['/foo/bar'],
+  \   },
+  \ },
+  \ ale#command#GetData()