2007-08-12 00:50:25 +00:00
#!/usr/bin/perl
package output::plain ;
use Exporter ;
@ ISA = qw( Exporter ) ;
use strict ;
2007-12-20 15:54:05 +01:00
sub new ($$$$$$) {
my ( $ class , $ summaryfile , $ verbose , $ immediate , $ statistics , $ totaltests ) = @ _ ;
2007-08-12 00:50:25 +00:00
my $ self = {
verbose = > $ verbose ,
immediate = > $ immediate ,
statistics = > $ statistics ,
test_output = > { } ,
2007-10-26 23:28:36 +02:00
suitesfailed = > [] ,
skips = > { } ,
summaryfile = > $ summaryfile ,
2007-12-20 15:54:05 +01:00
index = > 0 ,
totalsuites = > $ totaltests ,
2007-08-12 00:50:25 +00:00
} ;
bless ( $ self , $ class ) ;
}
sub output_msg ($$$) ;
2007-10-26 21:25:43 +02:00
sub start_testsuite ($$$)
2007-08-12 00:50:25 +00:00
{
2007-10-26 21:25:43 +02:00
my ( $ self , $ name , $ state ) = @ _ ;
2007-08-12 00:50:25 +00:00
2007-12-20 15:54:05 +01:00
$ self - > { index } + + ;
$ state - > { NAME } = $ name ;
$ state - > { START_TIME } = time ( ) ;
2007-08-12 00:50:25 +00:00
my $ duration = $ state - > { START_TIME } - $ self - > { statistics } - > { START_TIME } ;
2007-10-26 21:25:43 +02:00
$ self - > { test_output } - > { $ name } = "" unless ( $ self - > { verbose } ) ;
2007-08-12 00:50:25 +00:00
2007-12-20 15:54:02 +01:00
my $ out = "" ;
2007-12-20 15:54:05 +01:00
$ out . = "[$self->{index}/$self->{totalsuites} in " . $ duration . "s" ;
2007-12-20 15:54:02 +01:00
$ out . = sprintf ( ", %d errors" , $ self - > { statistics } - > { SUITES_FAIL } ) if ( $ self - > { statistics } - > { SUITES_FAIL } > 0 ) ;
$ out . = "] $name\n" ,
print "$out" ;
2007-08-12 00:50:25 +00:00
}
sub output_msg ($$$)
{
my ( $ self , $ state , $ output ) = @ _ ;
if ( $ self - > { verbose } ) {
print $ output ;
} else {
$ self - > { test_output } - > { $ state - > { NAME } } . = $ output ;
}
}
2007-08-26 19:07:46 +00:00
sub control_msg ($$$)
{
my ( $ self , $ state , $ output ) = @ _ ;
$ self - > output_msg ( $ state , $ output ) ;
}
2007-10-26 21:25:43 +02:00
sub end_testsuite ($$$$$$)
2007-08-12 00:50:25 +00:00
{
2007-12-20 15:54:02 +01:00
my ( $ self , $ name , $ state , $ result , $ unexpected , $ reason ) = @ _ ;
2007-08-12 00:50:25 +00:00
my $ out = "" ;
2007-12-20 15:54:02 +01:00
if ( $ unexpected ) {
$ self - > output_msg ( $ state , "ERROR: $reason\n" ) ;
2007-08-12 00:50:25 +00:00
}
2007-12-20 15:54:02 +01:00
if ( $ unexpected and $ self - > { immediate } and not $ self - > { verbose } ) {
2007-10-26 21:25:43 +02:00
$ out . = $ self - > { test_output } - > { $ name } ;
2007-12-11 14:24:20 +01:00
push ( @ { $ self - > { suitesfailed } } , $ name ) ;
2007-08-12 00:50:25 +00:00
}
print $ out ;
}
2007-12-20 15:54:02 +01:00
sub start_test ($$$$)
2007-08-12 00:50:25 +00:00
{
2007-12-20 15:54:02 +01:00
my ( $ self , $ state , $ parents , $ testname ) = @ _ ;
if ( $#$ parents == - 1 ) {
$ self - > start_testsuite ( $ testname , $ state ) ;
}
2007-08-12 00:50:25 +00:00
}
2007-09-08 14:12:45 +00:00
sub end_test ($$$$$$)
2007-08-12 00:50:25 +00:00
{
2007-12-20 15:54:02 +01:00
my ( $ self , $ state , $ parents , $ testname , $ result , $ unexpected , $ reason ) = @ _ ;
if ( $#$ parents == - 1 ) {
$ self - > end_testsuite ( $ testname , $ state , $ result , $ unexpected , $ reason ) ;
return ;
}
2007-10-02 15:53:26 +00:00
my $ append = "" ;
2007-09-08 14:12:45 +00:00
2007-10-02 15:53:26 +00:00
unless ( $ unexpected ) {
$ self - > { test_output } - > { $ state - > { NAME } } = "" ;
return ;
}
$ append = "UNEXPECTED($result): $testname\n" ;
$ self - > { test_output } - > { $ state - > { NAME } } . = $ append ;
if ( $ self - > { immediate } and not $ self - > { verbose } ) {
print $ self - > { test_output } - > { $ state - > { NAME } } ;
$ self - > { test_output } - > { $ state - > { NAME } } = "" ;
2007-09-08 14:12:45 +00:00
}
2007-08-12 00:50:25 +00:00
}
sub summary ($)
{
my ( $ self ) = @ _ ;
2007-10-26 23:28:36 +02:00
open ( SUMMARY , ">$self->{summaryfile}" ) ;
if ( $# { $ self - > { suitesfailed } } > - 1 ) {
print SUMMARY "= Failed tests =\n" ;
2007-12-11 14:24:20 +01:00
foreach ( @ { $ self - > { suitesfailed } } ) {
print SUMMARY "== $_ ==\n" ;
print SUMMARY $ self - > { test_output } - > { $ _ } . "\n\n" ;
}
print SUMMARY "\n" ;
2007-10-26 23:28:36 +02:00
}
2007-08-12 00:50:25 +00:00
if ( not $ self - > { immediate } and not $ self - > { verbose } ) {
foreach ( @ { $ self - > { suitesfailed } } ) {
print "===============================================================================\n" ;
print "FAIL: $_\n" ;
print $ self - > { test_output } - > { $ _ } ;
print "\n" ;
}
}
2007-10-26 23:28:36 +02:00
print SUMMARY "= Skipped tests =\n" ;
foreach my $ reason ( keys % { $ self - > { skips } } ) {
print SUMMARY "$reason\n" ;
foreach my $ name ( @ { $ self - > { skips } - > { $ reason } } ) {
print SUMMARY "\t$name\n" ;
}
print SUMMARY "\n" ;
}
close ( SUMMARY ) ;
2007-10-27 10:00:44 +02:00
print "\nA summary with detailed informations can be found in:\n $self->{summaryfile}\n" ;
if ( $ self - > { statistics } - > { SUITES_FAIL } == 0 ) {
my $ ok = $ self - > { statistics } - > { TESTS_EXPECTED_OK } +
$ self - > { statistics } - > { TESTS_EXPECTED_FAIL } ;
print "\nALL OK ($ok tests in $self->{statistics}->{SUITES_OK} testsuites)\n" ;
} else {
print "\nFAILED ($self->{statistics}->{TESTS_UNEXPECTED_FAIL} failures and $self->{statistics}->{TESTS_ERROR} errors in $self->{statistics}->{SUITES_FAIL} testsuites)\n" ;
}
2007-08-12 00:50:25 +00:00
}
2007-10-26 21:15:04 +02:00
sub skip_testsuite ($$)
2007-08-12 00:50:25 +00:00
{
2007-10-26 21:15:04 +02:00
my ( $ self , $ name , $ reason ) = @ _ ;
2007-08-12 04:00:15 +00:00
2007-10-26 23:28:36 +02:00
push ( @ { $ self - > { skips } - > { $ reason } } , $ name ) ;
2007-12-20 15:54:05 +01:00
$ self - > { totalsuites } - - ;
2007-08-12 04:00:15 +00:00
}
2007-08-12 00:50:25 +00:00
1 ;