gpt4 book ai didi

Perl 测试 - 得到编译警告但测试仍然顽固地表明一切正常

转载 作者:行者123 更新时间:2023-11-28 20:04:11 24 4
gpt4 key购买 nike

我在运行测试时得到了这个,但如您所见,两个测试仍然显示正常。我一点都不喜欢这个。如何将警告变成错误?

1..2
Allowing a native trait to automatically supply a default is deprecated. You can avoid this warning by supplying a default, builder, or making the attribute required at UserInfo.pm line 7
require UserInfo.pm called at (eval 4) line 2
main::BEGIN() called at UserInfo.pm line 0
eval {...} called at UserInfo.pm line 0
eval 'package main;
use UserInfo @{$args[0]};
1;

;' called at /packages/run.64/perl-5.14.1/lib/5.14.1/Test/More.pm line 885
Test::More::_eval('package main;\x{a}use UserInfo @{$args[0]};\x{a}1;\x{a}', 'ARRAY(0x16fa110)') called at /packages/run.64/perl-5.14.1/lib/5.14.1/Test/More.pm line 860
Test::More::use_ok('UserInfo') called at UserInfo.t line 7
ok 1 - use UserInfo;
ok 2 - require UserInfo;

最佳答案

将警告变成错误?给你!

use warnings FATAL=>"all";

如果你想让脚本不只是死掉,而是让特定的测试失败,你可以在上面添加:

use Test::Exception; 

# later
lives_and {
is ($this->value, 42);
} "Value is 42 (and no warnings)";

参见 Test::Exception .

另一种方式(正如我在下面的评论中所述)是定义一个警告伪信号处理程序:

my @warn;
$SIG{__WARN__} = sub { push @warn, shift; };

# later
ok (!@warn, "No warnings were emitted");

关于Perl 测试 - 得到编译警告但测试仍然顽固地表明一切正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7010302/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com