File Coverage

blib/lib/Dist/Zilla/Plugin/RunExtraTests.pm
Criterion Covered Total %
statement 38 43 88.3
branch 12 22 54.5
condition 4 6 66.6
subroutine 6 6 100.0
pod 0 1 0.0
total 60 78 76.9


line stmt bran cond sub pod time code
1 1     1   1961 use strict;
  1         1  
  1         31  
2 1     1   3 use warnings;
  1         2  
  1         58  
3              
4             package Dist::Zilla::Plugin::RunExtraTests;
5             # ABSTRACT: support running xt tests via dzil test
6              
7             our $VERSION = '0.028'; # from Dist-Zilla-Plugin-CheckExtraTests-0.028.tar.gz
8              
9             # Dependencies
10 1     1   4 use Dist::Zilla 4.3 ();
  1         20  
  1         18  
11 1     1   3 use Moose 2;
  1         10  
  1         8  
12 1     1   5170 use namespace::autoclean 0.09;
  1         24  
  1         6  
13              
14             # extends, roles, attributes, etc.
15              
16             with 'Dist::Zilla::Role::TestRunner';
17              
18             # methods
19              
20             sub test {
21 5     5 0 6207100 my ($self, $target, $arg) = @_;
22              
23 5         21 my %dirs; @dirs{ grep { -d } glob('xt/*') } = ();
  5         570  
  4         81  
24 5 100       51 delete $dirs{'xt/author'} unless $ENV{AUTHOR_TESTING};
25 5 50       46 delete $dirs{'xt/smoke'} unless $ENV{AUTOMATED_TESTING};
26 5 50       33 delete $dirs{'xt/release'} unless $ENV{RELEASE_TESTING};
27              
28 5         33 my @dirs = sort keys %dirs;
29 5         168 my @files = grep { -f } glob('xt/*');
  4         55  
30 5 100 100     97 return unless @dirs or @files;
31              
32             # If the dist hasn't been built yet, then build it:
33 3 50       54 unless ( -d 'blib' ) {
34 0         0 my @builders = @{ $self->zilla->plugins_with( -BuildRunner ) };
  0         0  
35 0 0       0 die "no BuildRunner plugins specified" unless @builders;
36 0         0 $_->build for @builders;
37 0 0       0 die "no blib; failed to build properly?" unless -d 'blib';
38             }
39              
40             my $jobs = $arg && exists $arg->{jobs}
41             ? $arg->{jobs}
42 3 50 33     286 : $self->can('default_jobs')
    50          
43             ? $self->default_jobs
44             : 1;
45 3 50       148 my @v = $self->zilla->logger->get_debug ? ('-v') : ();
46              
47 3         1265 require App::Prove;
48 3         27733 App::Prove->VERSION('3.00');
49              
50 3         27 my $app = App::Prove->new;
51              
52 3         308 $self->log_debug([ 'running prove with args: %s', join(' ', '-j', $jobs, @v, qw/-b xt/) ]);
53 3         1681 $app->process_args( '-j', $jobs, @v, qw/-b xt/);
54              
55 3         7223 $self->log_debug([ 'running prove with args: %s', join(' ', '-j', $jobs, @v, qw/-r -b/, @dirs) ]);
56 3         890 $app->process_args( '-j', $jobs, @v, qw/-r -b/, @dirs );
57 3 100       6248 $app->run or $self->log_fatal("Fatal errors in xt tests");
58 1         359681 return;
59             }
60              
61             __PACKAGE__->meta->make_immutable;
62              
63             1;
64              
65             __END__
66              
67             =pod
68              
69             =encoding UTF-8
70              
71             =head1 NAME
72              
73             Dist::Zilla::Plugin::RunExtraTests - support running xt tests via dzil test
74              
75             =head1 VERSION
76              
77             version 0.028
78              
79             =head1 SYNOPSIS
80              
81             In your dist.ini:
82              
83             [RunExtraTests]
84              
85             =head1 DESCRIPTION
86              
87             Runs F<xt> tests when the test phase is run (e.g. C<dzil test>, C<dzil release>
88             etc). F<xt/release>, F<xt/author>, and F<xt/smoke> will be tested based on the
89             values of the appropriate environment variables (C<RELEASE_TESTING>,
90             C<AUTHOR_TESTING>, and C<AUTOMATED_TESTING>), which are set by C<dzil test>.
91             Additionally, all other F<xt> files and directories will always be run.
92              
93             If C<RunExtraTests> is listed after one of the normal test-running
94             plugins (e.g. C<MakeMaker> or C<ModuleBuild>), then the dist will not
95             be rebuilt between running the normal tests and the extra tests.
96              
97             =for Pod::Coverage::TrustPod test
98              
99             =head1 SEE ALSO
100              
101             =over 4
102              
103             =item *
104              
105             L<Dist::Zilla>
106              
107             =back
108              
109             =head1 AUTHORS
110              
111             =over 4
112              
113             =item *
114              
115             David Golden <dagolden@cpan.org>
116              
117             =item *
118              
119             Jesse Luehrs <doy@cpan.org>
120              
121             =back
122              
123             =head1 COPYRIGHT AND LICENSE
124              
125             This software is Copyright (c) 2015 by David Golden.
126              
127             This is free software, licensed under:
128              
129             The Apache License, Version 2.0, January 2004
130              
131             =cut