CppUnit output to TAP format converter
Asked Answered
C

1

24

I seek a perl module to convert CppUnit output to TAP format. I want to use the prove command afterwards to run and check the tests.

Collier answered 12/2, 2012 at 10:28 Comment(2)
I don't know of anything, but CppUnit appears to be using JUnit XML output. You might have more luck looking for a JUnit-to-TAP converter. Otherwise your best bet might be to write a CppUnit plugin which outputs TAP directly rather than doing a conversion.Bodyguard
You should look at TAP::Harness::JUnit, its code may help you write the reverse converter (which doesn't seem to exist).Molina
T
2

Recently I was doing some converting from junit xml (not to TAP format though). It was very easy to do by using XML::Twig module. You code should look like this:

use XML::Twig;

my %hash;

my $twig = XML::Twig->new(
   twig_handlers => {
       testcase => sub { # this gets called per each testcase in XML
           my ($t, $e) = @_;
           my $testcase = $e->att("name");
           my $error = $e->field("error") || $e->field("failure");
           my $ok = defined $error ? "not ok" : "ok";
           # you may want to collect
           #   testcase name, result, error message, etc into hash
           $hash{$testcase}{result} = $ok;
           $hash{$testcase}{error}  = $error;
           # ...
       }
   }
);
$twig->parsefile("test.xml");
$twig->purge();

# Now XML processing is done, print hash out in TAP format:
print "1..", scalar(keys(%hash)), "\n";
foreach my $testcase (keys %hash) {
     # print out testcase result using info from hash
     # don't forget to add leading space for errors
     # ...
}

This should be relatively easy to polish into working state

Trista answered 18/10, 2012 at 6:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.