About Kent Cowgill
Articles filed under...
abs ab_ripper andylester arms back baggyshorts bestpractices biceps bike birthday blog bugs bus calculator cardio catalyst cgi chart chest chinups code cpan datamodel dbi doctor documentation exercise exhaustion fitness flattire flat_tire google gps heart_rate helmet history home houston html humor journal kate kenpo kenpo_x kettlebell knees lazy legs lisa lisanne maps math matthew michaelmckenna mom montreal motivation movie mysql oops orm P90X pain park patellar_tendonitis patrick perl phb photos physical_therapy plyometrics poor_gait presentation procrastination progress pullups pushups pyramid rabbits racecondition rant refactor rest ribs ride route running shoulders situps slides sore spike sql statistics syntax test testing textile timex training triceps ups versioncontrol video vim vimrc walk warren work workouts yapc yapcna2007 yoga youtube

A R C H I V E S

(3)
(2)
(7)
(15)
(16)
(25)
(3)
(4)
(2)
(4)
(11)
(1)
(1)
(3)
(2)
(2)
(10)
(5)
(2)
(3)
(4)
(9)
(21)
(3)
(3)
(1)
(6)
(4)
(1)
(4)
(3)
(2)
(1)


    Is Kent Cowgill Online?
    View Kent Cowgill's profile on LinkedIn
    Add to Technorati Favorites

    Recent Entries...

    Vibram FiveFingers FTW

    I picked up a pair of Vibram FiveFingers shoes today, and th...

    It's Clobbering Time!

    I'm putting my time off to good use. Last week I pulled d...

    Re: Re: Merry P90X-mas!

    Hi Dan! Actually if I recall correctly, I started feeling...

    Updates on their way

    It hasn't been too many posts since I've had to apologize fo...

    Re: Merry P90X-mas!

    Wow, another Perl programmer doing "P90X":http://wiki.dandas...

    Merry P90X-mas!

    So much to write, so little time. Having trouble remember...

    Still here, still working

    Yes, I'm still here. No, I haven't fallen off the face of...

    Catching up through week 7

    So it seems that nearly every time I write about what I plan...

    Motivation, or lack thereof

    Thursday, Friday, Saturday, Sunday - all a whole lot of noth...

    On track so far...

    The week is about half way over, and so far I haven't skippe...

    Testing and Documenting Legacy Code

    Kent Cowgill

    &qidYou may have guessed by now, but I've taken up a particularly onerous gauntlet at my job. I'm afraid to touch any modules. But holy cow, do they need touching.

    What do we learn from Refactoring: Improving the Design of Existing Code ? Well, we learn that without tests, you can't refactor. Well, you can - it's really not wise to do so, however. It will be difficult to know if you've broken something or slightly altered a particular functionality.

    Of course, tests also help you prove what you've got is a set of modules that performs to their specifications - or in the absense of a specification - proving that the code does what it looks like it's supposed to do based on certain circumstance.

    Given that our codebase is huge, undocumented, and more important untested, I've come up with a few snippets of shell code to really move me pretty far forward with my task.

    First, to create a directory hierarchy to house all my new tests:

    
    for i in $(find . -name "*.pm")
      do touch $(echo $i | \
               sed -e 's/\./\/path\/to\/dir/' | \
               sed -e 's/\.pm$/.t/')
    done
    
    
    

    And to give the files some default content (it's ugly but it sorta works, YMMV):

    
    for i in $(find . -size 0)
      do echo '#!/usr/bin/perl' >> $i
        echo "" >> $i
        echo "use strict;" >> $i
        echo "use warnings;" >> $i
        echo "" >> $i
        echo "Test::More 'no_plan';" >> $i
        echo "" >> $i
        echo "use_ok( '`sed -e 's/\//::/' | \
          sed -e 's/\.t//'`' );" >> $i
      done
    
    
    

    These snippets, plus my previously mentioned vim tip are really getting me pretty fair along in creating a comprehensive test suite and a good set of documentation for all of our legacy code.

    Oh, and as a side benefit, I'm getting to know the modules pretty well while I'm at it :)

    Main Page | Login

    Do you want to buy me ? Find more gift ideas at my wishlist