File Coverage

blib/lib/Dist/Zilla/Plugin/ExtraTests.pm
Criterion Covered Total %
statement 27 27 100.0
branch 3 4 75.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 38 40 95.0


line stmt bran cond sub pod time code
1             # ABSTRACT: rewrite ./xt tests to ./t tests with skips
2              
3             use Moose;
4 11     11   8227 with 'Dist::Zilla::Role::FileMunger';
  11         31  
  11         100  
5              
6             use Dist::Zilla::Pragmas;
7 11     11   75422  
  11         28  
  11         105  
8             use namespace::autoclean;
9 11     11   123  
  11         41  
  11         113  
10             #pod =head1 DESCRIPTION
11             #pod
12             #pod This plugin rewrites tests found in the following directories:
13             #pod
14             #pod ./xt/author - tests for author testing (env AUTHOR_TESTING is true)
15             #pod ./xt/release - tests for pre-release testers (env RELEASE_TESTING is true)
16             #pod ./xt/smoke - tests for automated testers (env AUTOMATED_TESTING is true)
17             #pod
18             #pod The tests are renamed and moved to F<./t>, and they are rewritten to include
19             #pod some simple Perl code to skip all included tests if the correct env vars are
20             #pod not set.
21             #pod
22             #pod =cut
23              
24             my ($self, $file) = @_;
25              
26 84     84 0 174 return unless $file->name =~ m{\Axt/(smoke|author|release)/.+\.t\z};
27             my $method = "_rewrite_$1\_test";
28 84 100       212  
29 20         82 $self->log("rewriting $1 test " . $file->name);
30              
31 20         83 $self->$method($file);
32             }
33 20         4895  
34             my ($self, $file) = @_;
35             $self->_rewrite($file, 'AUTOMATED_TESTING', '"smoke bot" testing');
36             }
37 1     1   4  
38 1         7 my ($self, $file) = @_;
39             $self->_rewrite($file, 'AUTHOR_TESTING', 'testing by the author');
40             }
41              
42 18     18   52 my ($self, $file) = @_;
43 18         76 $self->_rewrite($file, 'RELEASE_TESTING', 'release candidate testing');
44             }
45              
46             my ($self, $file, $env, $msg) = @_;
47 1     1   5  
48 1         4 my $name = $file->name =~ s{^xt/([^/]+)/}{t/$1-}r;
49              
50             $file->name($name);
51              
52 20     20   455 my @lines = split /\n/, $file->content;
53             my $after = $lines[0] =~ /\A#!/ ? 1 : 0;
54 20         83 splice @lines, $after, 0, qq|
55             BEGIN {
56 20         96 unless (\$ENV{$env}) {
57             print qq{1..0 # SKIP these tests are for $msg\\n};
58 20         77 exit
59 20 50       104 }
60 20         135 }
61             |;
62              
63             $file->content(join "\n", @lines, '');
64             }
65              
66             __PACKAGE__->meta->make_immutable;
67             1;
68              
69 20         136  
70             =pod
71              
72             =encoding UTF-8
73              
74             =head1 NAME
75              
76             Dist::Zilla::Plugin::ExtraTests - rewrite ./xt tests to ./t tests with skips
77              
78             =head1 VERSION
79              
80             version 6.028
81              
82             =head1 DESCRIPTION
83              
84             This plugin rewrites tests found in the following directories:
85              
86             ./xt/author - tests for author testing (env AUTHOR_TESTING is true)
87             ./xt/release - tests for pre-release testers (env RELEASE_TESTING is true)
88             ./xt/smoke - tests for automated testers (env AUTOMATED_TESTING is true)
89              
90             The tests are renamed and moved to F<./t>, and they are rewritten to include
91             some simple Perl code to skip all included tests if the correct env vars are
92             not set.
93              
94             =head1 PERL VERSION
95              
96             This module should work on any version of perl still receiving updates from
97             the Perl 5 Porters. This means it should work on any version of perl released
98             in the last two to three years. (That is, if the most recently released
99             version is v5.40, then this module should work on both v5.40 and v5.38.)
100              
101             Although it may work on older versions of perl, no guarantee is made that the
102             minimum required version will not be increased. The version may be increased
103             for any reason, and there is no promise that patches will be accepted to lower
104             the minimum required perl.
105              
106             =head1 AUTHOR
107              
108             Ricardo SIGNES 😏 <cpan@semiotic.systems>
109              
110             =head1 COPYRIGHT AND LICENSE
111              
112             This software is copyright (c) 2022 by Ricardo SIGNES.
113              
114             This is free software; you can redistribute it and/or modify it under
115             the same terms as the Perl 5 programming language system itself.
116              
117             =cut