ASPEER-MakeMaker
view release on metacpan or search on metacpan
t/02-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 qw(no_plan);
use ASPEER::MakeMaker::MM::Util ();
# 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_test {
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;
}
# Module loading must not modify the caller's default variable
#
my $common_lib_dn=abs_path('lib');
is(
system(
$^X,
"-I$common_lib_dn",
'-e',
'$_=q(caller value); require ASPEER::MakeMaker; exit($_ eq q(caller value) ? 0 : 1)'
),
0,
'loading module preserves caller default variable'
);
# Create a disposable MakeMaker distribution
#
my $cwd=getcwd();
my $temporary_dn=tempdir(CLEANUP => 1);
chdir($temporary_dn) || die("unable to chdir $temporary_dn, $!");
make_path('lib', 'bin', 'local lib');
my $local_lib_dn=abs_path('local lib');
blurp_test('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_test('lib/Sample.pm', "package Sample;\nour \$VERSION='0.001';\n1;\n");
blurp_test('lib/Sample.pm.md', "# Sample\n");
blurp_test('lib/Sample.pm.new', "temporary\n");
blurp_test('lib/Sample.pm.1', "temporary\n");
blurp_test('bin/sample.pl', "#!perl\nour \$VERSION='0.001';\nprint qq(sample\\n);\n");
blurp_test('LICENSE', "Sample license\n");
blurp_test('MANIFEST', <<'MANIFEST');
Makefile.PL
LICENSE
bin/sample.pl
lib/Sample.pm
lib/Sample.pm.md
lib/Sample.pm.new
lib/Sample.pm.1
t/02-mm-integration.t view on Meta::CPAN
is(scalar(@util_sync_target), 1, 'combined activation generates one util_sync target');
# Executable provenance is installed as data, not another executable
#
blurp_test('Makefile.PL', <<'MAKEFILE_PL');
use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Sample',
VERSION_FROM => 'bin/sample.pl',
EXE_FILES => ['bin/sample.pl'],
);
MAKEFILE_PL
is(system($^X, '-MASPEER::MakeMaker', 'Makefile.PL'), 0,
'minimal Makefile.PL succeeds without LICENSE or AUTHOR');
$makefile=slurp('Makefile');
like($makefile, qr/^EXE_FILES\s*=\s*bin\/sample\.pl$/m,
'executable Git-SHA sidecar is not treated as an executable');
if (length($git_sha)) {
is(slurp('bin/sample.pl.sha'), "$git_sha\n",
'executable Git-SHA provenance is generated');
like($makefile,
qr/'bin\/sample\.pl\.sha'\s+'\$\(INST_SCRIPT\)\/sample\.pl\.sha'/,
'executable Git-SHA provenance is mapped into INST_SCRIPT');
is(system($make, 'pure_all'), 0, 'executable Git-SHA provenance is copied');
is(slurp('blib/script/sample.pl.sha'), "$git_sha\n",
'installed executable Git-SHA provenance retains its content');
}
else {
ok(!-e 'bin/sample.pl.sha', 'executable Git-SHA generation is skipped without Git');
pass('executable Git-SHA install-map test skipped without Git');
pass('executable Git-SHA copy test skipped without Git');
pass('installed executable Git-SHA content test skipped without Git');
}
# Missing VERSION_FROM must not create a root sidecar
#
blurp_test('Makefile.PL', <<'MAKEFILE_PL');
use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Sample',
VERSION => '0.001',
);
MAKEFILE_PL
is(system($^X, '-MASPEER::MakeMaker', 'Makefile.PL'), 0,
'Makefile.PL succeeds without VERSION_FROM');
ok(!-e '.sha', 'Git-SHA provenance is not created without VERSION_FROM');
chdir($cwd) || die("unable to chdir $cwd, $!");
# File writes must report both data and close failures
#
{
no warnings qw(redefine);
local *IO::File::new=sub {bless({}, 'Local::FailingWrite')};
my $write_ok=eval {
ASPEER::MakeMaker::MM::Util::blurp('ignored', 'text');
1;
};
ok(!$write_ok, 'file write failure is fatal');
}
{
no warnings qw(redefine);
local *IO::File::new=sub {bless({}, 'Local::FailingClose')};
my $close_ok=eval {
ASPEER::MakeMaker::MM::Util::blurp('ignored', 'text');
1;
};
ok(!$close_ok, 'file close failure is fatal');
}
package Local::FailingWrite;
sub print {return 0}
sub close {return 1}
package Local::FailingClose;
sub print {return 1}
sub close {return 0}
( run in 2.907 seconds using v1.01-cache-2.11-cpan-0e0213f3164 )