如何在Perl';中声明后使用参数'tests';s测试::更多?

如何在Perl';中声明后使用参数'tests';s测试::更多?,perl,testing,Perl,Testing,从perldoc-f使用 函数的语法使用: use Module VERSION LIST use Module VERSION use Module LIST use Module use VERSION 但在这种情况下: use Test::More tests => 5; (它将测试数量设置为5) expresiontests=>5的数据类型是什么? 是单子还是别的什么 声明后如何使用此参数测试?是的,这是所提到的列表,=>只是一种奇特的书写方式:

perldoc-f使用

函数的语法
使用

   use Module VERSION LIST
   use Module VERSION
   use Module LIST
   use Module
   use VERSION
但在这种情况下:

use Test::More tests => 5;
(它将测试数量设置为5)

expresion
tests=>5的数据类型是什么?
是单子还是别的什么


声明后如何使用此参数
测试

是的,这是所提到的
列表
=>
只是一种奇特的书写方式:

use Test::More ("tests", 5);
加载模块后,依次调用
Test::More->import(“tests”,5)

您可以要求将其生成器对象提供给您:

use Test::More tests => 5;

my $plan = Test::More->builder->has_plan;

print "I'm going to run $plan tests\n";
您不必将测试的数量设置为文字。您可以计算它并将其存储在变量中:

use vars qw($tests);

BEGIN { $tests = ... some calculation ... }
use Test::More tests => $tests;

print "I'm going to run $tests tests\n";
不过,您不必提前宣布计划:

use Test::More;

my $tests = 5;
plan( tests => $tests );

print "I'm going to run $tests tests\n";
你问过跳过测试。如果要跳过所有测试,可以使用
skip_all
而不是
tests

use Test::More;

$condition = 1;

plan( $condition ? ( skip_all => "Some message" ) : ( tests => 4 ) );

pass() for 1 .. 5;
当您希望将测试分为多个组时,也可以这样做。您计算出每个组中的测试数量,并将其相加以创建计划。稍后您将知道要跳过多少:

use Test::More;

my( $passes, $fails ) = ( 3, 5 );
my( $skip_passes, $skip_fails ) = ( 0, 1 );

plan( tests => $passes + $fails );

SKIP: {
    skip "Skipping passes", $passes if $skip_passes;
    pass() for 1 .. $passes;
    }

SKIP: {
    skip "Skipping fails", $fails if $skip_fails;
    fail() for 1 .. $fails;
    }

谢谢,我可以在模块外获取此参数吗?我想在函数skip(skip$why,$how_many)中使用它,我认为您不能直接使用它,但为什么不直接使用“use Test::More”,然后稍后调用“plan()”?这样,您就可以在脚本的一个变量中存储测试的数量了?@oraz:您可以使用
$tests=Test::Builder->new->has_plan
--查看文档以获取计划的测试数量。但是如果你想得到这个值以便知道要跳过多少,你应该调用
skip\u all