ExtUtils::MakeMaker 6.03 -> 6.06_05ish
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / basic.t
1 #!/usr/bin/perl -w
2
3 # This test puts MakeMaker through the paces of a basic perl module
4 # build, test and installation of the Big::Fat::Dummy module.
5
6 BEGIN {
7     if( $ENV{PERL_CORE} ) {
8         chdir 't' if -d 't';
9         @INC = ('../lib', 'lib');
10     }
11     else {
12         unshift @INC, 't/lib';
13     }
14 }
15
16 use strict;
17 use Config;
18
19 use Test::More tests => 48;
20 use MakeMaker::Test::Utils;
21 use File::Find;
22 use File::Spec;
23
24 my $perl = which_perl();
25 my $Is_VMS = $^O eq 'VMS';
26
27 my $root_dir = 't';
28
29 if( $^O eq 'VMS' ) {
30     # On older systems we might exceed the 8-level directory depth limit
31     # imposed by RMS.  We get around this with a rooted logical, but we
32     # can't create logical names with attributes in Perl, so we do it
33     # in a DCL subprocess and put it in the job table so the parent sees it.
34     open( BFDTMP, '>bfdtesttmp.com' ) || die "Error creating command file; $!";
35     print BFDTMP <<'COMMAND';
36 $ IF F$TRNLNM("PERL_CORE") .EQS. "" .AND. F$TYPE(PERL_CORE) .EQS. ""
37 $ THEN
38 $!  building CPAN version
39 $   BFD_TEST_ROOT = F$PARSE("SYS$DISK:[]",,,,"NO_CONCEAL")-".][000000"-"]["-"].;"+".]"
40 $ ELSE
41 $!  we're in the core
42 $   BFD_TEST_ROOT = F$PARSE("SYS$DISK:[-]",,,,"NO_CONCEAL")-".][000000"-"]["-"].;"+".]"
43 $ ENDIF
44 $ DEFINE/JOB/NOLOG/TRANSLATION=CONCEALED BFD_TEST_ROOT 'BFD_TEST_ROOT'
45 COMMAND
46     close BFDTMP;
47
48     system '@bfdtesttmp.com';
49     END { 1 while unlink 'bfdtesttmp.com' }
50     $root_dir = 'BFD_TEST_ROOT:[t]';
51 }
52
53 chdir $root_dir;
54
55
56 perl_lib;
57
58 my $Touch_Time = calibrate_mtime();
59
60 $| = 1;
61
62 ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) ||
63   diag("chdir failed: $!");
64
65 my @mpl_out = `$perl Makefile.PL PREFIX=dummy-install`;
66
67 cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) ||
68   diag(@mpl_out);
69
70 my $makefile = makefile_name();
71 ok( grep(/^Writing $makefile for Big::Dummy/, 
72          @mpl_out) == 1,
73                                            'Makefile.PL output looks right');
74
75 ok( grep(/^Current package is: main$/,
76          @mpl_out) == 1,
77                                            'Makefile.PL run in package main');
78
79 ok( -e $makefile,       'Makefile exists' );
80
81 # -M is flakey on VMS
82 my $mtime = (stat($makefile))[9];
83 cmp_ok( $Touch_Time, '<=', $mtime,  '  its been touched' );
84
85 END { unlink makefile_name(), makefile_backup() }
86
87 my $make = make_run();
88
89 {
90     # Supress 'make manifest' noise
91     local $ENV{PERL_MM_MANIFEST_VERBOSE} = 0;
92     my $manifest_out = `$make manifest`;
93     ok( -e 'MANIFEST',      'make manifest created a MANIFEST' );
94     ok( -s 'MANIFEST',      '  its not empty' );
95 }
96
97 END { unlink 'MANIFEST'; }
98
99
100 `$make ppd`;
101 is( $?, 0,                      '  exited normally' );
102 ok( open(PPD, 'Big-Dummy.ppd'), '  .ppd file generated' );
103 my $ppd_html;
104 { local $/; $ppd_html = <PPD> }
105 close PPD;
106 like( $ppd_html, qr{^<SOFTPKG NAME="Big-Dummy" VERSION="0,01,0,0">}m, 
107                                                            '  <SOFTPKG>' );
108 like( $ppd_html, qr{^\s*<TITLE>Big-Dummy</TITLE>}m,        '  <TITLE>'   );
109 like( $ppd_html, qr{^\s*<ABSTRACT>Try "our" hot dog's</ABSTRACT>}m,         
110                                                            '  <ABSTRACT>');
111 like( $ppd_html, 
112       qr{^\s*<AUTHOR>Michael G Schwern &lt;schwern\@pobox.com&gt;</AUTHOR>}m,
113                                                            '  <AUTHOR>'  );
114 like( $ppd_html, qr{^\s*<IMPLEMENTATION>}m,          '  <IMPLEMENTATION>');
115 like( $ppd_html, qr{^\s*<DEPENDENCY NAME="strict" VERSION="0,0,0,0" />}m,
116                                                            '  <DEPENDENCY>' );
117 like( $ppd_html, qr{^\s*<OS NAME="$Config{osname}" />}m,
118                                                            '  <OS>'      );
119 like( $ppd_html, qr{^\s*<ARCHITECTURE NAME="$Config{archname}" />}m,  
120                                                            '  <ARCHITECTURE>');
121 like( $ppd_html, qr{^\s*<CODEBASE HREF="" />}m,            '  <CODEBASE>');
122 like( $ppd_html, qr{^\s*</IMPLEMENTATION>}m,           '  </IMPLEMENTATION>');
123 like( $ppd_html, qr{^\s*</SOFTPKG>}m,                      '  </SOFTPKG>');
124 END { unlink 'Big-Dummy.ppd' }
125
126
127 my $test_out = `$make test`;
128 like( $test_out, qr/All tests successful/, 'make test' );
129 is( $?, 0,                                 '  exited normally' );
130
131 # Test 'make test TEST_VERBOSE=1'
132 my $make_test_verbose = make_macro($make, 'test', TEST_VERBOSE => 1);
133 $test_out = `$make_test_verbose`;
134 like( $test_out, qr/ok \d+ - TEST_VERBOSE/, 'TEST_VERBOSE' );
135 like( $test_out, qr/All tests successful/,  '  successful' );
136 is( $?, 0,                                  '  exited normally' );
137
138
139 my $install_out = `$make install`;
140 is( $?, 0, 'install' ) || diag $install_out;
141 like( $install_out, qr/^Installing /m );
142 like( $install_out, qr/^Writing /m );
143
144 ok( -r 'dummy-install',     '  install dir created' );
145 my %files = ();
146 find( sub { 
147     # do it case-insensitive for non-case preserving OSs
148     $files{lc $_} = $File::Find::name; 
149 }, 'dummy-install' );
150 ok( $files{'dummy.pm'},     '  Dummy.pm installed' );
151 ok( $files{'liar.pm'},      '  Liar.pm installed'  );
152 ok( $files{'.packlist'},    '  packlist created'   );
153 ok( $files{'perllocal.pod'},'  perllocal.pod created' );
154
155
156 SKIP: {
157     skip "VMS install targets do not preserve PREFIX", 8 if $Is_VMS;
158
159     $install_out = `$make install PREFIX=elsewhere`;
160     is( $?, 0, 'install with PREFIX override' ) || diag $install_out;
161     like( $install_out, qr/^Installing /m );
162     like( $install_out, qr/^Writing /m );
163
164     ok( -r 'elsewhere',     '  install dir created' );
165     %files = ();
166     find( sub { $files{$_} = $File::Find::name; }, 'elsewhere' );
167     ok( $files{'Dummy.pm'},     '  Dummy.pm installed' );
168     ok( $files{'Liar.pm'},      '  Liar.pm installed'  );
169     ok( $files{'.packlist'},    '  packlist created'   );
170     ok( $files{'perllocal.pod'},'  perllocal.pod created' );
171 }
172
173
174 my $dist_test_out = `$make disttest`;
175 is( $?, 0, 'disttest' ) || diag($dist_test_out);
176
177 # Test META.yml generation
178 use ExtUtils::Manifest qw(maniread);
179 ok( -f 'META.yml',    'META.yml written' );
180 my $manifest = maniread();
181 # VMS is non-case preserving, so we can't know what the MANIFEST will
182 # look like. :(
183 _normalize($manifest);
184 is( $manifest->{'meta.yml'}, 'Module meta-data in YAML' );
185
186
187 # Make sure init_dirscan doesn't go into the distdir
188 @mpl_out = `$perl Makefile.PL "PREFIX=dummy-install"`;
189
190 cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) ||
191   diag(@mpl_out);
192
193 ok( grep(/^Writing $makefile for Big::Dummy/, @mpl_out) == 1,
194                                 'init_dirscan skipped distdir') || 
195   diag(@mpl_out);
196
197 # I know we'll get ignored errors from make here, that's ok.
198 # Send STDERR off to oblivion.
199 open(SAVERR, ">&STDERR") or die $!;
200 open(STDERR, ">".File::Spec->devnull) or die $!;
201
202 my $realclean_out = `$make realclean`;
203 is( $?, 0, 'realclean' ) || diag($realclean_out);
204
205 open(STDERR, ">&SAVERR") or die $!;
206 close SAVERR;
207
208
209 sub _normalize {
210     my $hash = shift;
211
212     while(my($k,$v) = each %$hash) {
213         delete $hash->{$k};
214         $hash->{lc $k} = $v;
215     }
216 }