File: autoprereqs.t

package info (click to toggle)
libdist-zilla-perl 6.033-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,928 kB
  • sloc: perl: 7,282; makefile: 4; sh: 1
file content (239 lines) | stat: -rw-r--r-- 5,808 bytes parent folder | download | duplicates (6)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
use strict;
use warnings;

use Test::More 0.88;
use Test::Deep;

use Test::DZil;
use YAML::Tiny;

sub build_meta {
  my $tzil = shift;

  $tzil->build;
  $tzil->distmeta;
}

my $tzil = Builder->from_config(
  { dist_root => 'corpus/dist/AutoPrereqs' },
  { },
);

# check found prereqs
my $meta = build_meta($tzil);

my %want_runtime = (
  # DZPA::Main should not be extracted
  'DZPA::Base::Moose1'    => 0,
  'DZPA::Base::Moose2'    => 0,
  'DZPA::Base::base1'     => 0,
  'DZPA::Base::base2'     => 0,
  'DZPA::Base::base3'     => 0,
  'DZPA::Base::parent1'   => 0,
  'DZPA::Base::parent2'   => 0,
  'DZPA::Base::parent3'   => 0,
  'DZPA::IgnoreAPI'       => 0,
  'DZPA::IndentedRequire' => '3.45',
  'DZPA::IndentedUse'     => '0.13',
  'DZPA::MinVerComment'   => '0.50',
  'DZPA::ModRequire'      => 0,
  'DZPA::NotInDist'       => 0,
  'DZPA::Role'            => 0,
  'DZPA::ScriptUse'       => 0,
  'base'                  => 0,
  'lib'                   => 0,
  'parent'                => 0,
  'perl'                  => 5.008,
  'strict'                => 0,
  'warnings'              => 0,
);

is_deeply(
  $meta->{prereqs}{runtime}{requires},
  \%want_runtime,
  'all requires found, but no more',
);

# Try again with configure_finder:
$tzil = Builder->from_config(
  { dist_root => 'corpus/dist/AutoPrereqs' },
  {
    add_files => {
      'source/dist.ini' => simple_ini(
        qw(GatherDir ExecDir),
        [ AutoPrereqs => { skip             => '^DZPA::Skip',
                           configure_finder => ':IncModules' } ],
      ),
      'source/inc/DZPA.pm' => "use DZPA::NotInDist;\n use DZPA::Configure;\n",
    },
  },
);

# check found prereqs
$meta = build_meta($tzil);

is_deeply(
  $meta->{prereqs}{runtime}{requires},
  \%want_runtime,
  'configure_finder did not change runtime requires',
);

my %want_configure = (
  'DZPA::Configure'       => 0,
  'DZPA::NotInDist'       => 0,
);

is_deeply(
  $meta->{prereqs}{configure}{requires},
  \%want_configure,
  'configure_requires is correct',
);


# Try again with tests added to the dist:
$tzil = Builder->from_config(
  { dist_root => 'corpus/dist/AutoPrereqs' },
  {
    add_files => {
      'source/dist.ini' => simple_ini(
        qw(GatherDir ExecDir),
        [ AutoPrereqs => { skip             => '^DZPA::Skip',
                           configure_finder => ':IncModules' } ],
      ),
      'source/inc/DZPA.pm' => "use DZPA::NotInDist;\n use DZPA::Configure;\n",
      'source/t/basic.t' => "use Test::Foo;\n",
    },
  },
);

# check found prereqs
$meta = build_meta($tzil);

my %want_test = (
  'Test::Foo'  => '0',
);

cmp_deeply(
  $meta,
  superhashof({
    prereqs => {
      runtime => { requires => \%want_runtime },
      configure => { requires => \%want_configure },
      test => { requires => \%want_test },
    },
  }),
  'test_finder did not change runtime, configure requires; test requires is correct',
);


# Try again with extra tests added to the dist:
$tzil = Builder->from_config(
  { dist_root => 'corpus/dist/AutoPrereqs' },
  {
    add_files => {
      'source/dist.ini' => simple_ini(
        qw(GatherDir ExecDir),
        [ AutoPrereqs => { skip             => '^DZPA::Skip',
                           configure_finder => ':IncModules' } ],
      ),
      'source/inc/DZPA.pm' => "use DZPA::NotInDist;\n use DZPA::Configure;\n",
      'source/t/basic.t' => "use Test::Foo;\n",
      'source/xt/author/more1.t' => "use Test::Bar;\n",
      'source/xt/smoke/more2.t' => "use Test::Baz;\n",
      'source/xt/release/more3.t' => "use Test::Qux;\n",
      'source/xt/more4.t' => "use Test::Norf;\n",
    },
  },
);

# check found prereqs
$meta = build_meta($tzil);

my %want_develop = (
  'Test::Bar'  => '0',
  'Test::Baz'  => '0',
  'Test::Qux'  => '0',
  'Test::Norf' => '0',
);

cmp_deeply(
  $meta,
  superhashof({
    prereqs => {
      runtime => { requires => \%want_runtime },
      configure => { requires => \%want_configure },
      test => { requires => \%want_test },
      develop => { requires => \%want_develop },
    },
  }),
  'develop_finder did not change runtime, configure, test requires; develop requires is correct',
);


# Try again with a customized scanner list:
$tzil = Builder->from_config(
  { dist_root => 'corpus/dist/AutoPrereqs' },
  {
    add_files => {
      'source/dist.ini' => simple_ini(
        qw(GatherDir ExecDir),
        [ AutoPrereqs => { scanner => 'Perl5', extra_scanner => 'Aliased' } ],
      ),
      'source/lib/DZPA/Aliased.pm' => "use aliased 'Long::Class::Name';\n",
    },
  },
);

# check found prereqs
$meta = build_meta($tzil);

{
my %want_runtime = %want_runtime;
# Moose-style prereqs should not be recognized this time:
delete $want_runtime{'DZPA::Base::Moose1'};
delete $want_runtime{'DZPA::Base::Moose2'};
delete $want_runtime{'DZPA::Role'};

$want_runtime{'DZPA::Skip::Blah'}  = 0; # not skipping anymore
$want_runtime{'DZPA::Skip::Foo'}   = 0;
$want_runtime{'aliased'}           = 0;
$want_runtime{'Long::Class::Name'} = 0;

is_deeply(
  $meta->{prereqs}{runtime}{requires},
  \%want_runtime,
  'custom scanner list',
);
}


# Try again with a non-default prereq type:
$tzil = Builder->from_config(
  { dist_root => 'corpus/dist/AutoPrereqs' },
  {
    add_files => {
      'source/dist.ini' => simple_ini(
        qw(GatherDir ExecDir),
        [ AutoPrereqs => { skip             => '^DZPA::Skip',
                           type             => 'suggests' } ],
      ),
      'source/t/basic.t' => "use Test::Foo;\n",
    },
  },
);

# check found prereqs
$meta = build_meta($tzil);

cmp_deeply(
  $meta,
  superhashof({
    prereqs => {
      runtime => { suggests => \%want_runtime },
      test => { suggests => \%want_test },
    },
  }),
  'all prereqs were added with the "suggests" relationship',
);

done_testing;