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.
2 silent! cd /testplugin/test
3 silent file top/middle/bottom/dummy.txt
5 function! CheckTempFile(filename) abort
6 " Check every part of the temporary filename, except the random part.
7 AssertEqual fnamemodify(tempname(), ':h'), fnamemodify(a:filename, ':h:h')
8 AssertEqual 'dummy.txt', fnamemodify(a:filename, ':t')
11 runtime autoload/ale/command.vim
13 function! ale#command#CreateTempFile(buffer, temporary_file, input) abort
14 return !empty(a:temporary_file)
21 delfunction CheckTempFile
23 runtime autoload/ale/command.vim
25 Execute(FormatCommand should do nothing to basic command strings):
27 \ ['', 'awesome-linter do something', 0],
28 \ ale#command#FormatCommand(bufnr('%'), '', 'awesome-linter do something', 0, v:null, v:null, [])
30 Execute(FormatCommand should handle %%, and ignore other percents):
32 \ ['', '% %%d %%f %x %', 0],
33 \ ale#command#FormatCommand(bufnr('%'), '', '%% %%%d %%%f %x %', 0, v:null, v:null, [])
35 Execute(FormatCommand should convert %s to the current filename):
39 \ 'foo ' . ale#Escape(expand('%:p')) . ' bar ' . ale#Escape(expand('%:p')),
42 \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s bar %s', 0, v:null, v:null, [])
44 Execute(FormatCommand should convert %t to a new temporary filename):
45 let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, v:null, v:null, [])
47 call CheckTempFile(g:result[0])
49 let g:match = matchlist(g:result[1], '\v^foo (.*) bar (.*)$')
51 Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
52 " The first item of the result should be a temporary filename, and it should
53 " be the same as the escaped name in the command string.
54 AssertEqual ale#Escape(g:result[0]), g:match[1]
55 " The two temporary filenames formatted in should be the same.
56 AssertEqual g:match[1], g:match[2]
58 Execute(FormatCommand should not convert %t to a new temporary filename when the input is given as v:false):
59 let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, v:false, v:null, [])
61 AssertEqual ['', 'foo %t bar %t', 0], g:result
63 Execute(FormatCommand should signal that files are created when temporary files are needed):
66 \ ale#command#FormatCommand(bufnr('%'), '', 'foo %t', 0, v:null, v:null, [])[2]
70 \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s', 0, v:null, v:null, [])[2]
72 Execute(FormatCommand should let you combine %s and %t):
73 let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %s', 0, v:null, v:null, [])
75 call CheckTempFile(g:result[0])
77 let g:match = matchlist(g:result[1], '\v^foo (.*) bar (.*)$')
79 Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
80 " The first item of the result should be a temporary filename, and it should
81 " be the same as the escaped name in the command string.
82 AssertEqual ale#Escape(g:result[0]), g:match[1]
83 " The second item should be equal to the original filename.
84 AssertEqual ale#Escape(expand('%:p')), g:match[2]
86 Execute(FormatCommand should replace %e with the escaped executable):
90 \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, v:null, v:null, [])
92 \ ['', '"foo bar"', 0],
93 \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, v:null, v:null, [])
96 \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, v:null, v:null, [])
99 \ ['', '''foo'' ''foo''', 0],
100 \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, v:null, v:null, [])
102 \ ['', '''foo bar''', 0],
103 \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, v:null, v:null, [])
106 \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, v:null, v:null, [])
109 Execute(EscapeCommandPart should escape all percent signs):
110 AssertEqual '%%s %%t %%%% %%s %%t %%%%', ale#engine#EscapeCommandPart('%s %t %% %s %t %%')
112 Execute(EscapeCommandPart should pipe in temporary files appropriately):
113 let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar', 1, v:null, v:null, [])
115 call CheckTempFile(g:result[0])
117 let g:match = matchlist(g:result[1], '\v^foo bar \< (.*)$')
118 Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
119 AssertEqual ale#Escape(g:result[0]), g:match[1]
121 let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar %t', 1, v:null, v:null, [])
123 call CheckTempFile(g:result[0])
125 let g:match = matchlist(g:result[1], '\v^foo bar (.*)$')
126 Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
127 AssertEqual ale#Escape(g:result[0]), g:match[1]
129 Execute(FormatCommand should apply filename modifiers to the current file):
131 \ ale#Escape(expand('%:p:h'))
132 \ . ' ' . ale#Escape('dummy.txt')
133 \ . ' ' . ale#Escape(expand('%:p:h:t'))
134 \ . ' ' . ale#Escape('txt')
135 \ . ' ' . ale#Escape(expand('%:p:r')),
136 \ ale#command#FormatCommand(bufnr(''), '', '%s:h %s:t %s:h:t %s:e %s:r', 0, v:null, v:null, [])[1]
138 Execute(FormatCommand should apply filename modifiers to the temporary file):
139 let g:result = ale#command#FormatCommand(bufnr(''), '', '%t:h %t:t %t:h:t %t:e %t:r', 0, v:null, v:null, [])
142 \ ale#Escape(fnamemodify(g:result[0], ':h'))
143 \ . ' ' . ale#Escape('dummy.txt')
144 \ . ' ' . ale#Escape(fnamemodify(g:result[0], ':h:t'))
145 \ . ' ' . ale#Escape('txt')
146 \ . ' ' . ale#Escape(fnamemodify(g:result[0], ':r')),
149 Execute(FormatCommand should apply filename mappings the current file):
150 let g:result = ale#command#FormatCommand(bufnr('%'), '', '%s', 0, v:null, v:null, [
151 \ [expand('%:p:h'), '/foo/bar'],
154 Assert g:result[1] =~# '/foo/bar'
156 Execute(FormatCommand should apply filename mappings to temporary files):
157 let g:result = ale#command#FormatCommand(bufnr('%'), '', '%t', 0, v:null, v:null, [
158 \ [fnamemodify(tempname(), ':h:h'), '/foo/bar']
161 Assert g:result[1] =~# '/foo/bar'
163 Execute(FormatCommand should apply filename modifiers to mapped filenames):
164 let g:result = ale#command#FormatCommand(bufnr('%'), '', '%s:h', 0, v:null, v:null, [
165 \ [expand('%:p:h'), '/foo/bar'],
168 AssertEqual ale#Escape('/foo/bar'), g:result[1]
170 let g:result = ale#command#FormatCommand(bufnr('%'), '', '%t:h:h:h', 0, v:null, v:null, [
171 \ [fnamemodify(tempname(), ':h:h'), '/foo/bar']
174 AssertEqual ale#Escape('/foo/bar'), g:result[1]
176 Execute(FormatCommand should apply regular cwd paths):
178 \ 'cd ' . (has('unix') ? '' : '/d ') . ale#Escape('/foo /bar') . ' && abc',
179 \ ale#command#FormatCommand(bufnr('%'), '', 'abc', 0, v:null, '/foo /bar', [])[1]
181 Execute(FormatCommand should apply cwd substitution and formatting):
182 call ale#test#SetFilename('foo.txt')
185 \ 'cd ' . (has('unix') ? '' : '/d ') . ale#Escape(getcwd()) . ' && abc',
186 \ ale#command#FormatCommand(bufnr('%'), '', 'abc', 0, v:null, '%s:h', [])[1]