Hack #10. Run Tests from Within Vim
Run your tests from your editor.
One of the nice things about
Perl is the "tweak, run, tweak, run" development cycle. There's no separate compile phase to slow you down. However, you likely find yourself frequently writing tests and madly switching back and forth between the tests and the code. When you run the tests, you may exit the editor or type something like !perl -Ilib/ t/test_program.t in vi's command mode. This breaks the "tweak, run" rhythm.
The Hack
Perl programmers don't like to slow things down. Instead, consider binding keys in your editor to the chicken-bone voodoo you use to run your test suite.
Binding keys
By running the tests from within the editor, you no longer have to remember how to execute the tests or edit the editor. Just tweak and run. Add the following line to your .vimrc file to run the currently edited test file by typing ,t (comma, tee):
map ,t <Esc>:!prove -vl %<CR>
This technique uses the prove program to run your tests. prove is a handy little program distributed with and designed to run your tests through Test::Harness. The switches are v (vee), which tells prove to run in "verbose" mode and show all of the test output, and l (ell), which tells prove to add lib/ to @INC.
If lib/ is not where you typically do your development, use the I switch to add a different path to @INC.
map ,t <Esc>:!prove -Iwork/ -v %<CR>
Seeing failures
If it's a long test and you get a few failures, it can be difficult to see where the failures ...