File Coverage

blib/lib/Dist/Zilla/Plugin/Author/Plicease/Tests.pm
Criterion Covered Total %
statement 23 84 27.3
branch 0 26 0.0
condition 0 6 0.0
subroutine 8 13 61.5
pod 0 5 0.0
total 31 134 23.1


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