当我尝试和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
的目录