App-GitHooks

 view release on metacpan or  search on metacpan

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


					$cover_db_path = $ENV{'COVER_DB_PATH'}
						if $is_valid;
				};

				# Use File::Spec->catfile() for portability.
				ok(
					defined(
						$cover_db_path //= File::Spec->catfile( Cwd::getcwd(), 'cover_db' )
					),
					'The coverage database directory is set.',
				);
				note( "Using the coverage database directory >$cover_db_path<." );
				$hook_template =~ s/\Q{cover_db_path}\E/$cover_db_path/g
					if defined( $cover_db_path );

				# Note: this is required because Devel::Coverage only analyzes the coverage
				# for files in -dir, which defaults to the current directory. It can be changed
				# to '/home' or '/' to make it cover both the test repository and the main lib/
				# directory in which the code for the hooks lives, but this wouldn't be portable.
				# Instead, we symlink the lib directory into the test repository, and the
				# coverage-specific version of the test githook template will use that symlink as
				# the source for the App::GitHooks modules. As long as the target system supports
				# symlinks, it then allows for coverage testing.
				# Note: lib/ is necessary for testing coverage via 'prove', but
				# blib/lib/ is necessary for testing coverage via 'cover'.
				ok(
					symlink( Cwd::getcwd() . '/lib', $repository->work_tree() . '/lib' ),
					'Symlink lib/ into the test repository to allow proper merging of coverage databases (with "prove").',
				);
				ok(
					mkdir( $repository->work_tree() . '/blib' ),
					'Create a blib/ directory in the test repository.',
				);
				ok(
					symlink( Cwd::getcwd() . '/lib', $repository->work_tree() . '/blib/lib' ),
					'Symlink blib/lib/ into the test repository to allow proper merging of coverage databases (with "cover").',
				);
			};

			# Set up the hooks.
			foreach my $hook_name ( @$hooks )
			{
				subtest(
					"Set up the $hook_name hook.",
					sub
					{
						plan( tests => 2 );

						my $hook_path = $repository->work_tree() . '/.git/hooks/' . $hook_name;
						lives_ok(
							sub
							{
								Path::Tiny::path( $hook_path )
									->spew( $hook_template );
							},
							'Write the hook.',
						);

						ok(
							chmod( 0755, $hook_path ),
							"Make the $hook_name hook executable.",
						);
					}
				);
			}

			# Set up a .githooksrc config.
			lives_ok(
				sub
				{
					my $content = "";

					# Main section.
					{
						# Only run specific plugins.
						$content .= "force_plugins = " . join( ', ', @$plugins ) . "\n"
							if defined( $plugins );
					}

					# Testing section.
					{
						$content .= "[testing]\n";

						# Pretend we're in an interactive terminal even if we're doing automated testing.
						$content .= "force_interactive = 1\n";

						# Disable color, to make it easier to match output.
						$content .= "force_use_colors = 0\n";

						# Disable utf-8 characters, to make it easier to match output.
						$content .= "force_is_utf8 = 0\n";

						# Just have commit-msg exit with the result of the checks, instead
						# of forcing to correct the issue.
						$content .= "commit_msg_no_edit = 1\n";
					}

					# Add any custom config passed.
					$content .= $config;

					# Write the file.
					Path::Tiny::path( $repository->work_tree(), '.githooksrc' )
						->spew( $content );
				},
				'Write a .githooksrc config file.',
			);
		}
	);

	return $repository;
}


=head2 ok_reset_githooksrc()

Ensures that an empty C<.githooksrc> is used.

	ok_reset_githooksrc();

Arguments:



( run in 0.634 second using v1.01-cache-2.11-cpan-524268b4103 )