use Test::File::Content; use Test::More; content_like( qr/\.pm/, qr/^#\s*ABSTRACT/, 'lib' ); content_like( pm => '__PACKAGE__->meta->make_immutable', 'lib/MooseClasses' ); content_unlike({ js => { 'console.log debug statement' => 'console.log', 'never use alert' => qr/[^\.]alert\(/, }, tt => [ qr/\[% DUMP/, ], pl => '\$foo', }, qw(lib root/templates jslib)); done_testing;
Example output:
not ok 1 - lib/MyLib.pm # Failed test 'lib/MyLib.pm' # file lib/MyLib.pm does not contain (?-xism:^#\s*ABSTRACT) ok 2 - lib/MooseClasses/Class.pm not ok 3 - jslib/test.js # Failed test 'jslib/test.js' # console.log debug statement found in jslib/test.js line 1 # console.log debug statement found in jslib/test.js line 2 ok 4 - root/templates/test.tt 1..4
When writing code, I tend to add a lot of debug statements like warn or Data::Dumper. Occasionally I name my variables $foo and $bar which is also quite a bad coding style. JavaScript files may contain console.log() or alert() calls, which are equally bad.
warn
Data::Dumper
$foo
$bar
console.log()
alert()
This test can help to find statements like these and ensure that other statements are there.
The following functions are exported by default:
Arguments: \%config, @directories
Arguments: $filter, $rule, @directories
%config consists of key value pairs where each key is a file extension (e.g. .pm) and the value is a $rule.
%config
.pm
$rule
$filter can either be a string literal (like the key of %config), an arrayref of extensions, a regular expression or even a coderef. The coderef is passed the filename as argument and is expected to return a true value if the file should be looked at.
$filter
$rule can be a string literal, an arrayref of rules or a regular expression.
@directories contains a list of directories or files to look at.
@directories
To install Test::File::Content, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::File::Content
CPAN shell
perl -MCPAN -e shell install Test::File::Content
For more information on module installation, please visit the detailed CPAN module installation guide.