Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Passing Dynamic Value to Test::More tests

by jesuashok (Curate)
on Jan 19, 2006 at 03:47 UTC ( [id://524120]=perlquestion: print w/replies, xml ) Need Help??

jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

use Test::More tests => 2;
How can I pass a dynamic Value to the test count Value.

like :-
$test_count = 2; use Test::More tests => $test_count;
It says that above is Invaid.

Could anyone tell me the way to pass dyanamic test count values.

"Keep pouring your ideas"

Replies are listed 'Best First'.
Re: Passing Dynamic Value to Test::More tests
by chromatic (Archbishop) on Jan 19, 2006 at 06:48 UTC

    An alternate approach is:

    # compile time use Test::More; # run time my $test_count = 2; plan( tests => $test_count );

    You can use this when you don't have tests that execute in BEGIN, CHECK, or INIT blocks.

      That's a great point. I use that pattern also for when I may want to skip a test file entirely if a test dependency isn't available.

      use Test::More; eval { require Some::Crazy::Dependency }; if ($@) { plan skip_all => "Some::Crazy::Dependency not available"; } else { plan tests => 42; }

      It could be done in a BEGIN block, too, but I find it more readable without them.

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Passing Dynamic Value to Test::More tests
by Madcap Laughs (Acolyte) on Jan 19, 2006 at 04:19 UTC
    Try:
    BEGIN {$test_count = 2} use Test::More tests => $test_count;
    Cheers,
    Rob
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Passing Dynamic Value to Test::More tests
by stonecolddevin (Parson) on Jan 19, 2006 at 04:00 UTC
    can you give us some sort of error message?
    meh.
Re: Passing Dynamic Value to Test::More tests
by Mandrake (Chaplain) on Jan 19, 2006 at 05:35 UTC
    This one works for me.
    BEGIN { $test_count = 2; eval ("use Test::More tests => ".$test_count) ; }
    Thanks..

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://524120]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-19 02:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found