Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a69df96

Browse files
committed
Merge pull request #8 from google/tests
Fix vroom tests to not depend on executables installed on host
2 parents 2770e52 + 4789353 commit a69df96

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

‎autoload/codefmt.vim‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,23 @@ if !exists('s:gofmt')
157157
endif
158158

159159

160+
""
161+
" Checks whether {formatter} is available.
162+
" NOTE: If @function(#DisableIsAvailableChecksForTesting) has been called, skips
163+
" the IsAvailable check and always returns true.
164+
function! s:IsAvailable(formatter) abort
165+
if get(s:, 'check_formatters_available', 1)
166+
return a:formatter.IsAvailable()
167+
endif
168+
return 1
169+
endfunction
170+
171+
160172
""
161173
" Detects whether a formatter has been defined for the current buffer/filetype.
162174
function! codefmt#IsFormatterAvailable() abort
163175
let l:formatters = copy(codefmtlib#GetFormatters())
164-
let l:is_available = 'v:val.AppliesToBuffer() && v:val.IsAvailable()'
176+
let l:is_available = 'v:val.AppliesToBuffer() && s:IsAvailable(v:val)'
165177
return !empty(filter(l:formatters, l:is_available)) ||
166178
\ !empty(get(b:, 'codefmt_formatter'))
167179
endfunction
@@ -187,7 +199,7 @@ function! s:GetFormatter(...) abort
187199
return
188200
endif
189201
let l:formatter = l:selected_formatters[0]
190-
if !l:formatter.IsAvailable()
202+
if !s:IsAvailable(l:formatter)
191203
" Not available. Print setup instructions if possible.
192204
let l:error = 'Formatter "%s" is not available.'
193205
if has_key(l:formatter, 'setup_instructions')
@@ -199,7 +211,7 @@ function! s:GetFormatter(...) abort
199211
else
200212
" No explicit name, use default.
201213
let l:default_formatters = filter(
202-
\ copy(l:formatters), 'v:val.AppliesToBuffer() && v:val.IsAvailable()')
214+
\ copy(l:formatters), 'v:val.AppliesToBuffer() && s:IsAvailable(v:val)')
203215
if !empty(l:default_formatters)
204216
let l:formatter = l:default_formatters[0]
205217
else
@@ -272,15 +284,15 @@ endfunction
272284
" @public
273285
" Suitable for use as 'operatorfunc'; see |g@| for details.
274286
" The type is ignored since formatting only works on complete lines.
275-
function! codefmt#FormatMap(type) range
287+
function! codefmt#FormatMap(type) rangeabort
276288
call codefmt#FormatLines(line("'["), line("']"))
277289
endfunction
278290

279291
""
280292
" Generate the completion for supported formatters. Lists available formatters
281293
" that apply to the current buffer first, then unavailable formatters that
282294
" apply, then everything else.
283-
function! codefmt#GetSupportedFormatters(ArgLead, CmdLine, CursorPos)
295+
function! codefmt#GetSupportedFormatters(ArgLead, CmdLine, CursorPos)abort
284296
let l:groups = [[], [], []]
285297
for l:formatter in codefmtlib#GetFormatters()
286298
let l:key = l:formatter.AppliesToBuffer() ? (
@@ -290,3 +302,11 @@ function! codefmt#GetSupportedFormatters(ArgLead, CmdLine, CursorPos)
290302
return join(l:groups[0] + l:groups[1] + l:groups[2], "\n")
291303
endfunction
292304

305+
306+
""
307+
" @private
308+
" Bypasses FORMATTER.IsAvailable checks and assumes every formatter is available
309+
" to avoid checking for executables on the path.
310+
function! codefmt#DisableIsAvailableChecksForTesting() abort
311+
let s:check_formatters_available = 0
312+
endfunction

‎vroom/autocmd.vroom‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
Install dependencies and setup maktaba:
22

3+
:set nocompatible
34
:let g:repo = fnamemodify($VROOMFILE, ':p:h:h')
45
:execute 'source' g:repo . '/bootstrap.vim'
56
:call maktaba#syscall#SetUsableShellRegex('\v<shell\.vroomfaker$')
67
:filetype plugin on
78

9+
We'll stub out codefmt to not care whether certain executables are installed on
10+
your system.
11+
12+
:call codefmt#DisableIsAvailableChecksForTesting()
13+
14+
815
You can use the AutoFormatBuffer command to enable automatic code formatting
916
when you save a file with a given filetype.
1017

‎vroom/main.vroom‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ stub that out for vroom.
1818
:endfunction
1919
:call maktaba#test#Override('repeat#set', 'FakeRepeat')
2020

21+
We'll also stub it out to not care whether certain executables are installed on
22+
your system.
23+
24+
:call codefmt#DisableIsAvailableChecksForTesting()
25+
2126

2227
This plugin defines a :FormatCode command that can be used to reformat buffers.
2328
It can format C++ code using clang-format.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /