App-GitHooks-Plugin-PerlCompile
view release on metacpan or search on metacpan
{
name => 'Catch .pl files.',
files =>
{
'test.pm' => "#!perl\n\nuse strict;\nbareword;\n",
},
expected => qr/x The file passes perl -c/,
},
{
name => 'Catch .t files.',
files =>
{
'test.pm' => "#!perl\n\nuse strict;\nbareword;\n",
},
expected => qr/x The file passes perl -c/,
},
{
name => 'Catch files without extension but with a Perl hashbang line.',
files =>
{
'test' => "#!perl\n\nuse strict;\nbareword;\n",
},
expected => qr/x The file passes perl -c/,
},
{
name => 'Skip files without extension and no hashbang.',
files =>
{
'test' => "A regular non-Perl file.\n",
},
expected => qr/^(?!.*\QThe file passes perl -c\E)/,
},
];
# Bail out if Git isn't available.
test_requires_git();
plan( tests => scalar( @$tests ) );
foreach my $test ( @$tests )
{
subtest(
$test->{'name'},
sub
{
plan( tests => 4 );
my $repository = ok_setup_repository(
cleanup_test_repository => 1,
config => $test->{'config'},
hooks => [ 'pre-commit' ],
plugins => [ 'App::GitHooks::Plugin::PerlCompile' ],
);
# Set up test files.
ok_add_files(
files => $test->{'files'},
repository => $repository,
);
# Try to commit.
my $stderr;
lives_ok(
sub
{
$stderr = Capture::Tiny::capture_stderr(
sub
{
$repository->run( 'commit', '-m', 'Test message.' );
}
);
note( $stderr );
},
'Commit the changes.',
);
like(
$stderr,
$test->{'expected'},
"The output matches expected results.",
);
}
);
}
( run in 1.532 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )