Last active
March 29, 2016 14:38
-
-
Save ferki/ee6b6a9f64770d9cacf7 to your computer and use it in GitHub Desktop.
Run Perl test from vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" perltest.vim - test driven development for Perl with vim | |
" | |
" ,t -- Run tests | |
" ,w -- Set current file as test file. Only this test will run. | |
" ,W -- Unset current test file. All tests will run. | |
" | |
" v1.02 - Updates at http://perlmonks.org/index.pl?node_id=434793 | |
function! Prove ( verbose, silent ) | |
if ! exists("g:testfile") | |
let g:testfile = "t" | |
endif | |
if g:testfile == "t" || g:testfile =~ "\.t$" | |
let s:params = "l" | |
if a:verbose | |
let s:params = s:params . "v" | |
endif | |
let cmd = "!clear; prove -" . s:params . " " . g:testfile | |
if a:silent | |
silent execute cmd | |
else | |
execute cmd | |
endif | |
if v:shell_error == 0 | |
hi StatusLine ctermfg=darkgreen ctermbg=white guifg=green guibg=white | |
let g:tests_passed = 1 | |
else | |
hi StatusLine ctermfg=darkred ctermbg=white guifg=red guibg=white | |
let g:tests_passed = 0 | |
endif | |
redraw! | |
else | |
call Compile () | |
endif | |
endfunction | |
function! Compile () | |
if ! exists("g:compilefile") | |
let g:compilefile = expand("%") | |
endif | |
execute "!perl -wc -Ilib " . g:compilefile | |
endfunction | |
let g:tests_passed = -1 | |
set errorformat= | |
\%-G%.%#had\ compilation\ errors., | |
\%-G%.%#syntax\ OK, | |
\%+Anot\ ok\%.%#-\ %m, | |
\%C%.%#\(%f\ at\ line\ %l\), | |
\%m\ at\ %f\ line\ %l., | |
\%+A%.%#\ at\ %f\ line\ %l\\,%.%#, | |
\%+C%.%# | |
nmap ,t :call Prove (0,0)<cr> | |
nmap ,tv :call Prove (1,0)<cr> | |
nmap ,T :call Prove (0,1)<cr> | |
nmap ,c :call Compile ()<cr> | |
nmap ,w :let g:testfile = expand("%")<cr>:echo "testfile is now" g:testfile<cr> | |
nmap ,W :unlet g:testfile<cr>:echo "testfile undefined; will run all tests"<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment