加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 21:23:05 所属栏目:大数据 来源:网络整理
导读:我寻求一个perl模块将CppUnit输出转换为TAP格式。我想使用prove命令后来运行和检查测试。 解决方法 最近我做一些转换从junit xml(不是到TAP格式)。 这是很容易做到使用XML :: Twig模块。 你的代码应该看起来像这样: use XML::Twig;my %hash;my $twig = XML:
我寻求一个perl模块将CppUnit输出转换为TAP格式。我想使用prove命令后来运行和检查测试。

解决方法

最近我做一些转换从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
     # ...
}

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读