]> git.madduck.net Git - etc/vim.git/blob - .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 '294584081929424aec883f90c7d6515b3743358d' as '.vim/bundle/vim-lsp-ale'
[etc/vim.git] / .vim / bundle / ale / test / test_temporary_file_management.vader
1 Before:
2   Save g:ale_buffer_info
3
4   let g:ale_buffer_info = {}
5   let g:ale_run_synchronously = 1
6
7   let g:command = 'echo test'
8   let g:filename = ''
9   let g:directory = ''
10   let g:preserved_directory = ''
11
12   function! TestCommandCallback(buffer) abort
13     " We are registering a temporary file, so we should delete it.
14     let g:filename = tempname()
15     call writefile(['foo'], g:filename)
16     call ale#command#ManageFile(a:buffer, g:filename)
17
18     " We are registering this directory appropriately, so we should delete
19     " the whole thing.
20     let g:directory = tempname()
21     call mkdir(g:directory)
22     call writefile(['foo'], g:directory . '/bar')
23     call ale#command#ManageDirectory(a:buffer, g:directory)
24
25     " We are registering this directory as temporary file, so we
26     " shouldn't delete it.
27     let g:preserved_directory = tempname()
28     call mkdir(g:preserved_directory)
29     call writefile(['foo'], g:preserved_directory . '/bar')
30     call ale#command#ManageFile(a:buffer, g:preserved_directory)
31
32     return g:command
33   endfunction
34
35   function! TestCallback(buffer, output) abort
36     return []
37   endfunction
38
39   call ale#linter#Define('foobar', {
40   \ 'name': 'testlinter',
41   \ 'executable': has('win32') ? 'cmd' : 'echo',
42   \ 'callback': 'TestCallback',
43   \ 'command': function('TestCommandCallback'),
44   \})
45   call ale#command#ClearData()
46
47 After:
48   Restore
49
50   if !empty(g:preserved_directory)
51     call delete(g:preserved_directory, 'rf')
52   endif
53
54   unlet! g:ale_run_synchronously
55   unlet! g:command
56   unlet! g:filename
57   unlet! g:directory
58   unlet! g:preserved_directory
59   delfunction TestCommandCallback
60   delfunction TestCallback
61   call ale#linter#Reset()
62   call ale#command#ClearData()
63
64 Given foobar (Some imaginary filetype):
65   foo
66   bar
67   baz
68
69 Execute(ALE should delete managed files/directories appropriately after linting):
70   AssertEqual 'foobar', &filetype
71
72   call ale#Queue(0)
73   call ale#test#FlushJobs()
74
75   Assert !filereadable(g:filename), 'The temporary file was not deleted'
76   Assert !isdirectory(g:directory), 'The temporary directory was not deleted'
77   Assert isdirectory(g:preserved_directory), 'The temporary directory was not kept'
78
79 Execute(ALE should delete managed files even if no command is run):
80   AssertEqual 'foobar', &filetype
81
82   let g:command = ''
83
84   call ale#Queue(0)
85   call ale#test#WaitForJobs(2000)
86
87   Assert !filereadable(g:filename), 'The temporary file was not deleted'
88   Assert !isdirectory(g:directory), 'The temporary directory was not deleted'
89   Assert isdirectory(g:preserved_directory), 'The temporary directory was not kept'
90
91 Execute(ALE should delete managed files when the buffer is removed):
92   call ale#engine#InitBufferInfo(bufnr('%'))
93   call TestCommandCallback(bufnr('%'))
94   call ale#engine#Cleanup(bufnr('%'))
95
96   Assert !filereadable(g:filename), 'The temporary file was not deleted'
97   Assert !isdirectory(g:directory), 'The temporary directory was not deleted'
98   Assert isdirectory(g:preserved_directory), 'The tempoary directory was not kept'
99
100 Execute(ALE should create and delete directories for ale#command#CreateDirectory()):
101   call ale#engine#InitBufferInfo(bufnr('%'))
102
103   let b:dir = ale#command#CreateDirectory(bufnr('%'))
104   let b:dir2 = ale#command#CreateDirectory(bufnr('%'))
105
106   Assert isdirectory(b:dir), 'The directory was not created'
107
108   " We should get the correct file permissions.
109   " We want to ensure that the directory is not readable by 'other'
110   if has('unix')
111     AssertEqual 'rwxr-x---', getfperm(b:dir)
112   endif
113
114   " The two directories shouldn't be the same.
115   AssertNotEqual b:dir2, b:dir
116
117   call ale#engine#Cleanup(bufnr('%'))
118
119   Assert !isdirectory(b:dir), 'The directory was not deleted'
120   Assert !isdirectory(b:dir2), 'The second directory was not deleted'
121
122 Execute(ale#command#ManageFile should add the file even if the buffer info hasn't been set yet):
123   call ale#command#ManageFile(bufnr(''), '/foo/bar')
124
125   AssertEqual
126   \ {
127   \   bufnr(''): {
128   \     'jobs': {},
129   \     'file_list': ['/foo/bar'],
130   \     'directory_list': [],
131   \   },
132   \ },
133   \ ale#command#GetData()
134
135 Execute(ale#command#ManageDirectory should add the directory even if the buffer info hasn't been set yet):
136   call ale#command#ManageDirectory(bufnr(''), '/foo/bar')
137
138   AssertEqual
139   \ {
140   \   bufnr(''): {
141   \     'jobs': {},
142   \     'file_list': [],
143   \     'directory_list': ['/foo/bar'],
144   \   },
145   \ },
146   \ ale#command#GetData()