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