I've been looking at some changes to our shell scripts lately, changes that require a fair bit of work to set up the test environment. So I wrote a quick shell script that would blow away the old stuff, re-extract the original files, symlink into my build environment appropriately (the files I'm working on), just to get to a pristine state easily.

And then I have a bunch of tests to run, and check. So there was some command line trickery to get stuff repeating the way I wanted. And now I have to move to a new platform to test it all again. The setup script should be close to what I need, but, of course the stuff I typed at the command line needs to be rewritten on the new machine since I can't just go back into the history there. Maybe some cut&paste, but as the commands are 200+ characters long, it's a pain.

One of the tests was running the same command on each file, looking for stuff. It started out as:

ls I/{some,dirs}/ | xargs -n 1 -t I/foo/bar -q 2>&1 | sed -e 's/stuffT +oRemove//' -e '/linesToIgnore/d' | less

This wasn't enough - too much to wade through. So it eventually became:

find I -type f | perl -nle 'open my $fh, "I/foo/bar -q $_ |" or next; +chomp(my $l = <$fh>); $l =~ s/stuffToRemove//; my $count =()= $l =~ / +stuffToCount/g; print "$_:$count[$l]" if $count > 2'

Eventually. Figuring there had to be an easier way to get this done, I started lamenting to myself about being able to do a "make test" like I do with my CPAN'd modules. A bit of digging showed that this just runs "prove" - which looks like I could just write a few .t scripts and test stuff that doesn't even have anything to do with perl. Some File::Find for the above line, maybe a subroutine wrapper around qx so as to clean up the output for proper "is" testing...

So, my question becomes not whether anyone has gone down this road before, as I'm sure some have (I might be smart (or at least, I think so ;-}), but not that smart), but what gotchas, if any, did that experience teach you? Things to keep in mind as I go down this road. I much prefer learning from other people's mistakes before being forced to learn from my own :-)

Right now, I'm doing this on Linux, AIX, probably Sun and HP. I may want to do this on Windows, eventually, too, since shell scripting is so much harder there ;-)

Update: Zaxo kinda hits on the reason behind the problem: I would like to not only prove that this works (actually, just some sort of unit test environment) so that I can try to push our team towards some sort of standardisation on unit testing. And maybe porting TAP clients to C to test our libraries, etc., would be a good idea ... but this is just kind of like the start of a push to show its usefulness in at least some aspects of what we do. Preferably without reinventing the wheel. Perl strikes me as the way to move things, but I've gotta prove prove to my team, and it's faster to do that based on others' experience than try to discover the gotchas (and cool, neat features) myself ;-)


In reply to proving something other than perl by Tanktalus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.