NAME
Test::File::Content - Tests files for their content based on their file extension
VERSION
version 1.0.1
SYNOPSIS
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
DESCRIPTION
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.
This test can help to find statements like these and ensure that other statements are there.
FUNCTIONS
The following functions are exported by default:
content_like
content_unlike
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
.
$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.
$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.
AUTHOR
Moritz Onken
COPYRIGHT AND LICENSE
This software is Copyright (c) 2011 by Moritz Onken.
This is free software, licensed under:
The (three-clause) BSD License