24
我尋求一個perl模塊將CppUnit輸出轉換爲TAP格式。之後我想使用證明命令運行並檢查測試。CppUnit輸出到TAP格式轉換器
我尋求一個perl模塊將CppUnit輸出轉換爲TAP格式。之後我想使用證明命令運行並檢查測試。CppUnit輸出到TAP格式轉換器
最近我做了一些從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
# ...
}
這應該是比較容易打磨到工作狀態
我不知道的東西,但CppUnit的似乎是使用JUnit XML輸出。您可能會有更多的運氣尋找JUnit-to-TAP轉換器。否則,最好的辦法可能是編寫一個[CppUnit插件](http://cppunit.sourceforge.net/doc/lastest/class_plug_in_manager.html),它直接輸出TAP,而不是進行轉換。 – Schwern 2012-02-13 00:06:12
你應該看看TAP :: Harness :: JUnit,它的代碼可以幫助你寫出逆向轉換器(這似乎不存在)。 – 2012-10-08 21:40:34