Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Test driven development with Perl and vim

by dragonchild (Archbishop)
on Feb 28, 2005 at 20:43 UTC ( [id://435186]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Test driven development with Perl and vim
in thread Test driven development with Perl and vim

Actually, as I discovered after posting, it's a lot easier to write a Compile() function that you get to control (like adding -Ilib) than depending on vim's make. So, I took that out. Plus, I found a few things better than BufNewFile and BufRead.

This is how my .exrc snippet looks now:

autocmd BufNewFile,BufRead *.p? so ~/.vim/perltest.vim autocmd BufEnter *.p? colors peachpuff autocmd BufNewFile,BufRead *.t so ~/.vim/perltest.vim autocmd BufEnter *.t colors blue

And, I make a few changes to my perltest.vim

" perltest.vim - test driven development for Perl with vim " " ,t -- Run tests " ,w -- Set current file as test file. Only this test will run. " ,W -- Unset current test file. All tests will run. " " Updates at http://perlmonks.org/index.pl?node_id=434793 function! Prove ( verbose ) if ! exists("g:testfile") let g:testfile = "t/" endif if g:testfile == "t/" || g:testfile =~ "\.t$" if a:verbose echo system("prove -vl " . g:testfile . " 2>&1 | tee " . & +errorfile) else echo system("prove -l " . g:testfile . " 2>&1 | tee " . &e +rrorfile) endif else call Compile () endif cfile endfunction function! Compile () if ! exists("g:compilefile") let g:compilefile = expand("%") endif execute "!perl -wc -Ilib " . g:compilefile cfile endfunction nmap ,t :call Prove (0)<cr> nmap ,T :call Prove (1)<cr> nmap ,v :call Compile ()<cr> nmap ,w :let g:testfile = expand("%")<cr>:echo "testfile is now" g:t +estfile<cr> nmap ,W :unlet g:testfile<cr>:echo "testfile undefined; will run all t +ests"<cr> " based on compiler/perl.vim by Christian J. Robinson <infynity@onewes +t.net> " added formats for test failures set errorformat= \%-G%.%#had\ compilation\ errors., \%-G%.%#syntax\ OK, \%+Anot\ ok\%.%#-\ %m, \%C%.%#\(%f\ at\ line\ %l\), \%m\ at\ %f\ line\ %l., \%+A%.%#\ at\ %f\ line\ %l\\,%.%#, \%+C%.%# " FIXME make this more local. Needed for redirection syntax which isn' +t csh compatible set sh=/bin/sh " Just more convenient when shelling out a lot. set autowrite

The main changes are:

  • Addition of ,T allowing for make test TEST_VERBOSE=1
  • Addition of ,v allowing for compile of .t files. This entailed creating Compile()
  • Addition of -l flag to prove, keeping the vim editor in the same directory as the tags file.

I'm still figuring out the various parameters. Heck, I've learned more about the vim settings in the last hour than I had in the 10+ years I've been using vi-based editors! :-)

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^4: Test driven development with Perl and vim
by gaal (Parson) on Mar 01, 2005 at 19:37 UTC
    Good point about taint mode. And -l can't hurt either, so I'm adding it too, though in all my new projects I've stopped with the (h2xs-originated, I think) legacy of putting everything under lib/. Well, actually if it's a web project I *do* use lib/ (and htdocs/ etc); but otherwise it's just snappier to use the main directory as the root for libraries.

    I'm not sure why you need the separate binding for compilation at all? I actually see it as a feature that Prove() does the Right Thing depending on whether the file is a test or not. (After all, if your test fails compile, quickfix will put you in the right place even if the compilation error happened when you tried to run the test.) Think of it as polymorphism at keybinding time :)

    Thanks for the comments!

    Update: Interesting thinko on my part, taking "verbose" for "taint". Well, I suppose they both tend to produce mode output than the regular checks :) I'm not convinced a verbose launch deserves a keybinding of its own — how often do you alternate? — maybe it's better to make both taint and verbose modes global options and keep the keys simple.

      If a failed test occurs when using ",t" then I want to re-run that specific testfile using ",T" so that I can see the helpful messages I put into each ok() statement. In Excel::Template, for example, I have almost 200 tests over 24 files and hope to be at 500 over 50+ before all is said and done. Each test file generally has between 4 and 20 tests, which is a manageable amount of output. 200 isn't.

      Being right, does not endow the right to be rude; politeness costs nothing.
      Being unknowing, is not the same as being stupid.
      Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
      Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

        I guess we need something that sets TEST_VERBOSE=1 when a regular ,t produced failures (and maybe, if the ,w target was unset, set it to the failing testfile).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://435186]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-28 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found