File Coverage

blib/lib/Dist/Zilla/Plugin/CheckExtraTests.pm
Criterion Covered Total %
statement 49 49 100.0
branch 6 10 60.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 61 66 92.4


line stmt bran cond sub pod time code
1 3     3   2360644 use strict;
  3         6  
  3         119  
2 3     3   17 use warnings;
  3         4  
  3         249  
3              
4             package Dist::Zilla::Plugin::CheckExtraTests;
5             # ABSTRACT: check xt tests before release
6              
7             our $VERSION = '0.028'; # from Dist-Zilla-Plugin-CheckExtraTests-0.028.tar.gz
8              
9             # Dependencies
10 3     3   22 use Dist::Zilla 4.3 ();
  3         122  
  3         83  
11 3     3   17 use Moose 2;
  3         43  
  3         21  
12 3     3   16081 use namespace::autoclean 0.09;
  3         92  
  3         22  
13              
14             # extends, roles, attributes, etc.
15              
16             with 'Dist::Zilla::Role::BeforeRelease';
17              
18             #pod =attr default_jobs
19             #pod
20             #pod This attribute is the default value that should be used as the C<jobs> argument
21             #pod for prerelease tests.
22             #pod
23             #pod =cut
24              
25             has default_jobs => (
26             is => 'ro',
27             isa => 'Int', # non-negative
28             default => 1,
29             );
30              
31             # methods
32              
33             sub before_release {
34 3     3 0 569621 my ( $self, $tgz ) = @_;
35 3         74 $tgz = $tgz->absolute;
36              
37 3         722 { require Path::Tiny; Path::Tiny->VERSION(0.013) }
  3         37  
  3         114  
38              
39 3         150 my $build_root = Path::Tiny::path( $self->zilla->root )->child('.build');
40 3 50       611 $build_root->mkpath unless -d $build_root;
41              
42 3         886 my $tmpdir = Path::Tiny->tempdir( DIR => $build_root );
43              
44 3         2094 $self->log("Extracting $tgz to $tmpdir");
45              
46 3         47383 require Archive::Tar;
47              
48 3         273941 my @files = do {
49 3         31 my $wd = File::pushd::pushd($tmpdir);
50 3         874 Archive::Tar->extract_archive("$tgz");
51             };
52              
53 3 50       201348 $self->log_fatal( [ "Failed to extract archive: %s", Archive::Tar->error ] )
54             unless @files;
55              
56             # Run tests on the extracted tarball:
57 3         243 my $target = $tmpdir->child( $self->zilla->dist_basename );
58              
59 3         580 local $ENV{RELEASE_TESTING} = 1;
60 3         20 local $ENV{AUTHOR_TESTING} = 1;
61              
62             {
63             # chdir in
64 3         11 require File::pushd;
  3         33  
65 3         19 my $wd = File::pushd::pushd($target);
66              
67             # make
68 3         712 my @builders = @{ $self->zilla->plugins_with( -BuildRunner ) };
  3         130  
69 3 50       1941 die "no BuildRunner plugins specified" unless @builders;
70 3         38 $_->build for @builders;
71              
72 3         1830216 my $jobs = $self->default_jobs;
73 3 50       121 my @v = $self->zilla->logger->get_debug ? ('-v') : ();
74              
75 3         3603 require App::Prove;
76 3         46757 App::Prove->VERSION('3.00');
77              
78 3         31 my $app = App::Prove->new;
79 3         287 $app->process_args( '-j', $jobs, @v, qw/-r -b xt/ );
80 3 100       13006 $app->run or $self->log_fatal("Fatal errors in xt tests");
81             }
82              
83 2         878085 $self->log("all's well; removing $tmpdir");
84 2         984 $tmpdir->remove_tree( { safe => 0 } );
85              
86 2         7612 return;
87             }
88              
89             __PACKAGE__->meta->make_immutable;
90              
91             1;
92              
93             __END__
94              
95             =pod
96              
97             =encoding UTF-8
98              
99             =head1 NAME
100              
101             Dist::Zilla::Plugin::CheckExtraTests - check xt tests before release
102              
103             =head1 VERSION
104              
105             version 0.028
106              
107             =head1 SYNOPSIS
108              
109             In your dist.ini:
110              
111             [CheckExtraTests]
112              
113             =head1 DESCRIPTION
114              
115             Runs all xt tests before release. Dies if any fail. Sets RELEASE_TESTING
116             and AUTHOR_TESTING.
117              
118             If you use L<Dist::Zilla::Plugin::TestRelease>, you should consider using
119             L<Dist::Zilla::Plugin::RunExtraTests> instead, which enables xt tests to
120             run as part of C<[TestRelease]> and is thus a bit more efficient as the
121             distribution is only built once for testing.
122              
123             =head1 ATTRIBUTES
124              
125             =head2 default_jobs
126              
127             This attribute is the default value that should be used as the C<jobs> argument
128             for prerelease tests.
129              
130             =for Pod::Coverage::TrustPod before_release
131              
132             =head1 SEE ALSO
133              
134             =over 4
135              
136             =item *
137              
138             L<Dist::Zilla>
139              
140             =back
141              
142             =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
143              
144             =head1 SUPPORT
145              
146             =head2 Bugs / Feature Requests
147              
148             Please report any bugs or feature requests through the issue tracker
149             at L<https://github.com/dagolden/Dist-Zilla-Plugin-CheckExtraTests/issues>.
150             You will be notified automatically of any progress on your issue.
151              
152             =head2 Source Code
153              
154             This is open source software. The code repository is available for
155             public review and contribution under the terms of the license.
156              
157             L<https://github.com/dagolden/Dist-Zilla-Plugin-CheckExtraTests>
158              
159             git clone https://github.com/dagolden/Dist-Zilla-Plugin-CheckExtraTests.git
160              
161             =head1 AUTHORS
162              
163             =over 4
164              
165             =item *
166              
167             David Golden <dagolden@cpan.org>
168              
169             =item *
170              
171             Jesse Luehrs <doy@cpan.org>
172              
173             =back
174              
175             =head1 CONTRIBUTORS
176              
177             =for stopwords Christopher J. Madsen David H. Adler Karen Etheridge Kent Fredric Olivier Mengué Ricardo Signes
178              
179             =over 4
180              
181             =item *
182              
183             Christopher J. Madsen <cjm@cpan.org>
184              
185             =item *
186              
187             David H. Adler <dha@pobox.com>
188              
189             =item *
190              
191             Karen Etheridge <ether@cpan.org>
192              
193             =item *
194              
195             Kent Fredric <kentfredric@gmail.com>
196              
197             =item *
198              
199             Olivier Mengué <dolmen@cpan.org>
200              
201             =item *
202              
203             Ricardo Signes <rjbs@cpan.org>
204              
205             =back
206              
207             =head1 COPYRIGHT AND LICENSE
208              
209             This software is Copyright (c) 2015 by David Golden.
210              
211             This is free software, licensed under:
212              
213             The Apache License, Version 2.0, January 2004
214              
215             =cut