|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | + |
| 4 | +use Test::More tests => 6; |
| 5 | +use File::Temp 'tempdir'; |
| 6 | + |
| 7 | +use File::Spec::Functions qw/catfile catdir/; |
| 8 | +use File::Path 'mkpath'; |
| 9 | +use Cwd 'cwd'; |
| 10 | + |
| 11 | +use IPC::Open3; |
| 12 | +use Symbol 'gensym'; |
| 13 | +use Env qw(@PERL5LIB $PERL_MM_OPT); |
| 14 | + |
| 15 | +# ABSTRACT: Test basic behaviour |
| 16 | + |
| 17 | +my $install = tempdir(); |
| 18 | +my $pwd = cwd; |
| 19 | + |
| 20 | +# Make sure install target is prepped. |
| 21 | +unshift @PERL5LIB, $install, catdir($pwd, 'lib'); |
| 22 | +$PERL_MM_OPT = "INSTALL_BASE=$install"; |
| 23 | + |
| 24 | +# Prep the source tree |
| 25 | +my $source = tempdir(); |
| 26 | + |
| 27 | +mkdir catdir($source, 'lib'); |
| 28 | +spew(catfile($source, 'lib', 'TestDist.pm'), "package TestDist;\n\$VERSION = '1.000';\n1;\n"); |
| 29 | + |
| 30 | +my $share = catdir($source, 'share'); |
| 31 | +my $dotdir = catdir($share, qw/dots .dotdir/); |
| 32 | + |
| 33 | +mkpath($dotdir); |
| 34 | +spew(catfile($dotdir, 'normalfile'), 'This is a normal file'); |
| 35 | +spew(catfile($dotdir, '.dotfile'), 'This is a dotfile'); |
| 36 | +spew(catfile($share, 'dots', '.dotfile'), 'This is a dotfile'); |
| 37 | +spew(catfile($share, 'normalfile'), 'This is a normal file'); |
| 38 | + |
| 39 | +spew(catfile($source, 'Makefile.PL'), <<'MAKEFILE'); |
| 40 | +use strict; |
| 41 | +use warnings; |
| 42 | +
|
| 43 | +use ExtUtils::MakeMaker; |
| 44 | +
|
| 45 | +my %Args = ( |
| 46 | + ABSTRACT => "Test Module", |
| 47 | + DISTNAME => "TestDist", |
| 48 | + NAME => "TestDist", |
| 49 | + PREREQ_PM => {}, |
| 50 | + sharedir => { |
| 51 | + dist => 'share', |
| 52 | + }, |
| 53 | +); |
| 54 | +
|
| 55 | +WriteMakefile(%Args); |
| 56 | +
|
| 57 | +MAKEFILE |
| 58 | + |
| 59 | +chdir $source; |
| 60 | +END { chdir $pwd } |
| 61 | + |
| 62 | +sub run_ok { |
| 63 | + my (@command) = @_; |
| 64 | + my $desc = join ' ', @command; |
| 65 | + local $Test::Builder::Level = $Test::Builder::Level + 1; |
| 66 | + |
| 67 | + my ($inh, $outh, $errh) = (undef, undef, gensym); |
| 68 | + my $pid = open3($inh, $outh, $errh, @command) or do { |
| 69 | + fail "Command $desc: $!"; |
| 70 | + return; |
| 71 | + }; |
| 72 | + close $inh; |
| 73 | + |
| 74 | + my $out = do { local $/; <$outh> }; |
| 75 | + my $err = do { local $/; <$errh> }; |
| 76 | + |
| 77 | + waitpid $pid, 0 or die 'Couldn\'t waitpid'; |
| 78 | + return cmp_ok( $?, '==', 0, "Command $desc" ) || note explain { 'stdout' => $out, 'stderr' => $err, exit => $? } |
| 79 | +} |
| 80 | + |
| 81 | +# Testing happens here: |
| 82 | +SKIP: { |
| 83 | + run_ok($^X, 'Makefile.PL'); |
| 84 | + run_ok('make'); |
| 85 | + run_ok('make', 'install'); |
| 86 | + |
| 87 | + my $dir = catdir($install, qw/lib perl5 auto share dist TestDist share/); |
| 88 | + ok(-d $dir, 'Sharedir has been created'); |
| 89 | + ok(-e catfile($dir, 'normalfile'), 'File in sharedir has been created'); |
| 90 | + ok(-e catfile($dir, qw/dots .dotdir .dotfile/), 'A dotfile in a dotdir installed'); |
| 91 | +} |
| 92 | + |
| 93 | +sub spew { |
| 94 | + my ($filename, $content) = @_; |
| 95 | + open my $fh, '>', $filename or die "Couldn't open $filename: $!"; |
| 96 | + print $fh $content or die "Couldn't write to $filename: $!"; |
| 97 | + close $fh or die "Couldn't close $filename: $!"; |
| 98 | + return; |
| 99 | +} |
0 commit comments