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.037;
2             # ABSTRACT: testing library for Dist::Zilla::App
3              
4 4     4   239360 use Dist::Zilla::Pragmas;
  4         10  
  4         21  
5              
6 4     4   936 use parent 'App::Cmd::Tester::CaptureExternal';
  4         639  
  4         29  
7 4     4   124980 use App::Cmd::Tester 0.306 (); # result_class, ->app
  4         69  
  4         94  
8              
9 4     4   1283 use Dist::Zilla::App;
  4         15  
  4         43  
10 4     4   2611 use File::Copy::Recursive qw(dircopy);
  4         22966  
  4         301  
11 4     4   1015 use File::pushd ();
  4         2653  
  4         91  
12 4     4   21 use File::Spec;
  4         7  
  4         70  
13 4     4   16 use File::Temp;
  4         7  
  4         333  
14 4     4   980 use Dist::Zilla::Path;
  4         11  
  4         25  
15              
16 4     4   1397 use Sub::Exporter::Util ();
  4         8  
  4         222  
17 4         28 use Sub::Exporter -setup => {
18             exports => [ test_dzil => Sub::Exporter::Util::curry_method() ],
19             groups => [ default => [ qw(test_dzil) ] ],
20 4     4   20 };
  4         8  
21              
22 4     4   2072 use namespace::autoclean -except => 'import';
  4         8  
  4         27  
23              
24 20     20 0 26264 sub result_class { 'Dist::Zilla::App::Tester::Result' }
25              
26             sub test_dzil {
27 20     20 1 1967917 my ($self, $source, $argv, $arg) = @_;
28 20   50     166 $arg ||= {};
29              
30 20 50       71 local @INC = map {; ref($_) ? $_ : File::Spec->rel2abs($_) } @INC;
  161         1951  
31              
32 20   33     910 my $tmpdir = $arg->{tempdir} || File::Temp::tempdir(CLEANUP => 1);
33 20         14687 my $root = path($tmpdir)->child('source');
34 20         2638 $root->mkpath;
35              
36 20         6380 dircopy($source, $root);
37              
38 20         119072 my $wd = File::pushd::pushd($root);
39              
40 20         2880 local $ENV{DZIL_TESTING} = 1;
41 20         336 my $result = $self->test_app('Dist::Zilla::App' => $argv);
42 20         319 $result->{tempdir} = $tmpdir;
43              
44 20         391 return $result;
45             }
46              
47             {
48             package Dist::Zilla::App::Tester::Result 6.037;
49              
50 4     4   3471 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   1217 my ($self) = @_;
79 1         2 [ map {; $_->{message} } @{ $self->app->zilla->logger->logger->events } ];
  8         38  
  1         9  
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.037
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
169             released in the last two to three years. (That is, if the most recently
170             released version is v5.40, then this module should work on both v5.40 and
171             v5.38.)
172              
173             Although it may work on older versions of perl, no guarantee is made that the
174             minimum required version will not be increased. The version may be increased
175             for any reason, and there is no promise that patches will be accepted to
176             lower the minimum required perl.
177              
178             =head1 AUTHOR
179              
180             Ricardo SIGNES 😏 <cpan@semiotic.systems>
181              
182             =head1 COPYRIGHT AND LICENSE
183              
184             This software is copyright (c) 2026 by Ricardo SIGNES.
185              
186             This is free software; you can redistribute it and/or modify it under
187             the same terms as the Perl 5 programming language system itself.
188              
189             =cut