无法检测 'factorial' 的来源。为什么?

Cannot detect source of 'factorial'. Why?

当我尝试 prove factorial:

时,我得到了以下回溯
Cannot detect source of 'factorial'! at /usr/share/perl/5.18/TAP/Parser/IteratorFactory.pm line 263.
    TAP::Parser::IteratorFactory::detect_source('TAP::Parser::IteratorFactory=HASH(0x2856b08)', 'TAP::Parser::Source=HASH(0x2856bc8)') called at /usr/share/perl/5.18/TAP/Parser/IteratorFactory.pm line 213
    TAP::Parser::IteratorFactory::make_iterator('TAP::Parser::IteratorFactory=HASH(0x2856b08)', 'TAP::Parser::Source=HASH(0x2856bc8)') called at /usr/share/perl/5.18/TAP/Parser.pm line 469
    TAP::Parser::_initialize('TAP::Parser=HASH(0x28569e8)', 'HASH(0x23d8cb8)') called at /usr/share/perl/5.18/TAP/Object.pm line 58
    TAP::Object::new('TAP::Parser', 'HASH(0x23d8cb8)') called at /usr/share/perl/5.18/TAP/Object.pm line 133
    TAP::Object::_construct('TAP::Harness=HASH(0x2131db8)', 'TAP::Parser', 'HASH(0x23d8cb8)') called at /usr/share/perl/5.18/TAP/Harness.pm line 779
    TAP::Harness::make_parser('TAP::Harness=HASH(0x2131db8)', 'TAP::Parser::Scheduler::Job=HASH(0x28235d0)') called at /usr/share/perl/5.18/TAP/Harness.pm line 578
    TAP::Harness::_aggregate_single('TAP::Harness=HASH(0x2131db8)', 'TAP::Parser::Aggregator=HASH(0x2740ae0)', 'TAP::Parser::Scheduler=HASH(0x2823570)') called at /usr/share/perl/5.18/TAP/Harness.pm line 670
    TAP::Harness::aggregate_tests('TAP::Harness=HASH(0x2131db8)', 'TAP::Parser::Aggregator=HASH(0x2740ae0)', 'factorial') called at /usr/share/perl/5.18/TAP/Harness.pm line 485
    TAP::Harness::__ANON__() called at /usr/share/perl/5.18/TAP/Harness.pm line 498
    TAP::Harness::runtests('TAP::Harness=HASH(0x2131db8)', 'factorial') called at /usr/share/perl/5.18/App/Prove.pm line 554
    App::Prove::_runtests('App::Prove=HASH(0x2120170)', 'HASH(0x2606428)', 'TAP::Harness', 'factorial') called at /usr/share/perl/5.18/App/Prove.pm line 512
    App::Prove::run('App::Prove=HASH(0x2120170)') called at /usr/bin/prove line 11

这是我的 factorial.pm:

package factorial;

use Exporter qw(import);

BEGIN {
    our @EXPORT_OK  = qw(factorial);
}

sub factorial
{
    my ($parm) = @_;

    my $factorial = 1;

    if ($parm == 0)
    {
        return $factorial;
    }

    foreach my $i (1..$parm) {
        $factorial *= $i;
    }

    return $factorial;
}

1;

还有我的factorial.t

#!/usr/bin/perl -w
use Test::More;

use factorial 'factorial';
is(factorial(0), 1, "boundary case");
is(factorial(1), 1, "factorial(1)");
is(factorial(2), 2, "factorial(2)");
is(factorial(6), 720, "factorial(6)");

done_testing;

我验证了我的 factorial 模块由 运行 这个程序工作(或者,至少,正确地做了一件事)。

#!/usr/bin/perl -w

use factorial 'factorial';

my $parm = 5;
print "Factorial($parm) = ", factorial($parm), "\n";

prove 的手册页声明它接受选项和文件或目录:

prove [options] [files or directories]

它不会为您做任何名称扩展。

你给了 prove 参数 factorial,而我怀疑你的测试文件名为 factorial.t

以下 prove 命令应该都是有效的:

prove factorial.t
prove fac*
prove <directory that contains factorial.t>

注意:最后两个命令可能 运行不止一个测试取决于工作目录的内容,或者你传递给的目录prove