Add ARM files
[dh-make-perl] / dev / arm / libmodule-build-perl / libmodule-build-perl-0.2808.01 / t / ppm.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest;
6 use Module::Build;
7 use Module::Build::ConfigData;
8
9 my $manpage_support = Module::Build::ConfigData->feature('manpage_support');
10 my $HTML_support = Module::Build::ConfigData->feature('HTML_support');
11
12
13 {
14   my ($have_c_compiler, $C_support_feature) = check_compiler();
15   if (! $C_support_feature) {
16     plan skip_all => 'C_support not enabled';
17   } elsif ( ! $have_c_compiler ) {
18     plan skip_all => 'C_support enabled, but no compiler found';
19   } elsif ( ! eval {require Archive::Tar} ) {
20     plan skip_all => "Archive::Tar not installed to read archives.";
21   } elsif ( ! eval {IO::Zlib->VERSION(1.01)} ) {
22     plan skip_all => "IO::Zlib 1.01 required to read compressed archives.";
23   } else {
24     plan tests => 12;
25   }
26 }
27
28
29 use Cwd ();
30 my $cwd = Cwd::cwd;
31 my $tmp = MBTest->tmpdir;
32
33
34 use DistGen;
35 my $dist = DistGen->new( dir => $tmp, xs => 1 );
36 $dist->add_file( 'hello', <<'---' );
37 #!perl -w
38 print "Hello, World!\n";
39 __END__
40
41 =pod
42
43 =head1 NAME
44
45 hello
46
47 =head1 DESCRIPTION
48
49 Says "Hello"
50
51 =cut
52 ---
53 $dist->change_build_pl
54 ({
55   module_name => $dist->name,
56   license     => 'perl',
57   scripts     => [ 'hello' ],
58 });
59 $dist->regen;
60
61 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
62
63 use File::Spec::Functions qw(catdir);
64
65 use Module::Build;
66 my @installstyle = qw(lib perl5);
67 my $mb = Module::Build->new_from_context(
68   verbose => 0,
69   quiet   => 1,
70
71   installdirs => 'site',
72   config => {
73     manpage_reset(), html_reset(),
74     ( $manpage_support ?
75       ( installsiteman1dir  => catdir($tmp, 'site', 'man', 'man1'),
76         installsiteman3dir  => catdir($tmp, 'site', 'man', 'man3') ) : () ),
77     ( $HTML_support ?
78       ( installsitehtml1dir => catdir($tmp, 'site', 'html'),
79         installsitehtml3dir => catdir($tmp, 'site', 'html') ) : () ),
80   },
81 );
82
83
84
85 $mb->dispatch('ppd', args => {codebase => '/path/to/codebase-xs'});
86
87 (my $dist_filename = $dist->name) =~ s/::/-/g;
88 my $ppd = slurp($dist_filename . '.ppd');
89
90 my $perl_version = Module::Build::PPMMaker->_ppd_version($mb->perl_version);
91 my $varchname = Module::Build::PPMMaker->_varchname($mb->config);
92
93 # This test is quite a hack since with XML you don't really want to
94 # do a strict string comparison, but absent an XML parser it's the
95 # best we can do.
96 is $ppd, <<"---";
97 <SOFTPKG NAME="$dist_filename" VERSION="0,01,0,0">
98     <TITLE>@{[$dist->name]}</TITLE>
99     <ABSTRACT>Perl extension for blah blah blah</ABSTRACT>
100     <AUTHOR>A. U. Thor, a.u.thor\@a.galaxy.far.far.away</AUTHOR>
101     <IMPLEMENTATION>
102         <PERLCORE VERSION="$perl_version" />
103         <OS NAME="$^O" />
104         <ARCHITECTURE NAME="$varchname" />
105         <CODEBASE HREF="/path/to/codebase-xs" />
106     </IMPLEMENTATION>
107 </SOFTPKG>
108 ---
109
110
111
112 $mb->dispatch('ppmdist');
113 is $@, '';
114
115 my $tar = Archive::Tar->new;
116
117 my $tarfile = $mb->ppm_name . '.tar.gz';
118 $tar->read( $tarfile, 1 );
119
120 my $files = { map { $_ => 1 } $tar->list_files };
121
122 my $fname = 'Simple';
123 $fname = DynaLoader::mod2fname([$fname]) if defined &DynaLoader::mod2fname;
124 exists_ok($files, "blib/arch/auto/Simple/$fname." . $mb->config('dlext'));
125 exists_ok($files, 'blib/lib/Simple.pm');
126 exists_ok($files, 'blib/script/hello');
127
128 SKIP: {
129   skip( "manpage_support not enabled.", 2 ) unless $manpage_support;
130
131   exists_ok($files, 'blib/man3/Simple.' . $mb->config('man3ext'));
132   exists_ok($files, 'blib/man1/hello.' . $mb->config('man1ext'));
133 }
134
135 SKIP: {
136   skip( "HTML_support not enabled.", 2 ) unless $HTML_support;
137
138   exists_ok($files, 'blib/html/site/lib/Simple.html');
139   exists_ok($files, 'blib/html/bin/hello.html');
140 }
141
142 $tar->clear;
143 undef( $tar );
144
145 $mb->dispatch('realclean');
146 $dist->clean;
147
148
149 SKIP: {
150   skip( "HTML_support not enabled.", 3 ) unless $HTML_support;
151
152   # Make sure html documents are generated for the ppm distro even when
153   # they would not be built during a normal build.
154   $mb = Module::Build->new_from_context(
155     verbose => 0,
156     quiet   => 1,
157
158     installdirs => 'site',
159     config => {
160       html_reset(),
161       installsiteman1dir  => catdir($tmp, 'site', 'man', 'man1'),
162       installsiteman3dir  => catdir($tmp, 'site', 'man', 'man3'),
163     },
164   );
165
166   $mb->dispatch('ppmdist');
167   is $@, '';
168
169   $tar = Archive::Tar->new;
170   $tar->read( $tarfile, 1 );
171
172   $files = {map { $_ => 1 } $tar->list_files};
173
174   exists_ok($files, 'blib/html/site/lib/Simple.html');
175   exists_ok($files, 'blib/html/bin/hello.html');
176
177   $tar->clear;
178
179   $mb->dispatch('realclean');
180   $dist->clean;
181 }
182
183
184 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
185 $dist->remove;
186
187 use File::Path;
188 rmtree( $tmp );
189
190
191 ########################################
192
193 sub exists_ok {
194   my $files = shift;
195   my $file  = shift;
196   local $Test::Builder::Level = $Test::Builder::Level + 1;
197   ok exists( $files->{$file} ) && $files->{$file}, $file;
198 }
199
200 # A hash of all Config.pm settings related to installing
201 # manpages with values set to an empty string.
202 sub manpage_reset {
203   return (
204     installman1dir => '',
205     installman3dir => '',
206     installsiteman1dir => '',
207     installsiteman3dir => '',
208     installvendorman1dir => '',
209     installvendorman3dir => '',
210   );
211 }
212
213 # A hash of all Config.pm settings related to installing
214 # html documents with values set to an empty string.
215 sub html_reset {
216   return (
217     installhtmldir => '',
218     installhtml1dir => '',
219     installhtml3dir => '',
220     installsitehtml1dir => '',
221     installsitehtml3dir => '',
222     installvendorhtml1dir => '',
223     installvendorhtml3dir => '',
224   );
225 }
226