ASPEER-MakeMaker-Markdown-Pod
view release on metacpan or search on metacpan
t/05-mm-integration.t view on Meta::CPAN
#!perl
use strict;
use warnings;
use lib 'lib';
use Config;
use Cwd qw(abs_path getcwd);
use File::Path qw(make_path);
use File::Temp qw(tempdir);
use Test::More;
use Markdown::Pod::Embed;
use ASPEER::MakeMaker::Markdown::Pod::MM;
# Read and write test fixture files
#
sub slurp {
my ($fn)=@_;
open(my $input_fh, '<', $fn) || die "unable to open $fn, $!";
local $/=undef;
my $text=<$input_fh>;
close($input_fh) || die "unable to close $fn, $!";
return $text;
}
sub blurp {
my ($fn, $text)=@_;
open(my $output_fh, '>', $fn) || die "unable to open $fn, $!";
print $output_fh $text;
close($output_fh) || die "unable to close $fn, $!";
return 1;
}
# Locate both distributions before entering the disposable project
#
my $cwd=getcwd();
my $extutils_lib_dn=abs_path('lib');
my $common_pm_fn=abs_path($INC{'ASPEER/MakeMaker/MM.pm'});
$common_pm_fn=~s{[/\\]ASPEER[/\\]MakeMaker[/\\]MM\.pm$}{};
my $embed_pm_fn=abs_path($INC{'Markdown/Pod/Embed.pm'});
$embed_pm_fn=~s{[/\\]Markdown[/\\]Pod[/\\]Embed\.pm$}{};
my $temporary_dn=tempdir(CLEANUP => 1);
chdir($temporary_dn) || die "unable to chdir $temporary_dn, $!";
make_path('lib', 'bin', 'doc', 'local lib/Docbook/Convert');
my $local_lib_dn=abs_path('local lib');
# Create a minimal MakeMaker distribution with a Markdown sidecar
#
blurp('Makefile.PL', <<'MAKEFILE_PL');
use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Sample',
VERSION_FROM => 'lib/Sample.pm',
EXE_FILES => ['bin/sample.pl'],
LICENSE => 'perl',
AUTHOR => 'Andrew Speer',
depend => {'generated.out' => 'generated.in'},
);
MAKEFILE_PL
blurp('lib/Sample.pm', "package Sample;\nour \$VERSION='0.001';\n1;\n");
blurp('lib/Sample.pm.md', "# NAME\n\nSample - generated documentation\n");
blurp('bin/sample.pl', "#!perl\nour \$VERSION='0.001';\nprint qq(sample\\n);\n");
blurp('doc/guide.xml', "<?xml version=\"1.0\"?>\n<article><title>Guide</title></article>\n");
blurp('local lib/Docbook/Convert/Pandoc.pm', <<'PANDOC_STUB');
package Docbook::Convert::Pandoc;
sub new {return bless({}, shift())}
sub convert_articles {
my ($self, $root_dn)=@_;
die "unexpected document root\n" unless $root_dn eq 'doc';
open(my $output_fh, '>', 'doc/guide.md') || die "unable to open output: $!";
print {$output_fh} "# Guide\n" || die "unable to write output: $!";
close($output_fh) || die "unable to close output: $!";
return ['doc/guide.md'];
}
1;
PANDOC_STUB
blurp('LICENSE', "Sample license\n");
blurp('MANIFEST', "Makefile.PL\nLICENSE\nbin/sample.pl\nlib/Sample.pm\nlib/Sample.pm.md\n");
# Create disposable Git provenance when Git is available
#
my $git_sha='';
if (system('git', 'init', '-q')==0) {
system('git', 'add', '.')==0 || die "unable to add Git fixtures, $!";
system(
'git',
'-c', 'user.name=ExtUtils Markdown Pod Test',
'-c', 'user.email=test@example.invalid',
'commit', '-qm', 'test fixture'
)==0 || die "unable to commit Git fixtures, $!";
$git_sha=qx(git rev-parse --short HEAD);
chomp($git_sha);
}
# Generate the Makefile using the two checkout libraries
#
local $ENV{'PERL5LIB'}=join(
$Config{'path_sep'},
grep {defined($_) && length($_)}
($extutils_lib_dn, $common_pm_fn, $embed_pm_fn, $ENV{'PERL5LIB'})
);
is(system($^X, "-I$local_lib_dn", '-MASPEER::MakeMaker::Markdown::Pod', 'Makefile.PL'), 0,
'Makefile.PL succeeds with command-line import');
my $makefile=slurp('Makefile');
like($makefile, qr/^PERLRUN\s*=.*-MASPEER::MakeMaker::Markdown::Pod/m,
'global PERLRUN reloads the MakeMaker integration');
like($makefile, qr/^PERLRUN\s*=.*-MExtUtils::MakeMaker/m,
'global PERLRUN retains loaded MakeMaker modules');
like($makefile, qr/^Makefile\s*:\s*\$\(VERSION_FROM\)$/m,
'Makefile depends on VERSION_FROM');
like($makefile, qr/^generated\.out\s*:\s*generated\.in$/m,
'existing Makefile dependencies are retained');
like($makefile, qr/(?:'-I[^']*local lib'|"-I[^"]*local lib")/,
'global PERLRUN quotes include paths containing spaces');
like($makefile, qr/^doc :: readme$/m, 'doc target generated');
like($makefile, qr/^readme ::$/m, 'readme target generated');
like($makefile,
qr/^MARKPOD_PM_TARGET=\$\(PERLRUN\) -M\$\(MARKPOD_PM\).*\s-e\s/m,
'target command explicitly reloads its dispatch module');
unlike($makefile, qr/^MM_PREFIX\s*=/m,
'private macro prefix configuration is not emitted');
like($makefile, qr/^\s*\@\$\(MARKPOD_PM_TARGET\) doc$/m,
'doc target passes its method explicitly');
like($makefile, qr/^LICENSE\s*=\s*perl$/m, 'license macro generated');
like(slurp('MYMETA.json'), qr/"license"\s*:\s*\[/,
'license metadata generated');
like($makefile, qr/^EXE_FILES\s*=\s*bin\/sample\.pl$/m,
'executable retains its declared filename');
ok(!-e 'bin/sample', 'extensionless executable is not created implicitly');
unlike($makefile, qr/lib\/Sample\.pm\.md\s+blib\//,
'Markdown sidecar excluded from install map');
like($makefile, qr/'LICENSE'\s+'\$\(INST_LIBDIR\)/,
'license file included in install map');
if (length($git_sha)) {
is(slurp('lib/Sample.pm.sha'), "$git_sha\n", 'Git-SHA provenance generated');
like($makefile, qr/lib\/Sample\.pm\.sha/, 'Git-SHA provenance included in install map');
utime(1000000000, 1000000000, 'lib/Sample.pm.sha') ||
die "unable to set Git-SHA fixture timestamp, $!";
}
else {
ok(!-e 'lib/Sample.pm.sha', 'Git-SHA generation skipped outside a checkout');
pass('Git-SHA install-map test skipped outside a checkout');
}
# Exercise the generated target rather than calling its implementation directly
( run in 1.453 second using v1.01-cache-2.11-cpan-234fa220139 )