2007-08-12 00:50:25 +00:00
#!/usr/bin/perl
package output::plain ;
use Exporter ;
@ ISA = qw( Exporter ) ;
2007-12-20 17:07:21 +01:00
use FindBin qw( $RealBin ) ;
use lib "$RealBin/.." ;
use Subunit qw( parse_results ) ;
2007-08-12 00:50:25 +00:00
use strict ;
2007-12-20 15:54:08 +01:00
sub new ($$$$$$$) {
2007-12-20 15:54:05 +01:00
my ( $ class , $ summaryfile , $ verbose , $ immediate , $ statistics , $ totaltests ) = @ _ ;
2007-08-12 00:50:25 +00:00
my $ self = {
verbose = > $ verbose ,
immediate = > $ immediate ,
statistics = > $ statistics ,
2007-12-20 15:54:08 +01:00
start_time = > time ( ) ,
2007-08-12 00:50:25 +00:00
test_output = > { } ,
2007-10-26 23:28:36 +02:00
suitesfailed = > [] ,
2007-12-20 15:54:08 +01:00
suites_ok = > 0 ,
2007-10-26 23:28:36 +02:00
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 ) ;
}
2007-12-20 17:07:21 +01:00
sub output_msg ($$) ;
2007-08-12 00:50:25 +00:00
2007-12-20 17:07:21 +01:00
sub start_testsuite ($$)
2007-08-12 00:50:25 +00:00
{
2007-12-20 17:07:21 +01:00
my ( $ self , $ name ) = @ _ ;
2007-08-12 00:50:25 +00:00
2007-12-20 15:54:05 +01:00
$ self - > { index } + + ;
2007-12-20 17:07:21 +01:00
$ self - > { NAME } = $ name ;
$ self - > { START_TIME } = time ( ) ;
2007-12-20 15:54:05 +01:00
2007-12-20 17:07:21 +01:00
my $ duration = $ self - > { START_TIME } - $ self - > { start_time } ;
2007-08-12 00:50:25 +00:00
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:08 +01:00
$ out . = sprintf ( ", %d errors" , ( $# { $ self - > { suitesfailed } } + 1 ) ) if ( $# { $ self - > { suitesfailed } } > - 1 ) ;
2008-02-18 21:52:23 +01:00
$ out . = "] $name" ;
if ( $ self - > { immediate } ) {
print "$out\n" ;
} else {
require Term::ReadKey ;
my ( $ wchar , $ hchar , $ wpixels , $ hpixels ) = Term::ReadKey:: GetTerminalSize ( ) ;
foreach ( 1 .. $ wchar ) { $ out . = " " ; }
print "\r" . substr ( $ out , 0 , $ wchar ) ;
}
2007-08-12 00:50:25 +00:00
}
2007-12-20 17:07:21 +01:00
sub output_msg ($$)
2007-08-12 00:50:25 +00:00
{
2007-12-20 17:07:21 +01:00
my ( $ self , $ output ) = @ _ ;
2007-08-12 00:50:25 +00:00
if ( $ self - > { verbose } ) {
print $ output ;
} else {
2007-12-20 17:07:21 +01:00
$ self - > { test_output } - > { $ self - > { NAME } } . = $ output ;
2007-08-12 00:50:25 +00:00
}
}
2007-12-20 17:07:21 +01:00
sub control_msg ($$)
2007-08-26 19:07:46 +00:00
{
2007-12-20 17:07:21 +01:00
my ( $ self , $ output ) = @ _ ;
2007-08-26 19:07:46 +00:00
2007-12-20 17:07:21 +01:00
$ self - > output_msg ( $ output ) ;
2007-08-26 19:07:46 +00:00
}
2007-12-20 17:07:21 +01:00
sub end_testsuite ($$$$$)
2007-08-12 00:50:25 +00:00
{
2007-12-20 17:07:21 +01:00
my ( $ self , $ name , $ result , $ unexpected , $ reason ) = @ _ ;
2007-08-12 00:50:25 +00:00
my $ out = "" ;
2007-12-20 15:54:02 +01:00
if ( $ unexpected ) {
2007-12-20 17:07:21 +01:00
$ self - > output_msg ( "ERROR: $reason\n" ) ;
2007-12-20 15:54:08 +01:00
push ( @ { $ self - > { suitesfailed } } , $ name ) ;
} else {
$ self - > { suites_ok } + + ;
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-08-12 00:50:25 +00:00
}
2007-12-20 15:54:08 +01:00
2007-08-12 00:50:25 +00:00
print $ out ;
}
2007-12-20 17:07:21 +01:00
sub start_test ($$$)
2007-08-12 00:50:25 +00:00
{
2007-12-20 17:07:21 +01:00
my ( $ self , $ parents , $ testname ) = @ _ ;
2007-12-20 15:54:02 +01:00
if ( $#$ parents == - 1 ) {
2007-12-20 17:07:21 +01:00
$ self - > start_testsuite ( $ testname ) ;
2007-12-20 15:54:02 +01:00
}
2007-08-12 00:50:25 +00:00
}
2007-12-20 17:07:21 +01:00
sub end_test ($$$$$)
2007-08-12 00:50:25 +00:00
{
2007-12-20 17:07:21 +01:00
my ( $ self , $ parents , $ testname , $ result , $ unexpected , $ reason ) = @ _ ;
2007-12-20 15:54:02 +01:00
if ( $#$ parents == - 1 ) {
2007-12-20 17:07:21 +01:00
$ self - > end_testsuite ( $ testname , $ result , $ unexpected , $ reason ) ;
2007-12-20 15:54:02 +01:00
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 ) {
2007-12-20 17:07:21 +01:00
$ self - > { test_output } - > { $ self - > { NAME } } = "" ;
2007-10-02 15:53:26 +00:00
return ;
}
$ append = "UNEXPECTED($result): $testname\n" ;
2007-12-20 17:07:21 +01:00
$ self - > { test_output } - > { $ self - > { NAME } } . = $ append ;
2007-10-02 15:53:26 +00:00
if ( $ self - > { immediate } and not $ self - > { verbose } ) {
2007-12-20 17:07:21 +01:00
print $ self - > { test_output } - > { $ self - > { NAME } } ;
$ self - > { test_output } - > { $ self - > { 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" ;
2007-12-20 15:54:08 +01:00
if ( $# { $ self - > { suitesfailed } } == - 1 ) {
2007-10-27 10:00:44 +02:00
my $ ok = $ self - > { statistics } - > { TESTS_EXPECTED_OK } +
$ self - > { statistics } - > { TESTS_EXPECTED_FAIL } ;
2007-12-20 15:54:08 +01:00
print "\nALL OK ($ok tests in $self->{suites_ok} testsuites)\n" ;
2007-10-27 10:00:44 +02:00
} else {
2007-12-20 15:54:08 +01:00
print "\nFAILED ($self->{statistics}->{TESTS_UNEXPECTED_FAIL} failures and $self->{statistics}->{TESTS_ERROR} errors in " . ( $# { $ self - > { suitesfailed } } + 1 ) . " testsuites)\n" ;
2007-10-27 10:00:44 +02:00
}
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 ;