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