The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Test::Perl::Critic - Use Perl::Critic in test scripts

SYNOPSIS

  use Test::Perl::Critic;

  critic_ok($file);                          #Test one file
  all_critic_ok($dir_1, $dir_2, $dir_N );    #Test all files in several $dirs
  all_critic_ok()                            #Test all files in distro

DESCRIPTION

Test::Perl::Critic wraps the Perl::Critic engine in a convenient subroutine suitable for test scripts written for Test::Harness. This makes it easy to integrate coding-standards enforcement into the build process.

SUBROUTINES

critic_ok( FILE [, TESTNAME ] )

Okays the test if Perl::Critic does not find any violations in FILE. If it does, the violations will be reported in the test diagnostics. The optional second argument is the name of test, which defaults to "Perl::Critic test for FILE".

all_critic_ok( @DIRECTORIES )

Runs critic_ok() for all Perl files beneath the given list of directories. If given an empty list, the function tries to find all Perl files in the blib/ directory. If the blib/ directory does not exist, then it tries the lib/ directory.

If you are testing a module, just make a t/criticize.t file with this:

  use Test::More;
  eval 'use Test::Perl::Critic';
  plan skip_all => 'Test::Perl::Critic required to criticise code' if $@;
  all_critic_ok();

Returns true if all files are ok, or false if any file fails.

all_code_files ( [@DIRECTORIES] )

Returns a list of all the Perl files found beneath each DIRECTORY, If @DIRECTORIES is an empty list, defaults to blib/. If blib/ does not exist, it tries lib/. Skips any files in CVS or .svn directories.

A Perl file is:

  • Any file that ends in .PL, .pl, .pm, or .t

  • Any file that has a first line with a shebang containing 'perl'

CONFIGURATION

Perl::Crtic is highly configurable. By default, Test::Perl::Critic invokes Perl::Critic with its default configuration. But if you have developed your code against a custom Perl::Critic configuration, you will want to configure Test::Perl::Critic to do the same.

Test::Perl::Critic allows you to configure Perl::Critic by passing the path to a perlcriticrc file in the use pragma. For example:

  use Test::Perl::Critic (-profile => 't/perlcriticrc');
  all_critic_ok();

Now place a copy of your own .perlcritic file in the distribution as t/perlcriticrc. Then, critc_ok() will be run on all Perl files in this distribution using this same Perl::Critic configuration. See the Perl::Critic documentation for details on the .perlcriticrc file format..

EXPORTS

  critic_ok()
  all_critic_ok()

BUGS

Please report all bugs to http://rt.cpan.org. Thanks.

SEE ALSO

Perl::Critic

Test::More

CREDITS

Andy Lester, whose Test::Pod module provided most of the code and documentation for Test::Critic. Thanks, Andy.

AUTHOR

Jeffrey Ryan Thalhammer <thaljef@cpan.org>

COPYRIGHT

Copyright (c) 2005 Jeffrey Ryan Thalhammer. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.