File: OldShareDirFiles.pm

package info (click to toggle)
libtest-json-schema-acceptance-perl 1.029-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,500 kB
  • sloc: perl: 831; makefile: 10
file content (60 lines) | stat: -rw-r--r-- 1,981 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use strict;
use warnings;
package inc::OldShareDirFiles;
use Moose;
with 'Dist::Zilla::Role::FileGatherer', 'Dist::Zilla::Role::BeforeRelease';
use Dist::Zilla::File::InMemory;
use Capture::Tiny 'capture';
use Path::Tiny;
use namespace::autoclean;

# for every file leaving the test suite, we must replace it with an empty file so ->_test_data can
# filter it out, because File::ShareDir::Install cannot remove old files when installing a new
# sharedir over top. see https://rt.cpan.org/Ticket/Display.html?id=92084#txn-1324511

has removed => ( is => 'ro', isa => 'ArrayRef[Str]', required => 1 );
sub mvp_multivalue_args { qw(removed) };

sub gather_files {
  my $self = shift;

  foreach my $filename (@{$self->removed}) {
    my $content = path('share/tests')->subsumes($filename) ? '[]'
      : path('share/remotes')->subsumes($filename) ? '{}'
      : die "don't know how to handle filename '$filename'";

    $self->add_file(Dist::Zilla::File::InMemory->new({ name => $filename, content => $content }))
  }
  return;
}

sub before_release {
  my $self = shift;

  my $distname = $self->zilla->name;
  my $version = $self->zilla->version;

  my ($diff, $error) = capture {
    system('diff', '-u', $distname.'-'.sprintf("%.3f", $version-0.001).'/MANIFEST', $distname.'-'.$version.'/MANIFEST');
  };

  die $error if $error;

  # skip old share/tests/draft-future -- not officially supported by any implementation
  # (now known as draft-next)
  $diff =~ s{^-share/tests/draft-future/.+\n}{}gm;

  # note: if a removed file was re-added in the submodule, we will get a "aborting; duplicate files
  # would be produced" fatal error from Gather plugins, so we don't need to explicitly check for
  # this case

  if (my @missing = map s/^-//r, grep m{^-share/}, split /\n/, $diff) {
    $self->log_fatal(join "\n", '',
      'These files were removed from the test suite and must be added to the config for [=inc::OldShareDirFiles]:',
      @missing,
      '',
    );
  }
}

1;