selftest: Add option to strip output of succeeded tests, and use it on
[ira/wip.git] / selftest / Subunit / Filter.pm
index 3a9e4f9409535dc9386d489acb775073cf12b3e8..93b690df8ee7c5db4b1263480c3f8bb56a5e2918 100644 (file)
@@ -54,7 +54,11 @@ sub report_time($$)
 sub output_msg($$)
 {
        my ($self, $msg) = @_;
-       print $msg;
+       unless(defined($self->{output})) {
+               print $msg;
+       } else {
+               $self->{output}.=$msg;
+       }
 }
 
 sub start_test($$)
@@ -65,6 +69,10 @@ sub start_test($$)
                $testname = $self->{prefix}.$testname;
        }
 
+       if ($self->{strip_ok_output}) {
+               $self->{output} = "";
+       }
+
        Subunit::start_test($testname);
 }
 
@@ -76,30 +84,47 @@ sub end_test($$$$$)
                $testname = $self->{prefix}.$testname;
        }
 
-       if (($result eq "fail" or $result eq "failure") and not $unexpected) { $result = "xfail"; }
+       if (($result eq "fail" or $result eq "failure") and not $unexpected) {
+               $result = "xfail";
+               $self->{xfail_added}++;
+       }
        my $xfail_reason = find_in_list($self->{expected_failures}, $testname);
        if (defined($xfail_reason) and ($result eq "fail" or $result eq "failure")) {
                $result = "xfail";
+               $self->{xfail_added}++;
                $reason .= $xfail_reason;
        }
 
+       if ($self->{strip_ok_output}) {
+               unless ($result eq "success" or $result eq "xfail" or $result eq "skip") {
+                       print $self->{output}
+               }
+       }
+       $self->{output} = undef;
+
        Subunit::end_test($testname, $result, $reason);
 }
 
 sub skip_testsuite($;$)
 {
-       Subunit::skip_testsuite(@_);
+       my ($self, $name, $reason) = @_;
+       Subunit::skip_testsuite($name, $reason);
 }
 
 sub start_testsuite($;$)
 {
        my ($self, $name) = @_;
        Subunit::start_testsuite($name);
+       $self->{xfail_added} = 0;
 }
 
 sub end_testsuite($$;$)
 {
        my ($self, $name, $result, $reason) = @_;
+       if ($self->{xfail_added} and ($result eq "fail" or $result eq "failure")) {
+               $result = "xfail";
+       }
+               
        Subunit::end_testsuite($name, $result, $reason);
 }
 
@@ -110,11 +135,13 @@ sub testsuite_count($$)
 }
 
 sub new {
-       my ($class, $prefix, $expected_failures) = @_;
+       my ($class, $prefix, $expected_failures, $strip_ok_output) = @_;
 
        my $self = { 
                prefix => $prefix,
                expected_failures => $expected_failures,
+               strip_ok_output => $strip_ok_output,
+               xfail_added => 0,
        };
        bless($self, $class);
 }