Skip to content

Instantly share code, notes, and snippets.

@rerorero
Last active July 24, 2020 03:12
Show Gist options
  • Save rerorero/016ba3c142d03c186481820f47db0b4a to your computer and use it in GitHub Desktop.
Save rerorero/016ba3c142d03c186481820f47db0b4a to your computer and use it in GitHub Desktop.
gotestfunc.vim
command GoUnitTest call s:go_unit_test()
function! s:go_unit_test() abort
let l:test = search('func \(Test\|Example\)', "bcnW")
if l:test == 0
echo "no test found"
return
end
" run via termnial (neoterm)
let l:line = getline(l:test)
let l:name = split(split(l:line, " ")[1], "(")[0]
let l:filepath = expand('%:p:h')
let l:cmd = ':T go test -run ' . l:name . '$ ' . l:filepath . ' -v -count 1'
exe l:cmd
exe ':Ttoggle'
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment