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