perl – CppUnit输出到TAP格式转换器

前端之家收集整理的这篇文章主要介绍了perl – CppUnit输出到TAP格式转换器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我寻求一个perl模块将CppUnit输出转换为TAP格式。我想使用prove命令后来运行和检查测试。

解决方法

最近我做一些转换从junit xml(不是到TAP格式)。
这是很容易做到使用XML :: Twig模块。
你的代码应该看起来像这样:
  1. use XML::Twig;
  2.  
  3. my %hash;
  4.  
  5. my $twig = XML::Twig->new(
  6. twig_handlers => {
  7. testcase => sub { # this gets called per each testcase in XML
  8. my ($t,$e) = @_;
  9. my $testcase = $e->att("name");
  10. my $error = $e->field("error") || $e->field("failure");
  11. my $ok = defined $error ? "not ok" : "ok";
  12. # you may want to collect
  13. # testcase name,result,error message,etc into hash
  14. $hash{$testcase}{result} = $ok;
  15. $hash{$testcase}{error} = $error;
  16. # ...
  17. }
  18. }
  19. );
  20. $twig->parsefile("test.xml");
  21. $twig->purge();
  22.  
  23. # Now XML processing is done,print hash out in TAP format:
  24. print "1..",scalar(keys(%hash)),"\n";
  25. foreach my $testcase (keys %hash) {
  26. # print out testcase result using info from hash
  27. # don't forget to add leading space for errors
  28. # ...
  29. }

这应该比较容易抛光成工作状态

猜你在找的Perl相关文章