I never really understood the point of prove ; I write my tests as normal Perl programs, launchable from the command line. perl t/testname.t does most of what I want to do.
With more than 24 tests in a file, though, I often promised myself to write or find someday a variant test harness that ignored successes and reported only failures or an all clear message.
I looked at the code of prove today to find where to add it, but again, it doesn't seem to do anything I really need and there was no way to add it. I moved on to Test::Harness::Straps. I don't know if anyone's ever actually used this module (and it's admittedly a bit of a mess inside, though the long-promised Test::Builder refactoring may make it easier to write), but it took 67 lines of code to do what I needed (and a little more) in a well-factored way.
I call it qtest:
#!/usr/bin/perl
use strict;
use warnings;
use Test::Harness::Straps;
my $strap = Test::Harness::Straps->new();
for my $file (@ARGV)
{
next unless -f $file;
my %results = $strap->analyze_file( $file );
if ($results{passing})
{
report( sprintf('All (%d) tests passed in %s', $results{seen}, $file));
}
elsif ($results{skip_all})
{
report( sprintf('All (%d) tests skipped in %s', $results{seen}, $file));
}
else
{
report( find_failures( $file, \%results ) );
}
}
sub report
{
my $message = shift;
print "$message\n";
}
sub find_failures
{
my ($file, $results) = @_;
my $report = create_header($file, @{$results}{qw( max seen ok )});
my $count = 0;
for my $test ( @{ $results->{details} } )
{
$count++;
next if $test->{ok};
$report.= create_test_result( $count, @{ $test }{qw( name reason ) } );
}
return $report;
}
sub create_header
{
my ($file, $expected, $seen, $passed) = @_;
my $failed = $seen - $passed;
return sprintf "File '%s'\nExpected %d / Seen %d / Okay %d / Failed %d\n",
@_, $failed;
}
sub create_test_result
{
my ($number, $name, $reason) = @_;
$name =~ s/^-\s*//;
$reason ||= '';
$reason = " ($reason)" if $reason;
return sprintf "\tTest #%d: %s%s\n", $number, $name, $reason;
}
In practice, I may tweak the formatting somewhat. It might be nice to report skips and surprisingly-passing TODO tests, too. I also might want a flag to end after the first failure, to solve the problem of cascading failures rolling off of the screen. Still, this was a lot simpler than I thought and already makes my life easier.
The Point of Prove (Score:2)
prove was based on a program that I wrote a long time ago to manage my tests better. I sent that off to Andy and it got warped into prove. Unfortunately, the one thing that I miss that I had code which would allow me to run sets of tests, based upon patterns on the command line. Thus, when working on stuff that touched "products", I might run a particular test program, or I might run all test programs with "prod" in the name. When I was done, I'd run the full test suite. It was very handy. Now I don'
Re:The Point of Prove (Score:1)
I don't understand why you need
proveto run sets of tests, unless it's for the nice summary at the end, which does seem like an advantage.(I just realized that that may be what you like as I started to type "my shell expands patterns just fine, so I don't need another program to do it for me". I think that's the conceptual part I didn't understand.)
Re:The Point of Prove (Score:1)
My entire test suite takes about 30 seconds (dual 2.8 GHz Xeon system)... and growing (since I only have about 10 percent coverage on three years of programming). That is long enough to get me out of the zone if I have to do it too much.
So... I run prove, the setup routines, and the particular tests I'm focusing on. The setup routines take about 5 seconds and the individual tests run in about 2 seconds. Which, is short enough not to take me off task (
Re:The Point of Prove (Score:2)
--
xoa
Test::Verbose (Score:2)
It's a shame that Test::Verbose is greatly overlooked. I find it absolutely indispensable.
Re:Test::Verbose (Score:1)
You're right, that is pretty close to what I want. I've just sent Barrie a patch to add Module::Build support.
Thanks for the pointer.
I don't understand your dislike of "prove" (Score:2)
It's also a lot easier than typing the equivalent
which I also had used in some of my early docs on testing. Thank goodness we hide
Re:I don't understand your dislike of "prove" (Score:2)