Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

self testing code Test::More

by mandog (Curate)
on Aug 29, 2002 at 04:05 UTC ( #193664=perlquestion: print w/ replies, xml ) Need Help??
mandog has asked for the wisdom of the Perl Monks concerning the following question:

We've written a simple script to do a simple task, still we'd like to include unit tests...

The problem is that if we don't run in test mode, we still get this message printed to stderr:

# No tests run!

Since the code will run from cron, this is a small hassle. The relivant bits are:

use Test::More qw(no_plan); if ( @ARGV == 0 ) { main(); } elsif ( @ARGV == 2 && lc( $ARGV[0] ) eq 'test' ) { Run_Test( $ARGV[1] ); } else { die "bad arguments: the comments may help in $0\n"; }


email: mandog

Comment on self testing code Test::More
Select or Download Code
Re: self testing code Test::More
by dws (Chancellor) on Aug 29, 2002 at 05:01 UTC
    Try something like
    my $TESTING = 1; ... if ( $TESTING ) { require Test::More; import Test::More qw(no_plan); Run_Test(...); }
Re: self testing code Test::More
by jmcnamara (Monsignor) on Aug 29, 2002 at 08:17 UTC

    You could use the autouse pragma to defer loading of the Test::More functions until they are required:
    #!/usr/bin/perl -w use autouse Test::More => 'no_plan'; if ( @ARGV == 0 ) { main(); } elsif ( @ARGV == 2 && lc( $ARGV[0] ) eq 'test' ) { Run_Test( $ARGV[1] ); } else { die "bad arguments: the comments may help in $0\n"; }

    --
    John.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-07-10 20:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (215 votes), past polls