in reply to Re: Test::More command-line arguments?
in thread Test::More command-line arguments?

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 $

Replies are listed 'Best First'.
Re^3: Test::More command-line arguments?
by tobyink (Canon) on Sep 25, 2012 at 00:24 UTC

    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'

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

      Bummer.

      Thanks, I may have to resort to this method. I appreciate the time both of you spent is drawing out the fundamental problem.

        Well, your tests shouldn't need arguments :)

        If you need to database connection details, traditional solution is to either use env vars ( along the lines of TEST_MYSQL_USER TEST_MYSQL_PASS ... or TEST_MYSQL_DSN )

        Of via distribution config file , which your tests know how to read

Re^3: Test::More command-line arguments?
by Anonymous Monk on Sep 25, 2012 at 00:22 UTC
    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.

      from prove - Run tests through a TAP harness

      Arguments to Tests

      It is possible to supply arguments to tests. To do so separate them from prove's own arguments with the arisdottle, '::'. For example

      prove -v t/mytest.t :: --url http://example.com

      would run t/mytest.t with the options '--url http://example.com'. When running multiple tests they will each receive the same arguments.