“无法在 /usr/lib/perl5/5.18.2/Test/More.pm 第 1020 行对活动子项运行测试 (h_c: is_deeply($n, $s))”

问题描述 投票:0回答:1

尝试将一些代码从

use Test::more
转换为
use Test::Builder
我在尝试使用
is_deeply
(perl 5.18.2)时遇到了这个问题:

无法在 /usr/lib/perl5/5.18.2/Test/More.pm 第 1020 行对活动子项运行测试 (h_c: is_deeply($n, $s))

Test::Builder
的手册说明了
explain
的示例:

is_deeply($有, $想要) ||诊断解释 $have;

但是

Test::Builder
没有
is_deeply
方法,但
Test::More
有它(我使用
use Test::More 'import' => [qw(is_deeply)];
仅导入该方法)。 不幸的是,当尝试从子测试中使用它时(
$tb->child()
),程序终止并显示上面引用的消息。

有没有办法在子测试中使用

is_deeply

来自 Perl 调试器内的消息:

Cannot run test (h_c: is_deeply($n, $s)) with active children at /usr/lib/perl5/5.18.2/Test/More.pm line 1020.
 at /usr/lib/perl5/5.18.2/Test/Builder.pm line 1969.
        Test::Builder::croak('Test::Builder=HASH(0x1b6e3c0)', 'Cannot run test (h_c: is_deeply($n, $s)) with active children') called at /usr/lib/perl5/5.18.2/Test/Builder.pm line 769
        Test::Builder::ok('Test::Builder=HASH(0x1b6e3c0)', 1, 'h_c: is_deeply($n, $s)') called at /usr/lib/perl5/5.18.2/Test/More.pm line 1020
        Test::More::is_deeply('HOTP::Core=ARRAY(0x31131c8)', 'HOTP::Core=ARRAY(0x310ab10)', 'h_c: is_deeply($n, $s)') called at otptest.pl line 96

perl
1个回答
0
投票

以下内容似乎成功地在

is_deeply
套件中导入了
Test::Builder
。不过在 Perl 5.26 上进行了测试。

use strict;
use warnings;
use Test::Builder;
use Test::More import => [qw(is_deeply)];

my $t = Test::Builder->new;

my $data = [{ a => 'b'}];

$t->subtest(
    'Import is_deeply only',
    \&test_me,
    $data,
);

$t->done_testing();

sub test_me {
        my $args = shift;
        my $expected = { a => 'b'};
        is_deeply $args->[0], $expected, 'I can use Test::More::is_deeply';
}

1;

© www.soinside.com 2019 - 2024. All rights reserved.