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.
            Asked
            
        
        
            Active
            
        
            Viewed 687 times
        
    24
            
            
        - 
                    16I 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](http://cppunit.sourceforge.net/doc/lastest/class_plug_in_manager.html) which outputs TAP directly rather than doing a conversion. – Schwern Feb 13 '12 at 00:06
- 
                    1You should look at TAP::Harness::JUnit, its code may help you write the reverse converter (which doesn't seem to exist). – Nowhere man Oct 08 '12 at 21:40
1 Answers
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
 
    
    
        mvp
        
- 111,019
- 13
- 122
- 148
 
    