This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move Module::Build from ext/ to cpan/
[perl5.git] / cpan / Module-Build / t / install_extra_target.t
1 #!perl -w
2 # Contributed by: Thorben Jaendling
3
4 use strict;
5 use lib 't/lib';
6 use MBTest tests => 8;
7
8 require_ok 'Module::Build';
9 ensure_blib('Module::Build');
10
11 use File::Spec::Functions qw( catdir );
12
13 my $tmp = MBTest->tmpdir;
14 my $output;
15
16 use DistGen;
17 my $dist = DistGen->new( dir => $tmp );
18
19 # note("Dist is in $tmp\n");
20
21 $dist->add_file("Build.PL", <<'===EOF===');
22 #!perl -w
23
24 use strict;
25 use Module::Build;
26
27 my $subclass = Module::Build->subclass(code => <<'=EOF=');
28 sub copy_files
29 {
30         my $self = shift;
31         my $dir = shift;
32
33         my $files = $self->rscan_dir($dir, sub {-f $_ and not m!/\.|[#~]$!});
34
35         foreach my $file (@$files) {
36                 $self->copy_if_modified(from => $file, to_dir => "blib");
37         }
38 }
39
40 #Copy etc files to blib
41 sub process_etc_files
42 {
43         my $self = shift;
44
45         $self->copy_files("etc");
46 }
47
48 #Copy share files to blib
49 sub process_share_files
50 {
51         my $self = shift;
52
53         $self->copy_files("share");
54 }
55
56 1;
57 =EOF=
58
59 my $build = $subclass->new(
60         module_name => 'Simple',
61         license     => 'perl'
62 );
63
64 $build->add_build_element('etc');
65 $build->add_build_element('share');
66
67 my $distdir = lc $build->dist_name();
68
69 foreach my $id ('core', 'site', 'vendor') {
70         #Where to install these build types when using prefix symantics
71         $build->prefix_relpaths($id, 'share' => "share/$distdir");
72         $build->prefix_relpaths($id, 'etc' => "etc/$distdir");
73
74         #Where to install these build types when using default symantics
75         my $set = $build->install_sets($id);
76         $set->{'share'} = '/usr/'.($id eq 'site' ? 'local/':'')."share/$distdir";
77         $set->{'etc'} = ($id eq 'site' ? '/usr/local/etc/':'/etc/').$distdir;
78 }
79
80 #Where to install these types when using install_base symantics
81 $build->install_base_relpaths('share' => "share/$distdir");
82 $build->install_base_relpaths('etc' => "etc/$distdir");
83
84 $build->create_build_script();
85
86 ===EOF===
87         
88 #Test Build.PL exists ok?
89
90 $dist->add_file("etc/config", <<'===EOF===');
91 [main]
92 Foo = bar
93 Jim = bob
94
95 [supplemental]
96 stardate = 1234344
97
98 ===EOF===
99
100 $dist->add_file("share/data", <<'===EOF===');
101 7 * 9 = 42?
102
103 ===EOF===
104
105 $dist->add_file("share/html/index.html", <<'===EOF===');
106 <HTML>
107   <BODY>
108     <H1>Hello World!</H1>
109   </BODY>
110 </HTML>
111
112 ===EOF===
113
114 $dist->regen;
115 $dist->chdir_in;
116
117 my $installdest = catdir($tmp, 't', "install_extra_targets-$$");
118
119 $output = stdout_of sub { $dist->run_build_pl("--install_base=$installdest") };
120
121 $output .= stdout_of sub { $dist->run_build };
122
123 my $error;
124 $error++ unless ok(-e "blib/etc/config", "Built etc/config");
125 $error++ unless ok(-e "blib/share/data", "Built share/data");
126 $error++ unless ok(-e "blib/share/html/index.html", "Built share/html");
127 diag "OUTPUT:\n$output" if $error;
128
129 $output = stdout_of sub { $dist->run_build('install') };
130
131 $error = 0;
132 $error++ unless ok(-e "$installdest/etc/simple/config", "installed etc/config");
133 $error++ unless ok(-e "$installdest/share/simple/data", "installed share/data");
134 $error++ unless ok(-e "$installdest/share/simple/html/index.html", "installed share/html");
135 diag "OUTPUT:\n$output" if $error;
136
137 $dist->remove();