首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Perl Carp:承认单元测试

Perl Carp:承认单元测试
EN

Stack Overflow用户
提问于 2015-11-19 08:07:59
回答 1查看 298关注 0票数 2

我正在尝试编写一个perl单元测试。我能够为它测试最好的情况。但是,如果在该方法中生成了错误,它将使用Carp:confess "<message>"打印错误。我不能在我的测试中捕捉到这个案例。我试着用

dies_ok( <method call>, 'Expected Error' );

然而,测试用例仍然失败。它打印传递给Carp::confess的消息,然后打印

Looks like your test exited with 111 before it could output anything. Dubious, test returned 111 (wstat 28416, 0x6f00)

有什么办法能让我染上这个病吗?我甚至尝试过throws_ok,但不起作用。

请指导我如何捕捉这些错误。我是否错误地使用了这些dies_okthrows_ok

EN

回答 1

Stack Overflow用户

发布于 2015-11-20 00:13:50

你可以在eval表达式后检查$@。

代码语言:javascript
复制
use strict;
use warnings;

use Test::More;

use Carp qw(confess);

sub err { confess('Bad thing'); }

eval { err };
like($@, qr/^Bad thing/, "confess('Bad thing')");

done_testing();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33792965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档