Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CppUnit output to TAP format converter

Tags:

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.

like image 283
Oleg Razgulyaev Avatar asked Feb 12 '12 10:02

Oleg Razgulyaev


1 Answers

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

like image 67
mvp Avatar answered Oct 29 '22 19:10

mvp