Which Tests Cover This Code? :)

Ovid on 2008-04-02T08:37:02

Johan Lindstrom's Devel::CoverX::Covered is still relatively new, but here are some changes to my .vimrc based on this (stripped down for clarity):

function! PerlMappings()
    noremap  ,cv :call Coverage()
    noremap K :!perldoc   perldoc -f 
endfunction

function! PerlTestMappings()
    noremap  ,t :!prove -vl --norc %
endfunction

function! Coverage()
    let filename = bufname('%')
    if match(filename, '\.t$') > -1
        execute '!covered by --test_file="'. filename .'"'
    else
        execute '!covered covering --source_file="'. filename .'"'
    end
endfunction

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

When I am editing lib/Bermuda.pm and I type ,cv, I get this:

t/basic.t
t/bermuda.t
t/exceptions.t
t/serialize.t
t/subelements.t
t/xml.t

And if I'm editing t/basic.t and I type ,cv, I get this:

lib/Bermuda.pm
lib/Bermuda/Island.pm
lib/Bermuda/Island/Attribute.pm
lib/Bermuda/Island/Element.pm
lib/Bermuda/Island/Metadata.pm
lib/Bermuda/Parser.pm
lib/Bermuda/RNG.pm
lib/Bermuda/Writer.pm

In other words, know what tests will cover your code and vice versa. Johan has more features on the way, including being able to know which tests cover a particular line of a file.

Already I need to update my Oslo talk :)