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