don't stay in temp directory at end of test
[p5sagit/local-lib.git] / t / install.t
CommitLineData
be160790 1use strict;
2use warnings;
3use Test::More;
4BEGIN { plan skip_all => "Install Capture::Tiny to test installation"
5 unless eval { require Capture::Tiny; 1 } }
93b577b5 6use Capture::Tiny qw(capture_merged);
be160790 7use File::Spec;
93b577b5 8use File::Path qw(mkpath);
be160790 9use Cwd;
10use Config;
11
4f7dfe32 12use lib 't/lib'; use TempDir;
13
93b577b5 14use local::lib ();
be160790 15
a92eab5f 16delete @ENV{
17 'PERL_MM_OPT',
18 'PERL_MB_OPT',
19 'PERL_LOCAL_LIB_ROOT',
20 grep /^MAKE/, keys %ENV
21};
22
93b577b5 23my @dirs = (
24 'plain',
25 'with space',
26 'with\backslash',
27 'with space\and-bs',
28);
be160790 29
93b577b5 30my %dist_types = (
31 EUMM => sub {
fc1885f9 32 open my $fh, '>', 'Makefile.PL' or die "can't create Makefile.PL: $!";
33 print $fh 'use ExtUtils::MakeMaker; WriteMakefile( NAME => "EUMM" );';
34 close $fh;
93b577b5 35 system($^X, 'Makefile.PL') && die "Makefile.PL failed";
36 system($Config{make}, 'install') && die "$Config{make} install failed";
37 },
38 MB => sub {
fc1885f9 39 open my $fh, '>', 'Build.PL' or die "can't create Build.PL: $!";
40 print $fh <<END_BUILD;
41use Module::Build;
42Module::Build->new(
43 module_name => "MB",
44 dist_version => 1,
45 license => "perl",
46)->create_build_script;
47END_BUILD
48 close $fh;
93b577b5 49 system($^X, 'Build.PL') && die "Build.PL failed";
50 system($^X, 'Build', 'install') && die "Build install failed";
51 },
52);
53
54plan tests => @dirs * keys(%dist_types) * 2;
be160790 55
56my $orig_dir = cwd;
93b577b5 57for my $dir_base (@dirs) {
58 for my $dist_type (sort keys %dist_types) {
59 chdir $orig_dir;
fc1885f9 60 my $temp = mk_temp_dir("install-$dist_type-XXXXX");
93b577b5 61 my $ll_dir = "$dist_type-$dir_base";
fc1885f9 62 my $ll = "$temp/$ll_dir";
63 mkpath(File::Spec->canonpath($ll));
64
93b577b5 65 local::lib->import($ll);
66
fc1885f9 67 my $dist_dir = mk_temp_dir("source-$dist_type-XXXXX");
68 chdir $dist_dir;
69 mkdir 'lib';
70 open my $fh, '>', "lib/$dist_type.pm";
71 print $fh '1;';
72 close $fh;
73
93b577b5 74 my $output = capture_merged { eval {
75 $dist_types{$dist_type}->();
be160790 76 } };
93b577b5 77 is $@, '', "installed $dist_type into '$ll_dir'"
78 or diag $output;
79
80 my $dest_dir = local::lib->install_base_perl_path($ll);
81 my $file = File::Spec->catfile($dest_dir, "$dist_type.pm");
82 (my $short_file = $file) =~ s/^\Q$ll/$ll_dir/;
83 ok(
84 -e $file,
85 "$dist_type - $dir_base - $dist_type.pm installed as '$short_file'",
86 ) or diag 'Files in ' . $dest_dir . ":\n", join("\n", do {
87 my $dh;
88 (opendir $dh, $dest_dir) ? readdir $dh : "doesn't exist";
89 });
be160790 90 }
be160790 91}
62b783b2 92chdir $orig_dir;