File Coverage

blib/lib/Dist/Zilla/Plugin/Test/CheckDeps.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod 0 1 0.0
total 11 12 91.6


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Test::CheckDeps; # git description: v0.012-22-g830c81b
2             # vim: set ts=8 sts=4 sw=4 tw=115 et :
3              
4             our $VERSION = '0.013';
5              
6 3     3   2821982 use Moose;
  3         6  
  3         21  
7             extends qw/Dist::Zilla::Plugin::InlineFiles/;
8             with qw/Dist::Zilla::Role::TextTemplate Dist::Zilla::Role::PrereqSource/;
9 3     3   18082 use namespace::autoclean;
  3         6  
  3         36  
10              
11             has todo_when => (
12             is => 'ro',
13             isa => 'Str',
14             default => '0', # special value for 'insert no special code at all'
15             );
16              
17             has fatal => (
18             is => 'ro',
19             isa => 'Bool',
20             default => 0,
21             );
22              
23             has level => (
24             is => 'ro',
25             isa => 'Str',
26             lazy => 1,
27             default => 'classic',
28             );
29              
30             has filename => (
31             is => 'ro',
32             isa => 'Str',
33             default => 't/00-check-deps.t',
34             );
35              
36             around dump_config => sub {
37             my $orig = shift;
38             my $self = shift;
39              
40             my $config = $self->$orig;
41              
42             $config->{+__PACKAGE__} = {
43             (map { $_ => $self->$_ } qw(todo_when level filename)),
44             fatal => $self->fatal ? 1 : 0,
45             };
46              
47             return $config;
48             };
49              
50             around add_file => sub {
51             my ($orig, $self, $file) = @_;
52              
53             return $self->$orig(
54             Dist::Zilla::File::InMemory->new(
55             name => $self->filename,
56             content => $self->fill_in_string($file->content,
57             {
58             dist => \($self->zilla),
59             plugin => \$self,
60             todo_when => $self->todo_when,
61             fatal => $self->fatal,
62             level => $self->level,
63             })
64             )
65             );
66             };
67              
68             sub register_prereqs {
69 3     3 0 15299 my $self = shift;
70 3         90 $self->zilla->register_prereqs({ phase => 'test' }, 'Test::More' => '0.94', 'Test::CheckDeps' => '0.010');
71             }
72              
73             __PACKAGE__->meta->make_immutable;
74              
75             # ABSTRACT: Check for presence of dependencies
76              
77             #pod =pod
78             #pod
79             #pod =head1 SYNOPSIS
80             #pod
81             #pod [Test::CheckDeps]
82             #pod fatal = 0 ; default
83             #pod level = classic
84             #pod
85             #pod =head1 DESCRIPTION
86             #pod
87             #pod This module adds a test that assures all dependencies have been installed properly. If requested, it can bail out all testing on error.
88             #pod
89             #pod This plugin accepts the following options:
90             #pod
91             #pod =for stopwords TODO
92             #pod
93             #pod =over 4
94             #pod
95             #pod =item * C<todo_when>: a code string snippet (evaluated when the test is run)
96             #pod to indicate when failing tests should be considered L<TODO|Test::More/Conditional tests>,
97             #pod rather than genuine fails -- default is '0' (tests are never C<TODO>).
98             #pod
99             #pod Other suggested values are:
100             #pod
101             #pod todo_when = !$ENV{AUTHOR_TESTING} && !$ENV{AUTOMATED_TESTING}
102             #pod todo_when = $^V < '5.012' ; CPAN.pm didn't reliably read META.* before this
103             #pod
104             #pod =item * C<fatal>: if true, C<BAIL_OUT> is called if the tests fail. Defaults
105             #pod to false.
106             #pod
107             #pod =item * C<level>: passed to C<check_dependencies> in L<Test::CheckDeps>.
108             #pod (Defaults to C<classic>.)
109             #pod
110             #pod =item * C<filename>: the name of the generated file. Defaults to
111             #pod F<t/00-check-deps.t>.
112             #pod
113             #pod =back
114             #pod
115             #pod =for Pod::Coverage register_prereqs
116             #pod
117             #pod =cut
118              
119             =pod
120              
121             =encoding UTF-8
122              
123             =head1 NAME
124              
125             Dist::Zilla::Plugin::Test::CheckDeps - Check for presence of dependencies
126              
127             =head1 VERSION
128              
129             version 0.013
130              
131             =head1 SYNOPSIS
132              
133             [Test::CheckDeps]
134             fatal = 0 ; default
135             level = classic
136              
137             =head1 DESCRIPTION
138              
139             This module adds a test that assures all dependencies have been installed properly. If requested, it can bail out all testing on error.
140              
141             This plugin accepts the following options:
142              
143             =for stopwords TODO
144              
145             =over 4
146              
147             =item * C<todo_when>: a code string snippet (evaluated when the test is run)
148             to indicate when failing tests should be considered L<TODO|Test::More/Conditional tests>,
149             rather than genuine fails -- default is '0' (tests are never C<TODO>).
150              
151             Other suggested values are:
152              
153             todo_when = !$ENV{AUTHOR_TESTING} && !$ENV{AUTOMATED_TESTING}
154             todo_when = $^V < '5.012' ; CPAN.pm didn't reliably read META.* before this
155              
156             =item * C<fatal>: if true, C<BAIL_OUT> is called if the tests fail. Defaults
157             to false.
158              
159             =item * C<level>: passed to C<check_dependencies> in L<Test::CheckDeps>.
160             (Defaults to C<classic>.)
161              
162             =item * C<filename>: the name of the generated file. Defaults to
163             F<t/00-check-deps.t>.
164              
165             =back
166              
167             =for Pod::Coverage register_prereqs
168              
169             =head1 AUTHOR
170              
171             Leon Timmermans <leont@cpan.org>
172              
173             =head1 CONTRIBUTORS
174              
175             =for stopwords Karen Etheridge Leon Timmermans Brendan Byrd
176              
177             =over 4
178              
179             =item *
180              
181             Karen Etheridge <ether@cpan.org>
182              
183             =item *
184              
185             Leon Timmermans <fawaka@gmail.com>
186              
187             =item *
188              
189             Brendan Byrd <GitHub@ResonatorSoft.org>
190              
191             =back
192              
193             =head1 COPYRIGHT AND LICENSE
194              
195             This software is copyright (c) 2011 by Leon Timmermans.
196              
197             This is free software; you can redistribute it and/or modify it under
198             the same terms as the Perl 5 programming language system itself.
199              
200             =cut
201              
202             __DATA__
203             ___[ test-checkdeps ]___
204             use strict;
205             use warnings;
206              
207             # this test was generated with {{ ref($plugin) . ' ' . $plugin->VERSION }}
208              
209             use Test::More 0.94;
210             {{
211             my $use = 'use Test::CheckDeps 0.010;';
212              
213             # todo_when = 0 is treated as a special default, backwards-compatible case
214             $use = "BEGIN {\n ($todo_when) && eval \"" . $use
215             . " 1\"\n or plan skip_all => '!!! Test::CheckDeps required for checking dependencies -- failure to satisfy specified prerequisites!';\n}\n"
216             . $use
217             if $todo_when ne '0';
218             $use
219             }}
220              
221             {{
222             $todo_when eq '0'
223             ? ''
224             : "local \$TODO = 'these tests are not fatal when $todo_when' if (${todo_when});\n"
225             . 'my $builder = Test::Builder->new;' . "\n"
226             . 'my $todo_output_orig = $builder->todo_output;' . "\n"
227             . '$builder->todo_output($builder->failure_output);' . "\n";
228             }}
229             check_dependencies('{{ $level }}');
230             {{
231             $todo_when ne '0' ? "\$builder->todo_output(\$todo_output_orig);\n" : '';
232             }}
233              
234             if ({{ $fatal }}) {
235             BAIL_OUT("Missing dependencies") if !Test::More->builder->is_passing;
236             }
237              
238             done_testing;