Test2-Harness-Renderer-JUnit
view release on metacpan or search on metacpan
lib/Test2/Harness/Renderer/JUnit.pm view on Meta::CPAN
$test->{'testsuite'}->{'failures'}++;
$test->{'testsuite'}->{'errors'}++;
# Grab the first amnesty description that's a TODO message.
my ($todo_message) = map { $_->{'details'} } grep { $_->{'tag'} // '' eq 'TODO' } @{ $f->{'amnesty'} };
push @{ $test->{'testcase'} }, $self->xml->testcase(
{ 'name' => "$test_name (TODO)", 'time' => $run_time, 'classname' => $test->{'testsuite'}->{'name'} },
$self->xml->error(
{ 'message' => $todo_message, 'type' => "TodoTestSucceeded" },
$self->_cdata("ok $test_name")
)
);
}
}
elsif ( $f->{'assert'}->{'pass'} ) { # Passing test
push @{ $test->{'testcase'} }, $self->xml->testcase(
{ 'name' => $test_name, 'time' => $run_time, 'classname' => $test->{'testsuite'}->{'name'} },
""
);
lib/Test2/Harness/Renderer/JUnit.pm view on Meta::CPAN
# These are method calls but you can't do methods with a dash in them so we have to store them as a SV and call it.
my $out_method = 'system-out';
my $err_method = 'system-err';
print {$fh} "<testsuites>\n";
my @jobs = sort { $a->{'job_name'} <=> $b->{'job_name'} } values %{ $self->{'tests'} };
foreach my $job (@jobs) {
print {$fh} $xml->testsuite(
$job->{'testsuite'},
@{ $job->{'testcase'} },
$xml->$out_method( $self->_cdata( $job->{$out_method} ) ),
$xml->$err_method( $self->_cdata( $job->{$err_method} ) ),
) . "\n";
}
print {$fh} "</testsuites>\n";
close $fh;
return;
}
# Because we want to test diag messages after a failed test, we delay closing failures
lib/Test2/Harness/Renderer/JUnit.pm view on Meta::CPAN
{
$fail->{'message'}
.= "# WARNING This test number has already been seen. Duplicate TEST # in output!\n";
}
my $xml = $self->xml;
push @{ $test->{'testcase'} }, $xml->testcase(
{ 'name' => $fail->{'test_name'}, 'time' => $fail->{'time'}, 'classname' => $test->{'testsuite'}->{'name'} },
$xml->failure(
{ 'message' => $fail->{message}, 'type' => 'TestFailed' },
$self->_cdata( $fail->{'full_message'} ) )
);
delete $test->{'last_failure'};
return;
}
sub xml {
my $self = shift;
return $self->{'xml'};
}
lib/Test2/Harness/Renderer/JUnit.pm view on Meta::CPAN
# use in a Java class name.
sub _clean_to_java_class_name {
my $str = shift;
$str =~ s/[^-:_A-Za-z0-9]+/_/gs;
return $str;
}
###############################################################################
# Creates a CDATA block for the given data (which is made squeaky clean first,
# so that JUnit parsers like Hudson's don't choke).
sub _cdata {
my ( $self, $data ) = @_;
# When I first added this conditional, I returned $data and at one point it was returning ^A and breaking the xml parser.
return '' if ( !$data or $data !~ m/\S/ms );
return $self->xml->xmlcdata( _squeaky_clean($data) );
}
###############################################################################
# Clean a string to the point that JUnit can't possibly have a problem with it.
sub _squeaky_clean {
my $string = shift;
# control characters (except CR and LF)
$string =~ s/([\x00-\x09\x0b\x0c\x0e-\x1f])/"^".chr(ord($1)+64)/ge;
( run in 0.689 second using v1.01-cache-2.11-cpan-454fe037f31 )