Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Test::More command-line arguments?

by Anonymous Monk
on Sep 24, 2012 at 23:55 UTC ( #995459=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm needing to write a Test::More test script which accepts command-line arguments, and passes these parameters to functions defined in the script itself.

Nothing in perldoc indicates that this is possible, nor have any tests using Getopt::Long works in such an environment.

Is there a way I can pluck values from the command-line while using Test::More?

Comment on Test::More command-line arguments?
Re: Test::More command-line arguments?
by chromatic (Archbishop) on Sep 25, 2012 at 00:03 UTC

    A Perl test file written with Test::More is just a Perl program. @ARGV works there like it does in any Perl program (I know, I use @ARGV in some of my test files.)

    Can you post some example code that does not behave as you expect?

      Here's a simple script run with Perl 5.8.8:

      #!/bin/env perl use strict; use warnings; use Test::More tests => 1; use Data::Dumper; print Data::Dumper->Dump([\@ARGV], [qw/ARGV/]); pass('placeholder');
      Upon execution, I'm getting the following:
      $ prove -v t.t one two three t.t .... 1..1 $ARGV = []; ok 1 - placeholder ok Cannot determine source for one at /tools/oss/packages/x86_64-rhel5/pe +rl/5.8.8-64/lib/5.8.8/App/Prove.pm line 496 $
        Okay, I see part of my error. If I run the script directly through the interpreter, I get results:
        $ perl t.t one two three 1..1 $ARGV = [ 'one', 'two', 'three' ]; ok 1 - placeholder $
        ...but is there a way I can pass command-line arguments if I use prove instead? I would like to have the statistics prove provides if possible.

        prove does not pass on arguments to the test files. prove assumes that you're trying to run test cases called "one", "two" and "three".

        If you need to provide arguments to a test file, you need to run it with perl, not prove:

        $ perl t.t one two three

        If you really want to use prove then perhaps modify your test file to read its options from environment variables instead.

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-04-23 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (554 votes), past polls