24

CppUnitの出力をTAP形式に変換するperlモジュールを探しています。後でproveコマンドを使用して、テストを実行および確認したいと思います。

4

1 に答える 1

2

最近、私はjunit xmlから(ただしTAP形式ではなく)変換を行っていました。XML::Twigモジュールを使用することは非常に簡単でした。コードは次のようになります。

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
     # ...
}

これは、作業状態に磨き上げるのが比較的簡単なはずです

于 2012-10-18T06:03:21.390 に答える