我正在尝试编写一个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_ok和throws_ok?
发布于 2015-11-20 00:13:50
你可以在eval表达式后检查$@。
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();https://stackoverflow.com/questions/33792965
复制相似问题