The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Perl::Critic::Policy::TestingAndDebugging::inprogressProhibitTestPrint - don't use arbitrary prints in a test script

DESCRIPTION

This policy is part of the Perl::Critic::Pulp addon. It asks you not to use a raw print in a test script to avoid any chance of confusing the test parsers.

    print "now doing $some $thing\n";           # bad

Either a # for a comment or diag from Test::More is better.

    print "# a comment about $some $thing\n";   # ok

    use Test::More;
    diag "blah blah blah";                      # ok

diag has the advantage that it will insert # comment after any newlines in the output too.

Various prints for explicit test output are allowed,

    print "ok 1\n"                       # ok
    print "not ok 2 - some reason\n"     # ok
    print "pragma +something\n"          # ok
    print "Bail out\n"                   # ok

commentize is that it guarantees the output won't be misinterpreted by the test harnesses, see "Diagnostics" in Test::More.

    print "ok now we're starting\n";    # bad
    print STDERR "something\n";         # bad

    # handles for test file setups ok
    print TESTFH "some data";           # ok

 and is under the
C<tests> theme (see L<Perl::Critic/POLICY THEMES>).

As with all things perlcritic, it's largely a matter of personal preference whether you want this actively enforced. If you're happy to be careful with your prints then disable this policy from your .perlcriticrc file in the usual way (see "CONFIGURATION" in Perl::Critic),

    [-TestingAndDebugging::inprogressProhibitTestPrint]

LIMITATIONS

A print to an unspecified destination is assumed to be stdout. If you use select to go to a test datafile or similar then this assumption will be wrong. Hopefully that sort of thing is rare.

    select MYTESTHANDLE;
    print 123;   # reported, but actually ok

SEE ALSO

Perl::Critic::Pulp, Perl::Critic

HOME PAGE

http://user42.tuxfamily.org/perl-critic-pulp/index.html

COPYRIGHT

Copyright 2008, 2009, 2010, 2011 Kevin Ryde

Perl-Critic-Pulp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Perl-Critic-Pulp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Perl-Critic-Pulp. If not, see http://www.gnu.org/licenses.