Stories
Slash Boxes
Comments

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)

Wednesday January 03, 2007
02:25 PM

runtests --recurse --exec 'some_prog %s' t/

[ #32063 ]

One of the features I'm working on for TAPx::Parser is the ability to test anything. Admittedly, this is a big attempt, but here's what I'm thinking. Imagine the following program:

#!/usr/bin/perl

use Test::HTML::Lint tests => 1;

my $file = shift;
open my $fh, '<', $file
  or die "Cannot open ($file) for reading: $!";
my $html = do { local $/; <$fh> };

html_ok( $html, "$file has valid HTML" );

Now that looks weird. Why would I want arguments to a test script? Well, name it test_html and you can do this ('extension' is deliberately misnamed):

runtests --recurse --exec 'test_hml %s' --xtension 'html?' www/

You've now turned all HTML files in your www/ directory into tests!

--exec is expected to take a sprintf format which will be opened with this:

my $fh      = gensym;
my $command = sprintf $exec, $arg;
if ( open $fh, "$command |" ) {
    return TAPx::Parser::Iterator->new($fh);
}
else {
    ...
}

So long as whatever you pass into --exec outputs TAP, you can test anything you want. In fact, it doesn't even have to be filenames. You could pass a list of urls to runtests and have your testing utility fetch them and run tests on them.

What I'm trying to figure out is how to easily handle a test suite with test programs written in Perl, C, etc. My current plans only allow one type of --exec at a time. Thoughts?

Update: I might just make the %s optional in the format and tack it on to the end if it's not in the string. I'd also disallow any other % sign in the format since that would screw up the sprintf.

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.
  • You might not want to use sprintf and the string form of pipe open. Think what happens when you get a file name containing spaces, or asterisks, or pipe characters, or anything else that's special to the shell (yes, I actually had such names: one of my applications used TT2 to generate documents, and the file names themselves were expanded by TT2, so I had names like [% customer.name | filename %] - [% orders.last_number | format('%04d') %].txt )

    I'd suggest doing what find's exec option does: gobble up al

  • Excuse my ignorance on what features you already have...

    Does this thing have URI support yet?

    Can I say "Go test that URL that will spit you back TAP" and have it work?
    • This feature is not yet ready but I'm already getting email asking for it so I need to see if I can get this out the door by this weekend at the latest. My biggest obstacle, actually, isn't getting this feature to work (it's fairly simple), but getting TAPx::Harness output as similar as possible to Test::Harness output. I don't want to suprise users too much by making the output radically different, but I also have so much more information I can present, if they users want it (such as which tests unexpect