How can I use the `tests` parameter after the declaration in Perl Test :: More?

from perldoc -f use
function syntax use:

   use Module VERSION LIST
   use Module VERSION
   use Module LIST
   use Module
   use VERSION

but in this case:

use Test::More tests => 5;

(he sets the number of tests to 5)

What is an expresion data type tests => 5?
Is it a LIST or something else?

How can I use this parameter testsafter the declaration?

+3
source share
2 answers

Yes, this is mentioned LIST- =>is just a fancy way to write this:

use Test::More ("tests", 5);

Which, in turn, causes Test::More->import("tests", 5)after loading the module.

+8
source

Test:: More, -:

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;
    }
+6

Source: https://habr.com/ru/post/1763853/


All Articles