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)

Thursday June 21, 2007
04:17 AM

Awesome Test::Class vim mapping

[ #33567 ]

In Test::Class, there is a terribly clunky way to tell it to run only one test (I can call it clunky because I submitted the patch for it). The way to do this is to create a TEST_METHOD environment variable:

package Tests::Customer;

use base 'My::Test::Class';

sub foo : Tests(12) {
    ...
}

sub bar : Tests {
    ...
}

sub baz : Tests(111) {
    ...
}

BEGIN { $ENV{TEST_METHOD} = 'quux' }
sub quux : Tests(no_plan) {
    ...
}

With the above, you will only have the 'quux' method run. This is very handy when you're focusing on a specific method and don't want to run your other long-running tests until you're done working on 'quux'. With the help of smylers (he really is a vim god, you know), I now have the following vim mapping:

noremap ,tm ?^sub.*:.*Test<cr>w"zyeOBEGIN { $ENV{TEST_METHOD} = '<c-r>z' }<esc>

It's a bit of a hack, but here's what it does. When you type ',tm', it does:

?^sub.*:.*Test<cr>
Search backwards until I find a test subroutine.
w"zye
Move to the next word (w) and yank to the end of the next word into the contents of the 'z' buffer.
OBEGIN { $ENV{TEST_METHOD} = 'z' }<esc>
Open a new line above the current one and create the BEGIN block, writing the contents of the 'z' buffer as the TEST_METHOD variable.

In other words, position your cursor in a method, type ',tm' while in command mode and it will try to create insert code which will only run the test method you're currently in. This really speeds up my testing!

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.
  • fun! TestClassRunThisMethod()
        let save_cursor=getpos('.')
        let SAVE_TEST_METHOD=$TEST_METHOD

        call search('^sub \+\zs.*:.*Test','bcW')
        let $TEST_METHOD = expand('<cword>')
        exe '!printenv | sort'

        let $TEST_METHOD=SAVE_TEST_METHOD
        call setpos('.', save_cursor)
    endfun

    nnoremap <expr> ,tm TestClassRunThisMethod()