File: gatherdir.t

package info (click to toggle)
libdist-zilla-perl 6.032-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,928 kB
  • sloc: perl: 7,275; makefile: 4; sh: 1
file content (144 lines) | stat: -rw-r--r-- 4,290 bytes parent folder | download | duplicates (2)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use strict;
use warnings;
use Test::More 0.88;

use ExtUtils::Manifest 'maniread';
use Test::DZil;
use Path::Tiny;

my $tzil = Builder->from_config(
  { dist_root => 'corpus/dist/DZT' },
  {
    add_files => {
      'source/dist.ini' => simple_ini(
        [ GatherDir => ],
        [ GatherDir => BonusFiles => {
          root   => '../corpus/extra',
          prefix => 'bonus',
        } ],
        [ GatherDir => DottyFiles => {
          root   => '../corpus/extra',
          prefix => 'dotty',
          include_dotfiles => 1,
        } ],
        [ GatherDir => Selective => {
          root   => '../corpus/extra',
          prefix => 'some',
          exclude_filename => [ 'notme.txt', 'subdir/index.html' ],
        } ],
        [ GatherDir => SelectiveMatch => {
          root   => '../corpus/extra',
          prefix => 'xmatch',
          exclude_match => [ 'notme\.*', '^subdir/index\.html$' ],
        } ],
        [ GatherDir => Symlinks => {
          root   => '../corpus/extra',
          follow_symlinks => 1,
          prefix => 'links',
        } ],
        [ GatherDir => PruneDirectory => {
          root   => '../corpus/extra',
          prefix => 'pruned',
          prune_directory => '^subdir$',
        } ],
        'Manifest',
        'MetaConfig',
      ),
      'source/.profile' => "Bogus dotfile.\n",
      'corpus/extra/.dotfile' => "Bogus dotfile.\n",
      'corpus/extra/notme.txt' => "A file to exclude.\n",
      'source/.dotdir/extra/notme.txt' => "Another file to exclude.\n",
      'source/extra/.dotdir/notme.txt' => "Another file to exclude.\n",
    },
    also_copy => { 'corpus/extra' => 'corpus/extra', 'corpus/global' => 'corpus/global' },
  },
);

my $corpus_dir = path($tzil->tempdir)->child('corpus');
if ($^O ne 'MSWin32' && $^O ne 'msys') {
  symlink $corpus_dir->child('extra', 'vader.txt'), $corpus_dir->child('extra', 'vader_link.txt')
    or note "could not create link: $!";

  # link must be to something that is not otherwise being gathered, or we get duplicate errors
  symlink $corpus_dir->child('global'), $corpus_dir->child('extra', 'global_link')
    or note "could not create link: $!";
}

$tzil->chrome->logger->set_debug(1);
$tzil->build;

my @files = map {; $_->name } @{ $tzil->files };

is_filelist(
  [ @files ],
  [ qw(
    bonus/subdir/index.html bonus/vader.txt bonus/notme.txt
    dotty/subdir/index.html dotty/vader.txt dotty/.dotfile dotty/notme.txt
    some/vader.txt
    xmatch/vader.txt
    links/vader.txt links/subdir/index.html links/notme.txt
    pruned/notme.txt pruned/vader.txt
    dist.ini lib/DZT/Sample.pm t/basic.t
    MANIFEST
  ),
    ($^O ne 'MSWin32' && $^O ne 'msys' ? ('links/global_link/config.ini') : ()),
    ($^O ne 'MSWin32' && $^O ne 'msys' ? (map { $_ . '/vader_link.txt' } qw(bonus dotty some xmatch links pruned)) : ()),
  ],
  "GatherDir gathers all files in the source dir",
);

my $manifest = maniread($tzil->tempdir->child('build/MANIFEST')->stringify);

my $count = grep { exists $manifest->{$_} } @files;
ok($count == @files, "all files found were in manifest");
ok(keys(%$manifest) == @files, "all files in manifest were on disk");

diag 'got log messages: ', explain $tzil->log_messages
  if not Test::Builder->new->is_passing;

my @to_remove;

TODO: {
  todo_skip('MSWin32 - skipping symlink test', 1) if $^O eq 'MSWin32' || $^O eq 'msys';

  # tmp/tmp -> tmp/private/tmp
  my $real_tmp = path('tmp', 'private', 'tmp');
  mkpath $real_tmp;
  my $link_tmp = path('tmp', 'tmp');
  symlink 'private/tmp', 'tmp/tmp';

  push @to_remove, [ $real_tmp, $link_tmp ];

  my $tzil = Builder->from_config(
    { dist_root => 'corpus/dist' },
    {
      add_files => {
        'source/dist.ini' => simple_ini(
          [ GatherDir => { root => 'DZ1' } ],
        ),
      },
      tempdir_root => 'tmp/tmp',
    },
  );

  $tzil->chrome->logger->set_debug(1);
  $tzil->build;

  my @files = map {; $_->name } @{ $tzil->files };

  is_filelist(
    [ @files ],
    [ qw(dist.ini lib/DZ1.pm) ],
    "GatherDir gathers all files in the source dir (canonically corpus/dist/DZ1)",
  );

  diag 'got log messages: ', explain $tzil->log_messages
    if not Test::Builder->new->is_passing;
}

for my $pair (@to_remove) {
  $pair->[0]->remove_tree;
  $pair->[1]->remove;
}

done_testing;