App-GitHooks

 view release on metacpan or  search on metacpan

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

				);

				# 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.',
				);
			}

t/20-run.t  view on Meta::CPAN

	defined(
		my $app = App::GitHooks->new(
			name      => 'commit-msg',
			arguments => [],
		)
	),
	'Create a new App::GitHooks object.',
);

my $exit_status;
my $stderr = Capture::Tiny::capture_stderr(
	sub
	{
		$exit_status = $app->run(
			invalid_argument => 'test',
			exit             => 0,
		);
	}
);
note( $stderr );

like(
	$stderr,
	qr/\QError detected in hook: \E/,
	'Invalid arguments are detected.',
);

is(
	$exit_status,
	1,
	'The exit status correctly indicates an error.',
);

t/21-run-dash.t  view on Meta::CPAN

# Require git.
test_requires_git( '1.7.4.1' );
plan( tests => 3 );

# Force a clean githooks config to ensure repeatable test conditions.
App::GitHooks::Test::ok_reset_githooksrc(
	content => "force_plugins = Test\n",
);

my $exit_status;
my $stderr = Capture::Tiny::capture_stderr(
	sub
	{
		$exit_status = App::GitHooks->run(
			name      => 'post-checkout',
			arguments => [],
			exit      => 0,  # Return the exit code instead of exiting.
		);
	}
);

is(
	$exit_status,
	0,
	'The hook ran successfully.',
) || note( "Exit status: $exit_status" );

if ( defined( $stderr ) && ( $stderr ne '' ) )
{
	note( "----- stderr -----" );
	note( $stderr );
	note( "------------------" );
}

# If dashes in hook names were not properly replaced to find the subroutine
# name, the following error should show:
#
#     Can't locate object method "run_post-checkout" via package
#     "App::GitHooks::Plugin::Test"

unlike(
	$stderr,
	qr/run_post-checkout/,
	'The subroutine name was correctly determined from the hook name.',
);


# Test package with a post-checkout action.
package App::GitHooks::Plugin::Test;

use base 'App::GitHooks::Plugin';

t/90-githooks/10-commands.t  view on Meta::CPAN

						( map { "-I$_" } @INC ),
						# The script to test.
						File::Spec->catfile( $source_directory, 'bin', 'githooks' ),
						# The arguments to pass to the script.
						@{ $test->{'arguments'} }
					)
				),
				'Execute "githooks".',
			);

			my $stderr = do { local $/; my $fh = $command->stderr(); <$fh> };
			ok(
				!defined( $stderr ) || ( $stderr eq '' ),
				'The command did not return any errors.',
			) || diag( $stderr );

			my $stdout = do { local $/; my $fh = $command->stdout(); <$fh> };
			ok(
				defined( $stdout ),
				'Capture the standard output.',
			);

			like(
				$stdout,
				$test->{'expected'},



( run in 0.731 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )