Stories
Slash Boxes
Comments

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Tuesday April 29, 2008
05:19 PM

Vim: Auto-Edit Whatever Tests Cover Your Program

[ #36280 ]

This is rough and needs a lot of cleaning up, but first, install Johan Lindstrom's Devel::CoverX::Covered. Then go into some directory where you have a test directory and run this bash script (stolen straight from the docs):

#!/bin/bash

#Clean up from previous test run
cover -delete

#Test run with coverage instrumentation
PERL5OPT=-MDevel::Cover prove -r t

#Collect covered and caller information
#  Run this _before_ running "cover"
#  Don't run with Devel::Covered enabled
covered runs

#Post process to generate covered database
cover -report Html_basic

Then, somewhere in your .vimrc (or better yet, a plugin), you have something like this:

au! FileType perl          :call PerlMappings()
au! BufRead,BufNewFile *.t :call PerlTestMappings()

" if it's a .pm file and it's in the t/ directory, we hope
" it's a Test::Class test.  This is fragile :/

au! BufNewFile,BufRead *.pm
    \ if match(bufname('%'), '^t\>') > -1 |
    \     call PerlTestMappings()         |
    \ else                                |
    \     call PerlMappings()             |
    \ endif

function! PerlMappings()
    noremap <buffer> ,tc :call Coverage()<cr>
    noremap <buffer> K :!perldoc <cword> <bar><bar> perldoc -f <cword><cr>
endfunction

function! PerlTestMappings()
    noremap <buffer> ,t :!prove -vl %<CR>
endfunction

function! Coverage()
    let filename = bufname('%')

    if match(filename, '\.t$') > -1
        let command = 'covered by --test_file="'. filename .'"'
    else
        let command = 'covered covering --source_file="'. filename .'"'
    end

    let result  = split( system(command), "\n" )
    let list    = []
    let counter = 1
    for element in result
        let list = list + [ counter . ": " . element ]
        let counter = counter + 1
    endfor
    let file = inputlist(list)
    execute "edit " . result[ file - 1 ]
endfunction

Now, if you're in a Perl module or a test file, you can type ',tc' and get a list of the tests covering the module or modules the test covers. Select the number of the one you want to edit and you automatically edit it.

This needs a lot more work, including much better error checking, but I am happy with the start of this.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.