File Coverage

blib/lib/Dist/Zilla/App/Tester.pm
Criterion Covered Total %
statement 55 65 84.6
branch 1 2 50.0
condition 2 5 40.0
subroutine 16 21 76.1
pod 1 2 50.0
total 75 95 78.9


line stmt bran cond sub pod time code
1             package Dist::Zilla::App::Tester 6.030;
2             # ABSTRACT: testing library for Dist::Zilla::App
3              
4 4     4   230021 use Dist::Zilla::Pragmas;
  4         17  
  4         30  
5              
6 4     4   967 use parent 'App::Cmd::Tester::CaptureExternal';
  4         566  
  4         45  
7 4     4   111367 use App::Cmd::Tester 0.306 (); # result_class, ->app
  4         68  
  4         95  
8              
9 4     4   1492 use Dist::Zilla::App;
  4         12  
  4         37  
10 4     4   4387 use File::Copy::Recursive qw(dircopy);
  4         25850  
  4         287  
11 4     4   1218 use File::pushd ();
  4         3477  
  4         101  
12 4     4   53 use File::Spec;
  4         11  
  4         87  
13 4     4   50 use File::Temp;
  4         10  
  4         389  
14 4     4   1196 use Dist::Zilla::Path;
  4         10  
  4         45  
15              
16 4     4   1246 use Sub::Exporter::Util ();
  4         12  
  4         193  
17 4         17 use Sub::Exporter -setup => {
18             exports => [ test_dzil => Sub::Exporter::Util::curry_method() ],
19             groups => [ default => [ qw(test_dzil) ] ],
20 4     4   24 };
  4         9  
21              
22 4     4   2013 use namespace::autoclean -except => 'import';
  4         9  
  4         25  
23              
24 20     20 0 26160 sub result_class { 'Dist::Zilla::App::Tester::Result' }
25              
26             sub test_dzil {
27 20     20 1 903839 my ($self, $source, $argv, $arg) = @_;
28 20   50     205 $arg ||= {};
29              
30 20 50       93 local @INC = map {; ref($_) ? $_ : File::Spec->rel2abs($_) } @INC;
  221         2322  
31              
32 20   33     251 my $tmpdir = $arg->{tempdir} || File::Temp::tempdir(CLEANUP => 1);
33 20         12369 my $root = path($tmpdir)->child('source');
34 20         2370 $root->mkpath;
35              
36 20         11666 dircopy($source, $root);
37              
38 20         91709 my $wd = File::pushd::pushd($root);
39              
40 20         3348 local $ENV{DZIL_TESTING} = 1;
41 20         303 my $result = $self->test_app('Dist::Zilla::App' => $argv);
42 20         316 $result->{tempdir} = $tmpdir;
43              
44 20         387 return $result;
45             }
46              
47             {
48             package Dist::Zilla::App::Tester::Result 6.030;
49              
50 4     4   3109 BEGIN { our @ISA = qw(App::Cmd::Tester::Result); }
51              
52             sub tempdir {
53 0     0   0 my ($self) = @_;
54 0         0 return $self->{tempdir};
55             }
56              
57             sub zilla {
58 0     0   0 my ($self) = @_;
59 0         0 return $self->app->zilla;
60             }
61              
62             sub build_dir {
63 0     0   0 my ($self) = @_;
64 0         0 return $self->zilla->built_in;
65             }
66              
67             sub clear_log_events {
68 0     0   0 my ($self) = @_;
69 0         0 $self->app->zilla->logger->logger->clear_events;
70             }
71              
72             sub log_events {
73 0     0   0 my ($self) = @_;
74 0         0 $self->app->zilla->logger->logger->events;
75             }
76              
77             sub log_messages {
78 1     1   2438 my ($self) = @_;
79 1         13 [ map {; $_->{message} } @{ $self->app->zilla->logger->logger->events } ];
  9         92  
  1         29  
80             }
81             }
82              
83             #pod =head1 DESCRIPTION
84             #pod
85             #pod This module exports only one function, C<test_dzil>.
86             #pod
87             #pod =head2 C<test_dzil>
88             #pod
89             #pod This function is used to test L<Dist::Zilla::App>.
90             #pod It receives two mandatory options. The first is the path to a Dist::Zilla-based
91             #pod distribution. The second, an array reference to a list of arguments.
92             #pod
93             #pod The third optional argument is a hash reference, with further options. At the moment
94             #pod the only supported option is c<tempdir>.
95             #pod
96             #pod It returns a L<Dist::Zilla::App::Tester::Result>, that inherits from
97             #pod L<App::Cmd::Tester::Result>. Typical methods called from this result are:
98             #pod
99             #pod =over 4
100             #pod
101             #pod =item C<output>
102             #pod
103             #pod The output of running dzil;
104             #pod
105             #pod =item C<tempdir>
106             #pod
107             #pod The folder used for temporary files.
108             #pod
109             #pod =item C<build_dir>
110             #pod
111             #pod The folder where the distribution was built.
112             #pod
113             #pod =back
114             #pod
115             #pod =cut
116              
117             1;
118              
119             __END__
120              
121             =pod
122              
123             =encoding UTF-8
124              
125             =head1 NAME
126              
127             Dist::Zilla::App::Tester - testing library for Dist::Zilla::App
128              
129             =head1 VERSION
130              
131             version 6.030
132              
133             =head1 DESCRIPTION
134              
135             This module exports only one function, C<test_dzil>.
136              
137             =head2 C<test_dzil>
138              
139             This function is used to test L<Dist::Zilla::App>.
140             It receives two mandatory options. The first is the path to a Dist::Zilla-based
141             distribution. The second, an array reference to a list of arguments.
142              
143             The third optional argument is a hash reference, with further options. At the moment
144             the only supported option is c<tempdir>.
145              
146             It returns a L<Dist::Zilla::App::Tester::Result>, that inherits from
147             L<App::Cmd::Tester::Result>. Typical methods called from this result are:
148              
149             =over 4
150              
151             =item C<output>
152              
153             The output of running dzil;
154              
155             =item C<tempdir>
156              
157             The folder used for temporary files.
158              
159             =item C<build_dir>
160              
161             The folder where the distribution was built.
162              
163             =back
164              
165             =head1 PERL VERSION
166              
167             This module should work on any version of perl still receiving updates from
168             the Perl 5 Porters. This means it should work on any version of perl released
169             in the last two to three years. (That is, if the most recently released
170             version is v5.40, then this module should work on both v5.40 and v5.38.)
171              
172             Although it may work on older versions of perl, no guarantee is made that the
173             minimum required version will not be increased. The version may be increased
174             for any reason, and there is no promise that patches will be accepted to lower
175             the minimum required perl.
176              
177             =head1 AUTHOR
178              
179             Ricardo SIGNES 😏 <cpan@semiotic.systems>
180              
181             =head1 COPYRIGHT AND LICENSE
182              
183             This software is copyright (c) 2023 by Ricardo SIGNES.
184              
185             This is free software; you can redistribute it and/or modify it under
186             the same terms as the Perl 5 programming language system itself.
187              
188             =cut