Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

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)

Friday October 10, 2008
10:29 AM

Vim: Run All Tests Which Cover This Module

[ #37639 ]

Update: Rufus Cable has written a vim syntax file for TAP, along with some other useful bindings. I think I'll put this together with my stuff and get around to that plugin.

It's trivial to set up vim mappings to run the current test program you're editing. I also wrote recently about how to run all tests in your vim buffers. Today, I'll explain a great technique to run all tests for the module you're currently editing.

First, grab Johan Lindstrom's Devel::CoverX::Covered. Once you have that set up and working, you can use something like this to your .vimrc (when, oh when, am I going to create a proper plugin for all of this and add it to github?):

function! PerlMappings()
    " run the code
    noremap <buffer> <leader>r :!perl %<cr>

    " or check that it compiles
    noremap <buffer> <leader>r :!perl -c %<cr>

    " or run tall of the tests for it
    noremap <buffer> <leader>t :call TestModuleCoverage()<cr>
endfunction

function! PerlTestMappings()
    noremap <buffer> <leader>r :!prove -vl %<cr>

    " or check that it compiles
    noremap <buffer> <leader>r :!perl -c %<cr>

    noremap <buffer> <leader>t :!prove -vl %<CR>
endfunction

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

    let tests = system('covered covering --source_file="'. filename .'"')

    let result  = split( tests, "\n" )

    if empty(result)
        echomsg "No tests found for: ". filename
    else
        execute ':!prove  ' . join(result)
    endif
endfunction

Then, if you're in a test file and hit ",t" (assuming that the comma is your leader), then you'll run the test. If you're in a regular Perl program or module, hitting ",t" will run all tests which cover that program or module.

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.