X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Finstall.t;h=b080636b9087335937ef26f8773e8604e2919504;hb=62b783b228390922553e1c972a31c9848b091afa;hp=2ac49ccc710b496989c15849679efd60915d25e9;hpb=8522f4d534fb0a64f7be010048e988dfda658258;p=p5sagit%2Flocal-lib.git diff --git a/t/install.t b/t/install.t index 2ac49cc..b080636 100644 --- a/t/install.t +++ b/t/install.t @@ -3,39 +3,90 @@ use warnings; use Test::More; BEGIN { plan skip_all => "Install Capture::Tiny to test installation" unless eval { require Capture::Tiny; 1 } } -use Capture::Tiny qw(capture); -use File::Temp qw(tempdir); +use Capture::Tiny qw(capture_merged); use File::Spec; +use File::Path qw(mkpath); use Cwd; use Config; -plan tests => 2; - -my $dir = tempdir('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), CLEANUP => 1); +use lib 't/lib'; use TempDir; use local::lib (); -local::lib->import($dir); + +delete @ENV{ + 'PERL_MM_OPT', + 'PERL_MB_OPT', + 'PERL_LOCAL_LIB_ROOT', + grep /^MAKE/, keys %ENV +}; + +my @dirs = ( + 'plain', + 'with space', + 'with\backslash', + 'with space\and-bs', +); + +my %dist_types = ( + EUMM => sub { + open my $fh, '>', 'Makefile.PL' or die "can't create Makefile.PL: $!"; + print $fh 'use ExtUtils::MakeMaker; WriteMakefile( NAME => "EUMM" );'; + close $fh; + system($^X, 'Makefile.PL') && die "Makefile.PL failed"; + system($Config{make}, 'install') && die "$Config{make} install failed"; + }, + MB => sub { + open my $fh, '>', 'Build.PL' or die "can't create Build.PL: $!"; + print $fh <new( + module_name => "MB", + dist_version => 1, + license => "perl", +)->create_build_script; +END_BUILD + close $fh; + system($^X, 'Build.PL') && die "Build.PL failed"; + system($^X, 'Build', 'install') && die "Build install failed"; + }, +); + +plan tests => @dirs * keys(%dist_types) * 2; my $orig_dir = cwd; -SKIP: for my $dist_type (qw(EUMM MB)) { - chdir File::Spec->catdir($orig_dir, qw(t dist), $dist_type); - if ($dist_type eq 'EUMM') { - my ($stdout, $stderr) = capture { eval { - system($^X, 'Makefile.PL') && die "Makefile.PL failed"; - system($Config{make}, 'install') && die "$Config{make} install failed"; - } }; - diag $stdout, $stderr if $@; - } else { - my ($stdout, $stderr) = capture { eval { - system($^X, 'Build.PL') && die "Build.PL failed"; - system($^X, 'Build', 'install') && die "Build install failed"; +for my $dir_base (@dirs) { + for my $dist_type (sort keys %dist_types) { + chdir $orig_dir; + my $temp = mk_temp_dir("install-$dist_type-XXXXX"); + my $ll_dir = "$dist_type-$dir_base"; + my $ll = "$temp/$ll_dir"; + mkpath(File::Spec->canonpath($ll)); + + local::lib->import($ll); + + my $dist_dir = mk_temp_dir("source-$dist_type-XXXXX"); + chdir $dist_dir; + mkdir 'lib'; + open my $fh, '>', "lib/$dist_type.pm"; + print $fh '1;'; + close $fh; + + my $output = capture_merged { eval { + $dist_types{$dist_type}->(); } }; - diag $stdout, $stderr if $@; + is $@, '', "installed $dist_type into '$ll_dir'" + or diag $output; + + my $dest_dir = local::lib->install_base_perl_path($ll); + my $file = File::Spec->catfile($dest_dir, "$dist_type.pm"); + (my $short_file = $file) =~ s/^\Q$ll/$ll_dir/; + ok( + -e $file, + "$dist_type - $dir_base - $dist_type.pm installed as '$short_file'", + ) or diag 'Files in ' . $dest_dir . ":\n", join("\n", do { + my $dh; + (opendir $dh, $dest_dir) ? readdir $dh : "doesn't exist"; + }); } - ok( - -e File::Spec->catfile( - $dir, qw(lib perl5), "$dist_type.pm", - ), - "$dist_type.pm installed into the correct location", - ); } +chdir $orig_dir;