File Coverage

blib/lib/Dist/Zilla/Plugin/Author/Plicease/Tests.pm
Criterion Covered Total %
statement 23 76 30.2
branch 0 24 0.0
condition 0 6 0.0
subroutine 8 13 61.5
pod 0 5 0.0
total 31 124 25.0


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Author::Plicease::Tests 2.75 {
2              
3 1     1   1507 use 5.020;
  1         4  
4 1     1   7 use Moose;
  1         3  
  1         7  
5 1     1   7789 use File::chdir;
  1         3273  
  1         120  
6 1     1   8 use File::Path qw( make_path );
  1         4  
  1         48  
7 1     1   8 use Path::Tiny qw( path );
  1         3  
  1         53  
8 1     1   7 use Sub::Exporter::ForMethods qw( method_installer );
  1         2  
  1         12  
9 1     1   261 use Data::Section { installer => method_installer }, -setup;
  1         3  
  1         5  
10 1     1   1011 use experimental qw( postderef );
  1         2  
  1         8  
11              
12             # ABSTRACT: add author only release tests to xt/release
13              
14              
15             with 'Dist::Zilla::Role::FileGatherer';
16             with 'Dist::Zilla::Role::BeforeBuild';
17             with 'Dist::Zilla::Role::InstallTool';
18             with 'Dist::Zilla::Role::TestRunner';
19              
20 0     0 0   sub mvp_multivalue_args { qw( diag diag_preamble ) }
21              
22             has diag => (
23             is => 'ro',
24             default => sub { [] },
25             );
26              
27             has diag_preamble => (
28             is => 'ro',
29             default => sub { [] },
30             );
31              
32             has _diag_content => (
33             is => 'rw',
34             isa => 'Str',
35             default => '',
36             );
37              
38             has test2_v0 => (
39             is => 'ro',
40             isa => 'Int',
41             default => 0,
42             );
43              
44             sub gather_files
45             {
46 0     0 0   my($self) = @_;
47              
48 0           require Dist::Zilla::File::InMemory;
49              
50             $self->add_file(
51             Dist::Zilla::File::InMemory->new(
52             name => $_,
53 0           content => ${ $self->section_data($_) },
54             )
55 0           ) for qw( xt/author/strict.t
56             xt/author/eol.t
57             xt/author/pod.t
58             xt/author/no_tabs.t
59             xt/author/pod_coverage.t
60             xt/author/pod_spelling_common.t
61             xt/author/pod_spelling_system.t
62             xt/author/version.t
63             xt/release/changes.t
64             xt/release/fixme.t );
65             }
66              
67             sub before_build
68             {
69 0     0 0   my($self) = @_;
70 0 0         my $content = ${ $self->section_data( $self->test2_v0 ? 't/00_xdiag.t' : 't/00_diag.t' ) };
  0            
71 0           $content =~ s{## PREAMBLE ##}{join "\n", map { s/^\| //; $_ } $self->diag_preamble->@*}e;
  0            
  0            
  0            
72 0           $self->_diag_content($content);
73             }
74              
75             # not really an installer, but we have to create a list
76             # of the prereqs / suggested modules after the prereqs
77             # have been calculated
78             sub setup_installer
79             {
80 0     0 0   my($self) = @_;
81              
82 0           my %list;
83 0           my $prereqs = $self->zilla->prereqs->as_string_hash;
84 0           foreach my $phase (keys %$prereqs)
85             {
86 0 0         next if $phase eq 'develop';
87 0           foreach my $type (keys $prereqs->{$phase}->%*)
88             {
89 0           foreach my $module (keys $prereqs->{$phase}->{$type}->%*)
90             {
91 0 0         next if $module =~ /^(perl|strict|warnings|base)$/;
92 0           $list{$module}++;
93             }
94             }
95             }
96              
97 0 0         if($list{'JSON::MaybeXS'})
98             {
99 0           $list{'JSON::PP'}++;
100 0           $list{'JSON::XS'}++;
101             }
102              
103 0 0         if(my($alien) = grep { $_->isa('Dist::Zilla::Plugin::Alien') } $self->zilla->plugins->@*)
  0            
104             {
105 0           $list{$_}++ foreach keys $alien->module_build_args->{alien_bin_requires}->%*;
106             }
107              
108 0           foreach my $lib ($self->diag->@*)
109             {
110 0 0         if($lib =~ /^-(.*)$/)
    0          
111             {
112 0           delete $list{$1};
113             }
114             elsif($lib =~ /^\+(.*)$/)
115             {
116 0           $list{$1}++;
117             }
118             else
119             {
120 0           $self->log_fatal('diagnostic override must be prefixed with + or -');
121             }
122             }
123              
124 0           my $code = '';
125              
126 0 0         $code = "BEGIN { eval q{ use EV; } }\n" if $list{EV};
127 0           $code .= '$modules{$_} = $_ for qw(' . "\n";
128 0           $code .= join "\n", map { " $_" } sort keys %list;
  0            
129 0           $code .= "\n);\n";
130 0 0 0       $code .= "eval q{ require Test::Tester; };" if $list{'Test::Builder'} && $list{'Test::Tester'};
131              
132 0           my($file) = grep { $_->name eq 't/00_diag.t' } $self->zilla->files->@*;
  0            
133              
134 0           my $content = $self->_diag_content;
135 0           $content =~ s{## GENERATE ##}{$code};
136              
137 0 0         if($file)
138             {
139 0           $file->content($content);
140             }
141             else
142             {
143 0           $file = Dist::Zilla::File::InMemory->new({
144             name => 't/00_diag.t',
145             content => $content
146             });
147 0           $self->add_file($file);
148             }
149              
150 0           $self->zilla->root->child(qw( t 00_diag.t ))->spew_raw($content);
151             }
152              
153             sub test
154             {
155 0     0 0   my($self, $target) = @_;
156 0 0 0       return if defined $ENV{CI} && $ENV{CI} =~ /^true$/i;
157 0           system 'prove', '-br', 'xt';
158 0 0         $self->log_fatal('release test failure') unless $? == 0;
159             }
160              
161             __PACKAGE__->meta->make_immutable;
162              
163             }
164              
165             1;
166              
167              
168             package Dist::Zilla::Plugin::Author::Plicease::Tests;
169              
170             =pod
171              
172             =encoding UTF-8
173              
174             =head1 NAME
175              
176             Dist::Zilla::Plugin::Author::Plicease::Tests - add author only release tests to xt/release
177              
178             =head1 VERSION
179              
180             version 2.75
181              
182             =head1 SYNOPSIS
183              
184             [Author::Plicease::Tests]
185             diag = +Acme::Override::INET
186             diag = +IO::Socket::INET
187             diag = +IO::SOCKET::IP
188             diag = -EV
189              
190             =head1 SEE ALSO
191              
192             =over 4
193              
194             =item L<Dist::Zilla>
195              
196             =item L<Dist::Zilla::PluginBundle::Author::Plicease>
197              
198             =back
199              
200             =head1 AUTHOR
201              
202             Graham Ollis <plicease@cpan.org>
203              
204             =head1 COPYRIGHT AND LICENSE
205              
206             This software is copyright (c) 2012-2022 by Graham Ollis.
207              
208             This is free software; you can redistribute it and/or modify it under
209             the same terms as the Perl 5 programming language system itself.
210              
211             =cut
212              
213             __DATA__
214              
215             __[ t/00_diag.t ]__
216             use strict;
217             use warnings;
218             use Config;
219             use Test::More tests => 1;
220              
221             # This .t file is generated.
222             # make changes instead to dist.ini
223              
224             my %modules;
225             my $post_diag;
226              
227             ## GENERATE ##
228             ## PREAMBLE ##
229              
230             my @modules = sort keys %modules;
231              
232             sub spacer ()
233             {
234             diag '';
235             diag '';
236             diag '';
237             }
238              
239             pass 'okay';
240              
241             my $max = 1;
242             $max = $_ > $max ? $_ : $max for map { length $_ } @modules;
243             our $format = "%-${max}s %s";
244              
245             spacer;
246              
247             my @keys = sort grep /(MOJO|PERL|\A(LC|HARNESS)_|\A(SHELL|LANG)\Z)/i, keys %ENV;
248              
249             if(@keys > 0)
250             {
251             diag "$_=$ENV{$_}" for @keys;
252              
253             if($ENV{PERL5LIB})
254             {
255             spacer;
256             diag "PERL5LIB path";
257             diag $_ for split $Config{path_sep}, $ENV{PERL5LIB};
258              
259             }
260             elsif($ENV{PERLLIB})
261             {
262             spacer;
263             diag "PERLLIB path";
264             diag $_ for split $Config{path_sep}, $ENV{PERLLIB};
265             }
266              
267             spacer;
268             }
269              
270             diag sprintf $format, 'perl', "$] $^O $Config{archname}";
271              
272             foreach my $module (@modules)
273             {
274             my $pm = "$module.pm";
275             $pm =~ s{::}{/}g;
276             if(eval { require $pm; 1 })
277             {
278             my $ver = eval { $module->VERSION };
279             $ver = 'undef' unless defined $ver;
280             diag sprintf $format, $module, $ver;
281             }
282             else
283             {
284             diag sprintf $format, $module, '-';
285             }
286             }
287              
288             if($post_diag)
289             {
290             spacer;
291             $post_diag->();
292             }
293              
294             spacer;
295              
296             __[ t/00_xdiag.t ]__
297             use Test2::V0 -no_srand => 1;
298             use Config;
299              
300             eval { require 'Test/More.pm' };
301              
302             # This .t file is generated.
303             # make changes instead to dist.ini
304              
305             my %modules;
306             my $post_diag;
307              
308             ## GENERATE ##
309             ## PREAMBLE ##
310              
311             my @modules = sort keys %modules;
312              
313             sub spacer ()
314             {
315             diag '';
316             diag '';
317             diag '';
318             }
319              
320             pass 'okay';
321              
322             my $max = 1;
323             $max = $_ > $max ? $_ : $max for map { length $_ } @modules;
324             our $format = "%-${max}s %s";
325              
326             spacer;
327              
328             my @keys = sort grep /(MOJO|PERL|\A(LC|HARNESS)_|\A(SHELL|LANG)\Z)/i, keys %ENV;
329              
330             if(@keys > 0)
331             {
332             diag "$_=$ENV{$_}" for @keys;
333              
334             if($ENV{PERL5LIB})
335             {
336             spacer;
337             diag "PERL5LIB path";
338             diag $_ for split $Config{path_sep}, $ENV{PERL5LIB};
339              
340             }
341             elsif($ENV{PERLLIB})
342             {
343             spacer;
344             diag "PERLLIB path";
345             diag $_ for split $Config{path_sep}, $ENV{PERLLIB};
346             }
347              
348             spacer;
349             }
350              
351             diag sprintf $format, 'perl', "$] $^O $Config{archname}";
352              
353             foreach my $module (sort @modules)
354             {
355             my $pm = "$module.pm";
356             $pm =~ s{::}{/}g;
357             if(eval { require $pm; 1 })
358             {
359             my $ver = eval { $module->VERSION };
360             $ver = 'undef' unless defined $ver;
361             diag sprintf $format, $module, $ver;
362             }
363             else
364             {
365             diag sprintf $format, $module, '-';
366             }
367             }
368              
369             if($post_diag)
370             {
371             spacer;
372             $post_diag->();
373             }
374              
375             spacer;
376              
377             done_testing;
378              
379             __[ xt/author/strict.t ]__
380             use strict;
381             use warnings;
382             use Test::More;
383             BEGIN {
384             plan skip_all => 'test requires Test::Strict'
385             unless eval q{ use Test::Strict; 1 };
386             };
387             use Test::Strict;
388             use FindBin;
389             use File::Spec;
390              
391             chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir));
392              
393             unshift @Test::Strict::MODULES_ENABLING_STRICT,
394             'ozo',
395             'Test2::Bundle::SIPS',
396             'Test2::V0',
397             'Test2::Bundle::Extended';
398             note "enabling strict = $_" for @Test::Strict::MODULES_ENABLING_STRICT;
399              
400             all_perl_files_ok( grep { -e $_ } qw( bin lib t Makefile.PL ));
401              
402              
403             __[ xt/author/eol.t ]__
404             use strict;
405             use warnings;
406             use Test::More;
407             BEGIN {
408             plan skip_all => 'test requires Test::EOL'
409             unless eval q{ use Test::EOL; 1 };
410             };
411             use Test::EOL;
412             use FindBin;
413             use File::Spec;
414              
415             chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir));
416              
417             all_perl_files_ok(grep { -e $_ } qw( bin lib t Makefile.PL ));
418              
419              
420             __[ xt/author/no_tabs.t ]__
421             use strict;
422             use warnings;
423             use Test::More;
424             BEGIN {
425             plan skip_all => 'test requires Test::NoTabs'
426             unless eval q{ use Test::NoTabs; 1 };
427             };
428             use Test::NoTabs;
429             use FindBin;
430             use File::Spec;
431              
432             chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir));
433              
434             all_perl_files_ok( grep { -e $_ } qw( bin lib t Makefile.PL ));
435              
436              
437             __[ xt/author/pod.t ]__
438             use strict;
439             use warnings;
440             use Test::More;
441             BEGIN {
442             plan skip_all => 'test requires Test::Pod'
443             unless eval q{ use Test::Pod; 1 };
444             };
445             use Test::Pod;
446             use FindBin;
447             use File::Spec;
448              
449             chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir));
450              
451             all_pod_files_ok( grep { -e $_ } qw( bin lib ));
452              
453              
454             __[ xt/release/changes.t ]__
455             use strict;
456             use warnings;
457             use Test::More;
458             BEGIN {
459             plan skip_all => 'test requires Test::CPAN::Changes'
460             unless eval q{ use Test::CPAN::Changes; 1 };
461             };
462             use Test::CPAN::Changes;
463             use FindBin;
464             use File::Spec;
465              
466             chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir));
467              
468             do {
469             my $old = \&Test::Builder::carp;
470             my $new = sub {
471             my($self, @messages) = @_;
472             return if $messages[0] =~ /^Date ".*" is not in the recommend format/;
473             $old->($self, @messages);
474             };
475             no warnings 'redefine';
476             *Test::Builder::carp = $new;
477             };
478              
479             changes_file_ok;
480              
481             done_testing;
482              
483              
484             __[ xt/release/fixme.t ]__
485             use strict;
486             use warnings;
487             use Test::More;
488             BEGIN {
489             plan skip_all => 'test requires Test::Fixme'
490             unless eval q{ use Test::Fixme 0.14; 1 };
491             };
492             use Test::Fixme 0.07;
493             use FindBin;
494             use File::Spec;
495              
496             chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir));
497              
498             run_tests(
499             match => qr/FIXME/,
500             where => [ grep { -e $_ } qw( bin lib t Makefile.PL Build.PL )],
501             warn => 1,
502             );
503              
504              
505             __[ xt/author/pod_coverage.t ]__
506             use strict;
507             use warnings;
508             use Test::More;
509             BEGIN {
510             plan skip_all => 'test requires 5.010 or better'
511             unless $] >= 5.010;
512             plan skip_all => 'test requires Test::Pod::Coverage'
513             unless eval q{ use Test::Pod::Coverage; 1 };
514             plan skip_all => 'test requires YAML'
515             unless eval q{ use YAML; 1; };
516             plan skip_all => 'test does not always work in cip check'
517             if defined $ENV{CIPSTATIC} && $ENV{CIPSTATIC} eq 'true';
518             };
519             use Test::Pod::Coverage;
520             use YAML qw( LoadFile );
521             use FindBin;
522             use File::Spec;
523              
524             my $config_filename = File::Spec->catfile(
525             $FindBin::Bin, File::Spec->updir, File::Spec->updir, 'author.yml'
526             );
527              
528             my $config;
529             $config = LoadFile($config_filename)
530             if -r $config_filename;
531              
532             plan skip_all => 'disabled' if $config->{pod_coverage}->{skip};
533              
534             chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir));
535              
536             my @private_classes;
537             my %private_methods;
538              
539             push $config->{pod_coverage}->{private}->@*,
540             'Alien::.*::Install::Files#Inline';
541              
542             foreach my $private ($config->{pod_coverage}->{private}->@*)
543             {
544             my($class,$method) = split /#/, $private;
545             if(defined $class && $class ne '')
546             {
547             my $regex = eval 'qr{^' . $class . '$}';
548             if(defined $method && $method ne '')
549             {
550             push @private_classes, { regex => $regex, method => $method };
551             }
552             else
553             {
554             push @private_classes, { regex => $regex, all => 1 };
555             }
556             }
557             elsif(defined $method && $method ne '')
558             {
559             $private_methods{$_} = 1 for split /,/, $method;
560             }
561             }
562              
563             my @classes = all_modules;
564              
565             plan tests => scalar @classes;
566              
567             foreach my $class (@classes)
568             {
569             SKIP: {
570             my($is_private_class) = map { 1 } grep { $class =~ $_->{regex} && $_->{all} } @private_classes;
571             skip "private class: $class", 1 if $is_private_class;
572              
573             my %methods = map {; $_ => 1 } map { split /,/, $_->{method} } grep { $class =~ $_->{regex} } @private_classes;
574             $methods{$_} = 1 for keys %private_methods;
575              
576             my $also_private = eval 'qr{^' . join('|', keys %methods ) . '$}';
577              
578             pod_coverage_ok $class, { also_private => [$also_private] };
579             };
580             }
581              
582              
583             __[ xt/author/pod_spelling_common.t ]__
584             use strict;
585             use warnings;
586             use Test::More;
587             BEGIN {
588             plan skip_all => 'test requires Test::Pod::Spelling::CommonMistakes'
589             unless eval q{ use Test::Pod::Spelling::CommonMistakes; 1 };
590             plan skip_all => 'test requires YAML'
591             unless eval q{ use YAML qw( LoadFile ); 1 };
592             };
593             use Test::Pod::Spelling::CommonMistakes;
594             use FindBin;
595             use File::Spec;
596              
597             my $config_filename = File::Spec->catfile(
598             $FindBin::Bin, File::Spec->updir, File::Spec->updir, 'author.yml'
599             );
600              
601             my $config;
602             $config = LoadFile($config_filename)
603             if -r $config_filename;
604              
605             plan skip_all => 'disabled' if $config->{pod_spelling_common}->{skip};
606              
607             chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir));
608              
609             # TODO: test files in bin too.
610             all_pod_files_ok;
611              
612              
613             __[ xt/author/pod_spelling_system.t ]__
614             use strict;
615             use warnings;
616             use Test::More;
617             BEGIN {
618             plan skip_all => 'test requires Test::Spelling'
619             unless eval q{ use Test::Spelling; 1 };
620             plan skip_all => 'test requires YAML'
621             unless eval q{ use YAML; 1; };
622             };
623             use Test::Spelling;
624             use YAML qw( LoadFile );
625             use FindBin;
626             use File::Spec;
627              
628             my $config_filename = File::Spec->catfile(
629             $FindBin::Bin, File::Spec->updir, File::Spec->updir, 'author.yml'
630             );
631              
632             my $config;
633             $config = LoadFile($config_filename)
634             if -r $config_filename;
635              
636             plan skip_all => 'disabled' if $config->{pod_spelling_system}->{skip};
637              
638             chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir));
639              
640             add_stopwords($config->{pod_spelling_system}->{stopwords}->@*);
641             add_stopwords(qw(
642             Plicease
643             stdout
644             stderr
645             stdin
646             subref
647             loopback
648             username
649             os
650             Ollis
651             Mojolicious
652             plicease
653             CPAN
654             reinstall
655             TODO
656             filename
657             filenames
658             login
659             callback
660             callbacks
661             standalone
662             VMS
663             hostname
664             hostnames
665             TCP
666             UDP
667             IP
668             API
669             MSWin32
670             OpenBSD
671             FreeBSD
672             NetBSD
673             unencrypted
674             WebSocket
675             WebSockets
676             timestamp
677             timestamps
678             poney
679             BackPAN
680             portably
681             RedHat
682             AIX
683             BSD
684             XS
685             FFI
686             perlish
687             optimizations
688             subdirectory
689             RESTful
690             SQLite
691             JavaScript
692             dir
693             plugins
694             munge
695             jQuery
696             namespace
697             PDF
698             PDFs
699             usernames
700             DBI
701             pluggable
702             APIs
703             SSL
704             JSON
705             YAML
706             uncommented
707             Solaris
708             OpenVMS
709             URI
710             URL
711             CGI
712             ));
713             all_pod_files_spelling_ok;
714              
715              
716             __[ xt/author/version.t ]__
717             use strict;
718             use warnings;
719             use Test::More;
720             use FindBin ();
721             BEGIN {
722              
723             plan skip_all => "test requires Test::Version 2.00"
724             unless eval q{
725             use Test::Version 2.00 qw( version_all_ok ), {
726             has_version => 1,
727             filename_match => sub { $_[0] !~ m{/(ConfigData|Install/Files)\.pm$} },
728             };
729             1
730             };
731              
732             plan skip_all => 'test requires YAML'
733             unless eval q{ use YAML; 1; };
734             }
735              
736             use YAML qw( LoadFile );
737             use FindBin;
738             use File::Spec;
739              
740             my $config_filename = File::Spec->catfile(
741             $FindBin::Bin, File::Spec->updir, File::Spec->updir, 'author.yml'
742             );
743              
744             my $config;
745             $config = LoadFile($config_filename)
746             if -r $config_filename;
747              
748             if($config->{version}->{dir})
749             {
750             note "using dir " . $config->{version}->{dir}
751             }
752              
753             version_all_ok($config->{version}->{dir} ? ($config->{version}->{dir}) : ());
754             done_testing;
755