Skip to content
Permalink
Browse files

vim: Call `cargo test` to run unit tests found in the current file

  • Loading branch information...
Jorge Aparicio
Jorge Aparicio committed Sep 1, 2014
1 parent efd436c commit 2c3a93247549d9d77ede79775d0f312fa00b5373
Showing with 24 additions and 2 deletions.
  1. +24 −2 .vimrc
26 .vimrc
@@ -165,9 +165,31 @@ nnoremap <leader>md :call VimuxRunCommand("clear && make doc")<cr>
nnoremap <leader>mt :call VimuxRunCommand("clear && make test")<cr>
nnoremap <leader>x :VimuxPromptCommand<cr>

nnoremap <leader>kb :call VimuxRunCommand("clear && cargo build")<cr>
" Run unit tests found in the current file
" (Assumes that there is a `mod test` somewhere in the current file)
" If editing foo/bar/baz.rs, call `cargo test foo::bar::baz::test`
function CargoModTest()
python << endpython
import itertools
import os.path
import subprocess
import vim

path = os.path.splitext(vim.current.buffer.name)[0]
mod = '::'.join(filter(lambda x: x != "mod", reversed(list(itertools.takewhile(lambda x: x != 'src', reversed(path.split('/')))))))

if mod == 'lib':
vim.command('call VimuxRunCommand("clear && cargo test")')
else:
vim.command('call VimuxRunCommand("clear && cargo test ^{}::test")'.format(mod))

endpython
endfunction

nnoremap <leader>kt :call CargoModTest()<cr>
nnoremap <leader>ka :call VimuxRunCommand("clear && cargo build")<cr>
nnoremap <leader>kb :call VimuxRunCommand("clear && cargo bench")<cr>
nnoremap <leader>kd :call VimuxRunCommand("clear && cargo doc")<cr>
nnoremap <leader>kt :call VimuxRunCommand("clear && cargo test")<cr>
nnoremap <leader>ku :call VimuxRunCommand("clear && cargo update")<cr>
"}}}

0 comments on commit 2c3a932

Please sign in to comment.
You can’t perform that action at this time.