File: mb_custom.t

package info (click to toggle)
libdist-zilla-plugins-cjm-perl 6.000-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 324 kB
  • sloc: perl: 1,439; makefile: 11
file content (211 lines) | stat: -rw-r--r-- 4,766 bytes parent folder | download | duplicates (4)
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
#! /usr/bin/perl
#---------------------------------------------------------------------

use strict;
use warnings;
use Test::More 0.88 tests => 10; # done_testing

use Test::DZil 'Builder';

#---------------------------------------------------------------------
sub make_re
{
  my $text = quotemeta shift;

  $text =~ s/\\\n/ *\n/g;

  # Accept either '0' or 0 in prereqs:
  $text =~ s/(\\'0\\')/(?:$1|0)/g;

  qr/^$text/m;
} # end make_re

#---------------------------------------------------------------------
{
  my $tzil = Builder->from_config(
    { dist_root => 'corpus/DZT' },
    {
      add_files => {
        'source/dist.ini' => <<'END INI',
name     = DZT-Sample
author   = E. Xavier Ample <example@example.org>
license  = Perl_5
copyright_holder = E. Xavier Ample
version          = 0.04

[Prereqs]
Foo::Bar = 1.00
Bloofle  = 0

[Prereqs / TestRequires]
Test::More = 0.88

[GatherDir]
[ModuleBuild::Custom]
mb_version = 0.3601
END INI

        'source/Build.PL' => <<'END BUILD',
use Module::Build;

my $builder = My_Build->new(
  module_name        => 'DZT::Sample',
  license            => 'perl',
  dist_author        => 'E. Xavier Ample <example@example.org>',
  dist_version_from  => 'lib/DZT/Sample.pm',
  dynamic_config     => 0,
  # Prerequisites inserted by DistZilla:
##{ $plugin->get_prereqs ##}
);

$builder->create_build_script();
END BUILD
      },
    },
  );

  $tzil->build;

  my $buildPL = $tzil->slurp_file('build/Build.PL');
  #print STDERR $buildPL;

  my $build_requires = <<'END BUILD_REQUIRES';
  'build_requires' => {
    'Module::Build' => '0.3601',
    'Test::More' => '0.88'
  },
END BUILD_REQUIRES

  my $configure_requires = <<'END CONFIGURE_REQUIRES';
  'configure_requires' => {
    'Module::Build' => '0.3601'
  },
END CONFIGURE_REQUIRES

  my $requires = <<'END REQUIRES';
  'requires' => {
    'Bloofle' => '0',
    'Foo::Bar' => '1.00'
  },
END REQUIRES

  like($buildPL, make_re($build_requires),     "build_requires");
  like($buildPL, make_re($configure_requires), "configure_requires");
  like($buildPL, make_re($requires),           "requires");
}

#---------------------------------------------------------------------
sub test_and_build_reqs {
  my $api_version = shift;

  (my $BuildSRC = <<'END BUILD') =~ s/~API_VERSION~/$api_version/;
use Module::Build;

my $builder = My_Build->new(
  module_name        => 'DZT::Sample',
  license            => 'perl',
  dist_author        => 'E. Xavier Ample <example@example.org>',
  dist_version_from  => 'lib/DZT/Sample.pm',
  dynamic_config     => 0,
  # Prerequisites inserted by DistZilla:
##{ $plugin->get_prereqs(~API_VERSION~) ##}
);

$builder->create_build_script();
END BUILD

  my $tzil = Builder->from_config(
    { dist_root => 'corpus/DZT' },
    {
      add_files => {
        'source/dist.ini' => <<'END INI',
name     = DZT-Sample
author   = E. Xavier Ample <example@example.org>
license  = Perl_5
copyright_holder = E. Xavier Ample
version          = 0.04

[Prereqs]
Foo::Bar = 1.00
Bloofle  = 0

[Prereqs / TestRequires]
Test::More = 0.88

[Prereqs / BuildRequires]
Foo::Make = 2.00

[GatherDir]
[ModuleBuild::Custom]
mb_version = 0.3601
END INI

        'source/Build.PL' => $BuildSRC,
      },
    },
  );

  $tzil->build;

  my $buildPL = $tzil->slurp_file('build/Build.PL');
  #print STDERR $buildPL;

  my $configure_requires = <<'END CONFIGURE_REQUIRES';
  'configure_requires' => {
    'Module::Build' => '0.3601'
  },
END CONFIGURE_REQUIRES

  my $requires = <<'END REQUIRES';
  'requires' => {
    'Bloofle' => '0',
    'Foo::Bar' => '1.00'
  },
END REQUIRES

  like($buildPL, make_re($configure_requires), "configure_requires");
  like($buildPL, make_re($requires),           "requires");

  return $buildPL;
}

#---------------------------------------------------------------------
{
  my $buildPL = test_and_build_reqs(0);

  my $build_requires = <<'END BUILD_REQUIRES_0';
  'build_requires' => {
    'Foo::Make' => '2.00',
    'Module::Build' => '0.3601',
    'Test::More' => '0.88'
  },
END BUILD_REQUIRES_0

  like($buildPL, make_re($build_requires), "build_requires (api 0)");
}

#---------------------------------------------------------------------
SKIP: {
  my $buildPL = test_and_build_reqs(1);

  eval { Test::DZil->VERSION( 4.300032 ) }
      or skip 'Dist::Zilla 4.300032 required', 2;

  my $build_requires = <<'END BUILD_REQUIRES_1';
  'build_requires' => {
    'Foo::Make' => '2.00',
    'Module::Build' => '0.3601'
  },
END BUILD_REQUIRES_1

  my $test_requires = <<'END TEST_REQUIRES_1';
  'test_requires' => {
    'Test::More' => '0.88'
  },
END TEST_REQUIRES_1

  like($buildPL, make_re($build_requires), "build_requires (api 1)");
  like($buildPL, make_re($test_requires),  "test_requires (api 1)");
}

done_testing;