Skip to content

Commit 67cc1a8

Browse files
committed
refactor ClangFormat() test function
1 parent 1bc0240 commit 67cc1a8

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

t/clang_format_spec.vim

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,23 @@ function! GetBuffer()
3535
endfunction
3636

3737
function! ClangFormat(line1, line2, ...)
38-
let opt = printf(" -lines=%d:%d -style='{BasedOnStyle: Google, IndentWidth: %d, UseTab: %s}' ", a:line1, a:line2, &l:shiftwidth, &l:expandtab==1 ? "false" : "true")
39-
let file = a:0 == 0 ? 'test.cpp' : a:1
40-
let cmd = g:clang_format#command.opt.'./'.s:root_dir.'t/' . file . ' --'
38+
let opt = printf("-lines=%d:%d -style='{BasedOnStyle: Google, IndentWidth: %d, UseTab: %s", a:line1, a:line2, &l:shiftwidth, &l:expandtab==1 ? "false" : "true")
39+
let file = 'test.cpp'
40+
41+
for a in a:000
42+
if a =~# '^test\.\w\+$'
43+
let file = a
44+
else
45+
let opt .= a
46+
endif
47+
endfor
48+
let opt .= "}'"
49+
50+
let cmd = printf('%s %s ./%st/%s --', g:clang_format#command, opt, s:root_dir, file)
51+
let result = Chomp(system(cmd))
52+
if v:shell_error
53+
throw "Error on system(): clang-format exited with non-zero.\nCommand: " . cmd . "\nOutput: " . result
54+
endif
4155
return Chomp(system(cmd))
4256
endfunction
4357
"}}}

0 commit comments

Comments
 (0)