Debian Codegraph @

inc/OldShareDirFiles.pm

raw
1 use strict;
2 use warnings;
3 package inc::OldShareDirFiles;
4 use Moose;
5 with 'Dist::Zilla::Role::FileGatherer', 'Dist::Zilla::Role::BeforeRelease';
6 use Dist::Zilla::File::InMemory;
7 use Capture::Tiny 'capture';
8 use Path::Tiny;
9 use namespace::autoclean;
10
11 # for every file leaving the test suite, we must replace it with an empty file so ->_test_data can
12 # filter it out, because File::ShareDir::Install cannot remove old files when installing a new
13 # sharedir over top. see https://rt.cpan.org/Ticket/Display.html?id=92084#txn-1324511
14
15 has removed => ( is => 'ro', isa => 'ArrayRef[Str]', required => 1 );
16 sub mvp_multivalue_args { qw(removed) };
17
18 sub gather_files {
19 my $self = shift;
20
21 foreach my $filename (@{$self->removed}) {
22 my $content = path('share/tests')->subsumes($filename) ? '[]'
23 : path('share/remotes')->subsumes($filename) ? '{}'
24 : die "don't know how to handle filename '$filename'";
25
26 $self->add_file(Dist::Zilla::File::InMemory->new({ name => $filename, content => $content }))
27 }
28 return;
29 }
30
31 sub before_release {
32 my $self = shift;
33
34 my $distname = $self->zilla->name;
35 my $version = $self->zilla->version;
36
37 my ($diff, $error) = capture {
38 system('diff', '-u', $distname.'-'.sprintf("%.3f", $version-0.001).'/MANIFEST', $distname.'-'.$version.'/MANIFEST');
39 };
40
41 die $error if $error;
42
43 # skip old share/tests/draft-future and draft-next, now replaced by "v1"
44 # and to be entirely ignored
45 $diff =~ s{^-share/(?:output-tests|remotes|tests)/draft-(?:future|next)/.+\n}{}gm;
46
47 # note: if a removed file was re-added in the submodule, we will get a "aborting; duplicate files
48 # would be produced" fatal error from Gather plugins, so we don't need to explicitly check for
49 # this case
50
51 if (my @missing = map s/^-//r, grep m{^-share/}, split /\n/, $diff) {
52 $self->log_fatal(join "\n", '',
53 'These files were removed from the test suite and must be added to the config for [=inc::OldShareDirFiles]:',
54 @missing,
55 '',
56 );
57 }
58 }
59
60 1;