App-GitHooks
view release on metacpan or search on metacpan
lib/App/GitHooks/Hook.pm view on Meta::CPAN
my $has_errors = 0;
foreach my $plugin ( @$plugins )
{
# Since Perl doesn't allow dashes in method names but git hook names have
# dashes, we need to make sure we convert dashes to underscores when
# generating the method name to run.
my $method = 'run_' . $app->get_hook_name();
$method =~ s/-/_/g;
# Run the plugin method corresponding to this hook.
# If the plugin throws an exception, print the error message and consider
# the return code to be a failure.
my $return_code = try
{
return $plugin->$method(
app => $app,
stdin => $stdin,
);
}
catch
{
# Require git.
test_requires_git( '1.7.4.1' );
plan( tests => 7 );
can_ok(
'App::GitHooks',
'new',
);
throws_ok(
sub
{
App::GitHooks->new(
arguments => 'Test',
name => 'commit-msg',
);
},
qr/The 'argument' parameter must be an arrayref/,
"The 'argument' argument is mandatory.",
);
throws_ok(
sub
{
App::GitHooks->new(
arguments => [],
name => undef,
);
},
qr/The argument 'name' is mandatory/,
"The 'name' argument is mandatory.",
);
throws_ok(
sub
{
App::GitHooks->new(
arguments => [],
name => 'invalid-name',
);
},
qr/Invalid hook name/,
"The 'name' argument must be valid.",
);
t/11-clone.t view on Meta::CPAN
ok(
defined(
my $app = App::GitHooks->new(
arguments => [],
name => 'commit-msg',
)
),
'Instantiate a new App::GitHooks object.',
);
throws_ok(
sub
{
$app->clone(
invalid_argument => 1,
);
},
qr/\QInvalid argument(s): invalid_argument/,
'clone() rejects invalid arguments.',
);
t/11-clone.t view on Meta::CPAN
);
# Test cloning with an override of the triggered hook name.
subtest(
'Clone app object .',
sub
{
plan( tests => 6 );
# Override with a valid hook name only.
throws_ok(
sub
{
my $clone = $app->clone(
name => 'test',
);
},
qr/\QInvalid hook name test\E/,
'Cloning the app object with an incorrect hook name is not allowed.',
);
t/12-force_non_interactive.t view on Meta::CPAN
),
'Create a new App::GitHooks object.',
);
is(
$app->force_non_interactive(),
0,
'Force is not set by default.',
);
throws_ok(
sub
{
$app->force_non_interactive( 'test' );
},
qr/Invalid argument/,
'Require a valid argument.',
);
lives_ok(
sub
t/13-Config/20-get_regex.t view on Meta::CPAN
expected => undef,
},
{
name => 'Empty value.',
config => "$key_name =\n",
expected => undef,
},
{
name => 'Value is not a regex.',
config => "$key_name = test\n",
throws => "The key $key_name in the section _ is not a regex, use /.../ to delimit your expression",
},
{
name => 'Value has unescaped slash delimiters.',
config => "$key_name = /test/test/\n",
throws => "The key $key_name in the section _ does not specify a valid regex, it has unescaped '/' delimiters inside it",
},
{
name => 'Valid regex.',
config => "$key_name = /test/\n",
expected => 'test',
},
];
# Declare tests.
plan( tests => scalar( @$tests + 1 ) );
t/13-Config/20-get_regex.t view on Meta::CPAN
);
ok(
defined(
my $config = $app->get_config()
),
'Retrieve the corresponding config object.',
);
my $regex;
if ( defined( $test->{'throws'} ) )
{
throws_ok(
sub
{
$regex = $config->get_regex( '_', $key_name );
},
qr/\Q$test->{'throws'}\E/,
'regex() throws the expected error.',
);
}
else
{
lives_ok(
sub
{
$regex = $config->get_regex( '_', $key_name );
},
'Retrieve the regex value.',
);
}
SKIP:
{
skip('The regex() call should return an exception.', 1)
if defined( $test->{'throws'} );
is(
$regex,
$test->{'expected'},
'The regex returned matches the expected value.',
);
}
}
);
}
t/13-Config/30-min_app_githooks_version.t view on Meta::CPAN
name => 'commit-msg'
);
},
'config is retrieved when no min_app_githooks_version is specified'
);
App::GitHooks::Test::ok_reset_githooksrc(
content => "min_app_githooks_version = 10000000\n"
);
throws_ok(
sub {
my $app = App::GitHooks->new(
arguments => [],
name => 'commit-msg'
);
},
qr/Requires at least App::Githooks version 10000000/i,
'throws expected error when min_app_githooks_version is greater than version'
);
App::GitHooks::Test::ok_reset_githooksrc(
content => "min_app_githooks_version = 1.0.0\n"
);
lives_ok(
sub {
my $app = App::GitHooks->new(
arguments => [],
t/40-Plugin/03-get_file_check_description.t view on Meta::CPAN
# Require git.
test_requires_git( '1.7.4.1' );
plan( tests => 2 );
can_ok(
'App::GitHooks::Plugin',
'get_file_check_description',
);
throws_ok(
sub
{
App::GitHooks::Plugin->get_file_check_description();
},
qr/\QYou must define a get_file_check_description() subroutine in the plugin\E/,
'The virtual method must be implemented in the plugin themselves.',
);
t/40-Plugin/20-get_name.t view on Meta::CPAN
# Require git.
test_requires_git( '1.7.4.1' );
plan( tests => 6 );
can_ok(
'App::GitHooks::Plugin',
'get_name',
);
throws_ok(
sub
{
App::GitHooks::Plugin->get_name();
},
qr/\QNot a valid plugin class: >App::GitHooks::Plugin<\E/,
'The base class does not have a name.',
);
throws_ok(
sub
{
App::GitHooks::Plugin::get_name( undef );
},
qr/\QYou need to call this method on a class\E/,
'Make sure the method is called on a class (1).',
);
throws_ok(
sub
{
App::GitHooks::Plugin::get_name( '' );
},
qr/\QYou need to call this method on a class\E/,
'Make sure the method is called on a class (2).',
);
subtest(
'Test standard plugin.',
( run in 0.280 second using v1.01-cache-2.11-cpan-496ff517765 )