Category: | testing |
Author/Contact Info | Adrian Howard |
Description: | Quick and dirty test runner for perl that only reports test failures and unexpectedly succeeding todo tests. Update: typo fixed, thanks tlm. Update: fixed is_expected_test_result, thanks tomhukins |
#!/usr/bin/perl use strict; use warnings; use Test::Harness::Straps; use IPC::Run3; my $strap = Test::Harness::Straps->new(); show_failures( $_ ) for @ARGV; sub show_failures { my $file = shift; my $result = test_result( $file ); show_details( $result ) unless is_expected( $result ); } sub test_result { my $file = shift; return { file => $file, $strap->analyze( $file, collect_stderr_and_stdout( $file ) ) }; } sub is_expected { my $result = shift; return $result->{ passing } && $result->{ bonus } == 0; }; sub show_details { my $result = shift; print "$result->{file}\n", map { "* $_->{name}\n" . diagnostics( $_ ) } grep { ! is_expected_test_result( $_ ) } @{ $result->{ det +ails } }; } sub is_expected_test_result { my $test_result = shift; return $test_result->{ok} && ! is_unexpected_todo_success( $test_result ) && ! diagnostics( $_ ); } sub diagnostics { my $test_result = shift; return $test_result->{ diagnostics } if $test_result->{ diagnostic +s }; return " unexpected success from TODO test\n" if is_unexpected_todo_success( $test_result ); return ''; } sub is_unexpected_todo_success { my $test_result = shift; return $test_result->{type} eq "todo" && $test_result->{actual_ok} } sub collect_stderr_and_stdout { my $file = shift; my $command = [ $strap->_command, $strap->_switches( $file ) || () +, $file ]; my $output = []; run3( $command, \undef, $output, $output ) || die "run3: $!\n"; return $output; } |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Quiet test runner
by tomhukins (Curate) on Sep 21, 2005 at 15:22 UTC | |
by adrianh (Chancellor) on Sep 22, 2005 at 07:49 UTC |