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