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

在perl测试中规划死亡

发布时间:2020-12-15 21:47:52 所属栏目:大数据 来源:网络整理
导读:参见英文答案 Is it possbile to test for expected errors when the testee exits with failure using TAP within Perl?3个 有没有办法为你期望死的Perl调用编写测试?我想验证某些调用会因格式错误的输入而死亡. sub routine_a { my $arg = shift; die if
参见英文答案 > Is it possbile to test for expected errors when the testee exits with failure using TAP within Perl?3个
有没有办法为你期望死的Perl调用编写测试?我想验证某些调用会因格式错误的输入而死亡.
sub routine_a {
   my $arg = shift;
   die if $arg eq 'FOO';
   print "routine_a: $argn";
}
sub routine_b {
   my $arg = shift;
   die if $arg eq 'BAR';
   print "routine_b: $argn";
}

sub test_all {
   assert( routine_a("blah") );
   assert( routine_b("blab") );
   assert_death( routine_a("FOO") );
   assert_death( routine_b("BAR") );
}

解决方法

见 Test::Exception:
use Test::Exception;
dies_ok { $foo->method } 'expecting to die';

(编辑:李大同)

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

    推荐文章
      热点阅读