several_authors.t revision 1.3
1#!/usr/bin/perl -w
2
3# This is a test checking various aspects of the optional argument
4# MIN_PERL_VERSION to WriteMakefile.
5
6BEGIN {
7    unshift @INC, 't/lib';
8}
9
10use strict;
11
12use TieOut;
13use MakeMaker::Test::Utils;
14use Config;
15use ExtUtils::MM;
16use Test::More
17    !MM->can_run(make()) && $ENV{PERL_CORE} && $Config{'usecrosscompile'}
18    ? (skip_all => "cross-compiling and make not available")
19    : (tests => 19);
20use File::Path;
21use File::Temp qw[tempdir];
22
23use ExtUtils::MakeMaker;
24my $CM = eval { require CPAN::Meta; };
25
26my $DIRNAME = 'Multiple-Authors';
27my %FILES = (
28    'Makefile.PL'   => <<'END',
29use ExtUtils::MakeMaker;
30WriteMakefile(
31    NAME             => 'Multiple::Authors',
32    AUTHOR           => ['John Doe <jd@example.com>', 'Jane Doe <jd@example.com>'],
33    VERSION_FROM     => 'lib/Multiple/Authors.pm',
34    PREREQ_PM        => { strict => 0 },
35);
36END
37
38    'lib/Multiple/Authors.pm'    => <<'END',
39package Multiple::Authors;
40
41$VERSION = 0.05;
42
43=head1 NAME
44
45Multiple::Authors - several authors
46
47=cut
48
491;
50END
51
52);
53
54# avoid environment variables interfering with our make runs
55delete @ENV{qw(PERL_JSON_BACKEND CPAN_META_JSON_BACKEND PERL_YAML_BACKEND)} if $ENV{PERL_CORE};
56delete @ENV{qw(LIB MAKEFLAGS PERL_CORE)};
57
58my $perl     = which_perl();
59my $make     = make_run();
60my $makefile = makefile_name();
61
62chdir 't';
63perl_lib; # sets $ENV{PERL5LIB} relative to t/
64
65my $tmpdir = tempdir( DIR => '../t', CLEANUP => 1 );
66use Cwd; my $cwd = getcwd; END { chdir $cwd } # so File::Temp can cleanup
67chdir $tmpdir;
68
69hash2files($DIRNAME, \%FILES);
70END {
71    ok( chdir(File::Spec->updir), 'leaving dir' );
72    ok( rmtree($DIRNAME), 'teardown' );
73}
74
75ok( chdir $DIRNAME, "entering dir $DIRNAME" ) ||
76    diag("chdir failed: $!");
77
78note "argument verification"; {
79    my $stdout = tie *STDOUT, 'TieOut';
80    ok( $stdout, 'capturing stdout' );
81    my $warnings = '';
82    local $SIG{__WARN__} = sub {
83        $warnings .= join '', @_;
84    };
85
86    eval {
87        WriteMakefile(
88            NAME             => 'Multiple::Authors',
89            AUTHOR           => ['John Doe <jd@example.com>', 'Jane Doe <jd@example.com>'],
90        );
91    };
92    is( $warnings, '', 'arrayref in AUTHOR does not trigger a warning' );
93    is( $@, '',        '  nor a hard failure' );
94
95}
96
97
98note "argument verification via CONFIGURE"; {
99    my $stdout = tie *STDOUT, 'TieOut';
100    ok( $stdout, 'capturing stdout' );
101    my $warnings = '';
102    local $SIG{__WARN__} = sub {
103        $warnings .= join '', @_;
104    };
105
106    eval {
107        WriteMakefile(
108            NAME             => 'Multiple::Authors',
109            CONFIGURE => sub {
110               return {AUTHOR => 'John Doe <jd@example.com>',};
111            },
112        );
113    };
114    is( $warnings, '', 'scalar in AUTHOR inside CONFIGURE does not trigger a warning' );
115    is( $@, '',        '  nor a hard failure' );
116
117}
118
119
120note "generated files verification"; {
121    unlink $makefile;
122    my @mpl_out = run(qq{$perl Makefile.PL});
123    END { unlink $makefile, makefile_backup() }
124
125    cmp_ok( $?, '==', 0, 'Makefile.PL exiting normally' ) || diag(@mpl_out);
126    ok( -e $makefile, 'Makefile present' );
127}
128
129
130note "ppd output"; {
131    my $ppd_file = 'Multiple-Authors.ppd';
132    my @make_out = run(qq{$make ppd});
133    END { unlink $ppd_file }
134
135    cmp_ok( $?, '==', 0,    'Make ppd exiting normally' ) || diag(@make_out);
136
137    my $ppd_html = slurp($ppd_file);
138    ok( defined($ppd_html), '  .ppd file present' );
139
140    like( $ppd_html, qr{John Doe &lt;jd\@example.com&gt;, Jane Doe &lt;jd\@example.com&gt;},
141                            '  .ppd file content good' );
142}
143
144
145note "META.yml output"; SKIP: {
146    skip 'Failed to load CPAN::Meta', 5 unless $CM;
147    my $distdir  = 'Multiple-Authors-0.05';
148    $distdir =~ s{\.}{_}g if $Is_VMS;
149
150    my $meta_yml = "$distdir/META.yml";
151    my $meta_json = "$distdir/META.json";
152    my @make_out    = run(qq{$make metafile});
153    END { rmtree $distdir if defined $distdir }
154
155    cmp_ok( $?, '==', 0, 'Make metafile exiting normally' ) || diag(@make_out);
156
157    for my $case (
158        ['META.yml', $meta_yml],
159        ['META.json', $meta_json],
160    ) {
161        my ($label, $meta_name) = @$case;
162        ok(
163          my $obj = eval {
164            CPAN::Meta->load_file($meta_name, {lazy_validation => 0})
165          },
166          "$label validates"
167        );
168        is_deeply( [ $obj->authors ],
169          [
170            q{John Doe <jd@example.com>},
171            q{Jane Doe <jd@example.com>},
172          ],
173          "$label content good"
174        );
175    }
176}
177