File Coverage

blib/lib/Dist/Zilla/Plugin/TestRelease.pm
Criterion Covered Total %
statement 32 32 100.0
branch 2 4 50.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 40 43 93.0


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::TestRelease 6.037;
2             # ABSTRACT: extract archive and run tests before releasing the dist
3              
4 3     3   2893 use Moose;
  3         10  
  3         30  
5             with 'Dist::Zilla::Role::BeforeRelease';
6              
7 3     3   24605 use Dist::Zilla::Pragmas;
  3         9  
  3         30  
8              
9 3     3   29 use namespace::autoclean;
  3         7  
  3         36  
10              
11             #pod =head1 DESCRIPTION
12             #pod
13             #pod This plugin runs before a release happens. It will extract the to-be-released
14             #pod archive into a temporary directory and use the TestRunner plugins to run its
15             #pod tests. If the tests fail, the release is aborted and the temporary directory
16             #pod is left in place. If the tests pass, the temporary directory is cleaned up and
17             #pod the release process continues.
18             #pod
19             #pod This will set the RELEASE_TESTING and AUTHOR_TESTING env vars while running the
20             #pod test suite.
21             #pod
22             #pod =head1 CREDITS
23             #pod
24             #pod This plugin was originally contributed by Christopher J. Madsen.
25             #pod
26             #pod =cut
27              
28 3     3   314 use File::pushd ();
  3         15  
  3         116  
29 3     3   16 use Dist::Zilla::Path;
  3         22  
  3         37  
30              
31             sub before_release {
32 1     1 0 6 my ($self, $tgz) = @_;
33 1         10 $tgz = $tgz->absolute;
34              
35 1         228 my $build_root = $self->zilla->root->child('.build');
36 1 50       63 $build_root->mkpath unless -d $build_root;
37              
38 1         1045 my $tmpdir = path( File::Temp::tempdir(DIR => $build_root) );
39              
40 1         68 $self->log("Extracting $tgz to $tmpdir");
41              
42 1         552 require Archive::Tar;
43              
44 1         2 my @files = do {
45 1         10 my $wd = File::pushd::pushd($tmpdir);
46 1         236 Archive::Tar->extract_archive("$tgz");
47             };
48              
49 1 50       123715 $self->log_fatal([ "Failed to extract archive: %s", Archive::Tar->error ])
50             unless @files;
51              
52             # Run tests on the extracted tarball:
53 1         107 my $target = $tmpdir->child( $self->zilla->dist_basename );
54              
55 1         124 local $ENV{RELEASE_TESTING} = 1;
56 1         16 local $ENV{AUTHOR_TESTING} = 1;
57 1         60 $self->zilla->run_tests_in($target);
58              
59 1         154 $self->log("all's well; removing $tmpdir");
60 1         2481 $tmpdir->remove_tree({ safe => 0 });
61             }
62              
63             __PACKAGE__->meta->make_immutable;
64             1;
65              
66             __END__
67              
68             =pod
69              
70             =encoding UTF-8
71              
72             =head1 NAME
73              
74             Dist::Zilla::Plugin::TestRelease - extract archive and run tests before releasing the dist
75              
76             =head1 VERSION
77              
78             version 6.037
79              
80             =head1 DESCRIPTION
81              
82             This plugin runs before a release happens. It will extract the to-be-released
83             archive into a temporary directory and use the TestRunner plugins to run its
84             tests. If the tests fail, the release is aborted and the temporary directory
85             is left in place. If the tests pass, the temporary directory is cleaned up and
86             the release process continues.
87              
88             This will set the RELEASE_TESTING and AUTHOR_TESTING env vars while running the
89             test suite.
90              
91             =head1 PERL VERSION
92              
93             This module should work on any version of perl still receiving updates from
94             the Perl 5 Porters. This means it should work on any version of perl
95             released in the last two to three years. (That is, if the most recently
96             released version is v5.40, then this module should work on both v5.40 and
97             v5.38.)
98              
99             Although it may work on older versions of perl, no guarantee is made that the
100             minimum required version will not be increased. The version may be increased
101             for any reason, and there is no promise that patches will be accepted to
102             lower the minimum required perl.
103              
104             =head1 CREDITS
105              
106             This plugin was originally contributed by Christopher J. Madsen.
107              
108             =head1 AUTHOR
109              
110             Ricardo SIGNES 😏 <cpan@semiotic.systems>
111              
112             =head1 COPYRIGHT AND LICENSE
113              
114             This software is copyright (c) 2026 by Ricardo SIGNES.
115              
116             This is free software; you can redistribute it and/or modify it under
117             the same terms as the Perl 5 programming language system itself.
118              
119             =cut