App-GitHooks

 view release on metacpan or  search on metacpan

lib/App/GitHooks/Test.pm  view on Meta::CPAN


An arrayref of the module names of the plugins to run for this test (for
example, C<App::GitHooks::Plugins::Test::CustomReply>).

=back

Optional arguments:

=over 4

=item * cleanup_test_repository

Whether the test repository created in order to run a test should be destroyed
at the end of the test (default: 1).

=back

=cut

sub test_hook
{
	my ( %args ) = @_;
	my $tests = delete( $args{'tests'} );
	my $hook_name = delete( $args{'hook_name'} );
	my $plugins = delete( $args{'plugins'} );
	my $cleanup_test_repository = delete( $args{'cleanup_test_repository'} ) // 1;
	croak "Invalid arguments passed: " . join( ', ', keys %args )
		if scalar( keys %args ) != 0;
	croak "A hook name must be specified"
		if !defined( $hook_name );
	croak "The hook name is not valid"
		if $hook_name !~ /^[\w-]+$/;

	# Bail out if Git isn't available.
	Test::Requires::Git::test_requires_git( '1.7.4.1' );
	plan( tests => scalar( @$tests ) );

	foreach my $test ( @$tests )
	{
		subtest(
			$test->{'name'},
			sub
			{
				plan( tests => 5 );

				my $repository = ok_setup_repository(
					cleanup_test_repository => $cleanup_test_repository,
					config                  => $test->{'config'},
					hooks                   => [ $hook_name ],
					plugins                 => $plugins,
				);

				# Set up a test file.
				ok_add_file(
					repository => $repository,
					path       => 'test.pl',
					content    => "#!perl\n\nuse strict;\nbareword;\n",
				);

				# Try to commit.
				my $stderr;
				my $exit_status;
				lives_ok(
					sub
					{
						$stderr = Capture::Tiny::capture_stderr(
							sub
							{
								$repository->run( 'commit', '-m', 'Test message.' );
								$exit_status = $? >> 8;
							}
						);
						note( $stderr );
					},
					'Commit the changes.',
				);

				like(
					$stderr,
					$test->{'expected'},
					"The output matches expected results.",
				);

				is(
					$exit_status,
					$test->{'exit_status'},
					'The exit status is correct.',
				);
			}
		);
	}

	return;
}


=head1 BUGS

Please report any bugs or feature requests through the web interface at
L<https://github.com/guillaumeaubert/App-GitHooks/issues/new>.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.


=head1 SUPPORT

You can find documentation for this module with the perldoc command.

	perldoc App::GitHooks::Test


You can also look for information at:

=over

=item * GitHub's request tracker

L<https://github.com/guillaumeaubert/App-GitHooks/issues>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/app-githooks>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/app-githooks>

=item * MetaCPAN

L<https://metacpan.org/release/App-GitHooks>

=back


=head1 AUTHOR

L<Guillaume Aubert|https://metacpan.org/author/AUBERTG>,
C<< <aubertg at cpan.org> >>.



( run in 0.748 second using v1.01-cache-2.11-cpan-364913b4093 )