xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/basic.t (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
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
6BEGIN {
7    unshift @INC, 't/lib';
8}
9
10use strict;
11use Config;
12use ExtUtils::MakeMaker;
13
14use Test::More tests => 80;
15use MakeMaker::Test::Utils;
16use MakeMaker::Test::Setup::BFD;
17use File::Find;
18use File::Spec;
19use File::Path;
20
21my $perl = which_perl();
22my $Is_VMS = $^O eq 'VMS';
23
24chdir 't';
25
26perl_lib;
27
28my $Touch_Time = calibrate_mtime();
29
30$| = 1;
31
32ok( setup_recurs(), 'setup' );
33END {
34    ok( chdir File::Spec->updir );
35    ok( teardown_recurs(), 'teardown' );
36}
37
38ok( chdir('Big-Dummy'), "chdir'd to Big-Dummy" ) ||
39  diag("chdir failed: $!");
40
41my @mpl_out = run(qq{$perl Makefile.PL "PREFIX=../dummy-install"});
42END { rmtree '../dummy-install'; }
43
44cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) ||
45  diag(@mpl_out);
46
47my $makefile = makefile_name();
48ok( grep(/^Writing $makefile for Big::Dummy/,
49         @mpl_out) == 1,
50                                           'Makefile.PL output looks right');
51
52ok( grep(/^Current package is: main$/,
53         @mpl_out) == 1,
54                                           'Makefile.PL run in package main');
55
56ok( -e $makefile,       'Makefile exists' );
57
58# -M is flakey on VMS
59my $mtime = (stat($makefile))[9];
60cmp_ok( $Touch_Time, '<=', $mtime,  '  its been touched' );
61
62END { unlink makefile_name(), makefile_backup() }
63
64my $make = make_run();
65
66{
67    # Supress 'make manifest' noise
68    local $ENV{PERL_MM_MANIFEST_VERBOSE} = 0;
69    my $manifest_out = run("$make manifest");
70    ok( -e 'MANIFEST',      'make manifest created a MANIFEST' );
71    ok( -s 'MANIFEST',      '  its not empty' );
72}
73
74END { unlink 'MANIFEST'; }
75
76
77my $ppd_out = run("$make ppd");
78is( $?, 0,                      '  exited normally' ) || diag $ppd_out;
79ok( open(PPD, 'Big-Dummy.ppd'), '  .ppd file generated' );
80my $ppd_html;
81{ local $/; $ppd_html = <PPD> }
82close PPD;
83like( $ppd_html, qr{^<SOFTPKG NAME="Big-Dummy" VERSION="0.01">}m,
84                                                           '  <SOFTPKG>' );
85like( $ppd_html, qr{^\s*<ABSTRACT>Try "our" hot dog's</ABSTRACT>}m,
86                                                           '  <ABSTRACT>');
87like( $ppd_html,
88      qr{^\s*<AUTHOR>Michael G Schwern &lt;schwern\@pobox.com&gt;</AUTHOR>}m,
89                                                           '  <AUTHOR>'  );
90like( $ppd_html, qr{^\s*<IMPLEMENTATION>}m,          '  <IMPLEMENTATION>');
91like( $ppd_html, qr{^\s*<REQUIRE NAME="strict::" />}m,  '  <REQUIRE>' );
92unlike( $ppd_html, qr{^\s*<REQUIRE NAME="warnings::" />}m,  'no <REQUIRE> for build_require' );
93
94my $archname = $Config{archname};
95if( $] >= 5.008 ) {
96    # XXX This is a copy of the internal logic, so it's not a great test
97    $archname .= "-$Config{PERL_REVISION}.$Config{PERL_VERSION}";
98}
99like( $ppd_html, qr{^\s*<ARCHITECTURE NAME="$archname" />}m,
100                                                           '  <ARCHITECTURE>');
101like( $ppd_html, qr{^\s*<CODEBASE HREF="" />}m,            '  <CODEBASE>');
102like( $ppd_html, qr{^\s*</IMPLEMENTATION>}m,           '  </IMPLEMENTATION>');
103like( $ppd_html, qr{^\s*</SOFTPKG>}m,                      '  </SOFTPKG>');
104END { unlink 'Big-Dummy.ppd' }
105
106
107my $test_out = run("$make test");
108like( $test_out, qr/All tests successful/, 'make test' );
109is( $?, 0,                                 '  exited normally' ) ||
110    diag $test_out;
111
112# Test 'make test TEST_VERBOSE=1'
113my $make_test_verbose = make_macro($make, 'test', TEST_VERBOSE => 1);
114$test_out = run("$make_test_verbose");
115like( $test_out, qr/ok \d+ - TEST_VERBOSE/, 'TEST_VERBOSE' );
116like( $test_out, qr/All tests successful/,  '  successful' );
117is( $?, 0,                                  '  exited normally' ) ||
118    diag $test_out;
119
120
121my $install_out = run("$make install");
122is( $?, 0, 'install' ) || diag $install_out;
123like( $install_out, qr/^Installing /m );
124
125ok( -r '../dummy-install',     '  install dir created' );
126my %files = ();
127find( sub {
128    # do it case-insensitive for non-case preserving OSs
129    my $file = lc $_;
130
131    # VMS likes to put dots on the end of things that don't have them.
132    $file =~ s/\.$// if $Is_VMS;
133
134    $files{$file} = $File::Find::name;
135}, '../dummy-install' );
136ok( $files{'dummy.pm'},     '  Dummy.pm installed' );
137ok( $files{'liar.pm'},      '  Liar.pm installed'  );
138ok( $files{'program'},      '  program installed'  );
139ok( $files{'.packlist'},    '  packlist created'   );
140ok( $files{'perllocal.pod'},'  perllocal.pod created' );
141
142
143SKIP: {
144    skip 'VMS install targets do not preserve $(PREFIX)', 8 if $Is_VMS;
145
146    $install_out = run("$make install PREFIX=elsewhere");
147    is( $?, 0, 'install with PREFIX override' ) || diag $install_out;
148    like( $install_out, qr/^Installing /m );
149
150    ok( -r 'elsewhere',     '  install dir created' );
151    %files = ();
152    find( sub { $files{$_} = $File::Find::name; }, 'elsewhere' );
153    ok( $files{'Dummy.pm'},     '  Dummy.pm installed' );
154    ok( $files{'Liar.pm'},      '  Liar.pm installed'  );
155    ok( $files{'program'},      '  program installed'  );
156    ok( $files{'.packlist'},    '  packlist created'   );
157    ok( $files{'perllocal.pod'},'  perllocal.pod created' );
158    rmtree('elsewhere');
159}
160
161
162SKIP: {
163    skip 'VMS install targets do not preserve $(DESTDIR)', 10 if $Is_VMS;
164
165    $install_out = run("$make install PREFIX= DESTDIR=other");
166    is( $?, 0, 'install with DESTDIR' ) ||
167        diag $install_out;
168    like( $install_out, qr/^Installing /m );
169
170    ok( -d 'other',  '  destdir created' );
171    %files = ();
172    my $perllocal;
173    find( sub {
174        $files{$_} = $File::Find::name;
175    }, 'other' );
176    ok( $files{'Dummy.pm'},     '  Dummy.pm installed' );
177    ok( $files{'Liar.pm'},      '  Liar.pm installed'  );
178    ok( $files{'program'},      '  program installed'  );
179    ok( $files{'.packlist'},    '  packlist created'   );
180    ok( $files{'perllocal.pod'},'  perllocal.pod created' );
181
182    ok( open(PERLLOCAL, $files{'perllocal.pod'} ) ) ||
183        diag("Can't open $files{'perllocal.pod'}: $!");
184    { local $/;
185      unlike(<PERLLOCAL>, qr/other/, 'DESTDIR should not appear in perllocal');
186    }
187    close PERLLOCAL;
188
189# TODO not available in the min version of Test::Harness we require
190#    ok( open(PACKLIST, $files{'.packlist'} ) ) ||
191#        diag("Can't open $files{'.packlist'}: $!");
192#    { local $/;
193#      local $TODO = 'DESTDIR still in .packlist';
194#      unlike(<PACKLIST>, qr/other/, 'DESTDIR should not appear in .packlist');
195#    }
196#    close PACKLIST;
197
198    rmtree('other');
199}
200
201
202SKIP: {
203    skip 'VMS install targets do not preserve $(PREFIX)', 9 if $Is_VMS;
204
205    $install_out = run("$make install PREFIX=elsewhere DESTDIR=other/");
206    is( $?, 0, 'install with PREFIX override and DESTDIR' ) ||
207        diag $install_out;
208    like( $install_out, qr/^Installing /m );
209
210    ok( !-d 'elsewhere',       '  install dir not created' );
211    ok( -d 'other/elsewhere',  '  destdir created' );
212    %files = ();
213    find( sub { $files{$_} = $File::Find::name; }, 'other/elsewhere' );
214    ok( $files{'Dummy.pm'},     '  Dummy.pm installed' );
215    ok( $files{'Liar.pm'},      '  Liar.pm installed'  );
216    ok( $files{'program'},      '  program installed'  );
217    ok( $files{'.packlist'},    '  packlist created'   );
218    ok( $files{'perllocal.pod'},'  perllocal.pod created' );
219    rmtree('other');
220}
221
222
223my $dist_test_out = run("$make disttest");
224is( $?, 0, 'disttest' ) || diag($dist_test_out);
225
226# Test META.yml generation
227use ExtUtils::Manifest qw(maniread);
228
229my $distdir  = 'Big-Dummy-0.01';
230$distdir =~ s/\./_/g if $Is_VMS;
231my $meta_yml = "$distdir/META.yml";
232
233ok( !-f 'META.yml',  'META.yml not written to source dir' );
234ok( -f $meta_yml,    'META.yml written to dist dir' );
235ok( !-e "META_new.yml", 'temp META.yml file not left around' );
236
237SKIP: {
238    # META.yml spec 1.4 was added in 0.11
239    skip "Test::YAML::Meta >= 0.11 required", 2
240      unless eval { require Test::YAML::Meta }   and
241             Test::YAML::Meta->VERSION >= 0.11;
242
243    Test::YAML::Meta::meta_spec_ok($meta_yml);
244}
245
246ok open META, $meta_yml or diag $!;
247my $meta = join '', <META>;
248ok close META;
249
250is $meta, <<"END";
251--- #YAML:1.0
252name:               Big-Dummy
253version:            0.01
254abstract:           Try "our" hot dog's
255author:
256    - Michael G Schwern <schwern\@pobox.com>
257license:            unknown
258distribution_type:  module
259configure_requires:
260    ExtUtils::MakeMaker:  0
261build_requires:
262    warnings:  0
263requires:
264    strict:  0
265no_index:
266    directory:
267        - t
268        - inc
269generated_by:       ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION
270meta-spec:
271    url:      http://module-build.sourceforge.net/META-spec-v1.4.html
272    version:  1.4
273END
274
275my $manifest = maniread("$distdir/MANIFEST");
276# VMS is non-case preserving, so we can't know what the MANIFEST will
277# look like. :(
278_normalize($manifest);
279is( $manifest->{'meta.yml'}, 'Module meta-data (added by MakeMaker)' );
280
281
282# Test NO_META META.yml suppression
283unlink $meta_yml;
284ok( !-f $meta_yml,   'META.yml deleted' );
285@mpl_out = run(qq{$perl Makefile.PL "NO_META=1"});
286cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out);
287my $distdir_out = run("$make distdir");
288is( $?, 0, 'distdir' ) || diag($distdir_out);
289ok( !-f $meta_yml,   'META.yml generation suppressed by NO_META' );
290
291
292# Make sure init_dirscan doesn't go into the distdir
293@mpl_out = run(qq{$perl Makefile.PL "PREFIX=../dummy-install"});
294
295cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' ) || diag(@mpl_out);
296
297ok( grep(/^Writing $makefile for Big::Dummy/, @mpl_out) == 1,
298                                'init_dirscan skipped distdir') ||
299  diag(@mpl_out);
300
301# I know we'll get ignored errors from make here, that's ok.
302# Send STDERR off to oblivion.
303open(SAVERR, ">&STDERR") or die $!;
304open(STDERR, ">",File::Spec->devnull) or die $!;
305
306my $realclean_out = run("$make realclean");
307is( $?, 0, 'realclean' ) || diag($realclean_out);
308
309open(STDERR, ">&SAVERR") or die $!;
310close SAVERR;
311
312
313sub _normalize {
314    my $hash = shift;
315
316    while(my($k,$v) = each %$hash) {
317        delete $hash->{$k};
318        $hash->{lc $k} = $v;
319    }
320}
321