ASPEER-MakeMaker-Markdown-Pod

 view release on metacpan or  search on metacpan

t/05-mm-integration.t  view on Meta::CPAN


#  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
#
my $make=$Config{'make'} || 'make';
is(system($make, 'doc'), 0, 'generated doc target succeeds');
like(slurp('lib/Sample.pm'), qr/^=head1 NAME$/m,
    'generated target delegates Markdown conversion');
is(slurp('doc/guide.md'), "# Guide\n",
    'generated target converts article XML absent from MANIFEST');


#  Regenerate with optional integration declared inside Makefile.PL
#
my $embedded_import=<<'EMBEDDED_IMPORT';
eval {
    require ASPEER::MakeMaker::Markdown::Pod;
    ASPEER::MakeMaker::Markdown::Pod->import();
    1;
};

EMBEDDED_IMPORT
my $makefile_pl=slurp('Makefile.PL');
$makefile_pl=~s/(use ExtUtils::MakeMaker;\n)/$1$embedded_import/ ||
    die 'unable to add embedded import to Makefile.PL';
blurp('Makefile.PL', $makefile_pl);

is(system($^X, 'Makefile.PL'), 0,
    'Makefile.PL succeeds with embedded optional import');
$makefile=slurp('Makefile');
like($makefile, qr/^PERLRUN\s*=.*-MASPEER::MakeMaker::Markdown::Pod/m,
    'embedded import installs the full integration');
my @doc_target=($makefile=~/^doc :: readme$/mg);
is(scalar(@doc_target), 1, 'embedded import generates one doc target');
if (length($git_sha)) {
    is((stat('lib/Sample.pm.sha'))[9], 1000000000,
        'unchanged Git-SHA provenance is not rewritten');
}
else {
    pass('Git-SHA rewrite test skipped outside a checkout');
}


#  Command-line and embedded activation together remain idempotent
#
is(system($^X, '-MASPEER::MakeMaker::Markdown::Pod', 'Makefile.PL'), 0,
    'combined command-line and embedded activation succeeds');
$makefile=slurp('Makefile');
@doc_target=($makefile=~/^doc :: readme$/mg);
is(scalar(@doc_target), 1, 'combined activation generates one doc target');


#  Install executable Git provenance as data rather than as another executable
#
blurp('Makefile.PL', <<'MAKEFILE_PL');



( run in 1.032 second using v1.01-cache-2.11-cpan-234fa220139 )