forked from andk/cpanpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12cpan.t
244 lines (228 loc) · 7.28 KB
/
12cpan.t
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
240
241
242
243
244
BEGIN {
$|++;
local $^W;
eval "qr/qr/";
if ($@) {
$|=1;
print "1..0 # SKIP no qr//\n";
eval "require POSIX; 1" and POSIX::_exit(0);
}
}
my $count;
use strict;
use Test::More;
use File::Spec;
sub _f ($) {
File::Spec->catfile(split /\//, shift);
}
use File::Copy qw(cp);
unlink _f"t/CPAN/MyConfig.pm"; # cp non-overwriting on OS/2
cp _f"t/CPAN/TestConfig.pm", _f"t/CPAN/MyConfig.pm"
or die "Could not cp t/CPAN/TestConfig.pm over t/CPAN/MyConfig.pm: $!";
unshift @INC, "t";
require CPAN::MyConfig;
require CPAN;
require CPAN::Kwalify;
require CPAN::HandleConfig;
{
eval {CPAN::rtlpr()};
like $@, qr/Unknown CPAN command/,q/AUTOLOAD rejects/;
BEGIN{$count++}
}
{
my $rdep = CPAN::Exception::RecursiveDependency->new([qw(foo bar baz)]);
like $rdep, qr/^--not.*--$/, "not a recursive/circular dependency";
BEGIN{$count++}
}
{
my $rdep = CPAN::Exception::RecursiveDependency->new([qw(foo bar baz foo)]);
like $rdep, qr/foo.+=>.+bar.+=>.+baz.+=>.+foo/s, "circular dependency";
BEGIN{$count++}
}
{
my $a = CPAN::Shell->expand("Module",
"CPAN::Test::Dummy::Perl5::Make"
)->distribution->author->as_string;
like $a, qr/Andreas/, "found Andreas in CPAN::Test::Dummy::Perl5::Make";
BEGIN{$count++}
}
{
no strict;
{
package S;
for my $m (qw(myprint mydie mywarn mysleep)){
*$m = sub {
return;
}
}
}
$CPAN::Frontend = $CPAN::Frontend = "S";
$_ = "Fcntl";
my $m = CPAN::Shell->expand(Module => $_);
$m->uptodate;
is($_,"Fcntl","\$_ is properly localized");
BEGIN{$count++}
}
{
my @s;
BEGIN{
@s=(
'"a"',
'["a"]',
'{a=>"b"}',
'{"a;"=>"b"}',
'"\\\\"',
);
$count+=@s;
}
for (0..$#s) {
my $x = eval $s[$_];
my $y = CPAN::HandleConfig->neatvalue($x);
my $z = eval $y;
is_deeply($z,$x,"s[$_]");
}
}
{
my $this_block_count;
BEGIN { $count += $this_block_count = 2; }
eval { require Kwalify; require YAML; }; # most of the kwalify
# stuff does not work
# without yaml
if ($@ || (($YAML::VERSION||$YAML::VERSION||0) < 0.62)) { # silence 5.005_04
for (1..$this_block_count) {
ok(1, "dummy Kwalify/YAML $_");
}
} else {
my $data = {
"match" => {
"distribution" => "^(ABW|ADAMK)/Template-Toolkit-2.16"
},
"pl" => {
"args" => [
"TT_EXTRAS=no"
],
"expect" => [
"Do you want to build the XS Stash module",
"n\n",
"Do you want to install these components",
"n\n",
"Installation directory",
"\n",
"URL base for TT2 images",
"\n",
],
barth => '1984',
},
};
eval {CPAN::Kwalify::_validate("distroprefs",
$data,
_f("t/12cpan.t"),
0)};
ok($@,"no kwalify [$@]");
delete $data->{pl}{barth};
CPAN::Kwalify::_clear_cache();
eval {CPAN::Kwalify::_validate("distroprefs",
$data,
_f("t/12cpan.t"),
0)};
ok(!$@,"kwalify ok");
}
}
{
my $this_block_count;
BEGIN { $count += $this_block_count = 8; }
eval { require YAML::Syck; };
my $excuse;
if ($@) {
$excuse = "YAML::Syck not available";
} elsif (($YAML::Syck::VERSION||$YAML::Syck::VERSION||0) < 0.97) { # silence 5.005_04
$excuse = "YAML::Syck too old";
} elsif ($] < 5.008) {
$excuse = "Defered code segfaults on 5.6.x";
}
if ($excuse) {
for (1..$this_block_count) {
ok(1, "Skipping ($excuse) $_");
}
} else {
my $yaml_file = _f('t/yaml_code.yml');
local $CPAN::Config->{yaml_module} = 'YAML::Syck';
{
my $data = CPAN->_yaml_loadfile($yaml_file)->[0];
local $::yaml_load_code_works = 0;
my $code = $data->{code};
is(ref $code, 'CODE', 'deserialisation returned CODE');
$code->();
is($::yaml_load_code_works, 0, 'running the code did the right thing');
my $obj = $data->{object};
isa_ok($obj, 'CPAN::DeferredCode');
local $^W;
my $dummy = "$obj";
is($::yaml_load_code_works, 0, 'stringifying the obj does nothing');
}
{
local $CPAN::Config->{yaml_load_code} = 1;
my $data = CPAN->_yaml_loadfile($yaml_file)->[0];
local $::yaml_load_code_works = 0;
my $code = $data->{code};
is(ref $code, 'CODE', 'deserialisation returned CODE');
$code->();
is($::yaml_load_code_works, 1, 'running the code did the right thing');
my $obj = $data->{object};
isa_ok($obj, 'CPAN::DeferredCode');
my $dummy = "$obj";
is($::yaml_load_code_works, 2, 'stringifying the obj ran the code');
}
}
}
{
my $this_block_count;
my @no_proxy;
BEGIN {
@no_proxy = ({
domain => "at",
expect => 1,
},
{
domain => "kh",
expect => 0,
},
);
$this_block_count = 3 * @no_proxy;
$count += $this_block_count;
}
my $ftp = "CPAN::FTP";
$CPAN::Config->{http_proxy} = "http://myproxy.local/";
$CPAN::Config->{proxy_user} = "myproxyuser";
$CPAN::Config->{proxy_pass} = "myproxypass";
$ENV{PERL_MM_USE_DEFAULT} = 1;
for my $n (@no_proxy) {
$CPAN::Config->{no_proxy} = $n->{domain};
my $pftpvars = $ftp->_proxy_vars("http://battambang.kh/");
for my $k (qw(http_proxy proxy_user proxy_pass)) {
my $v = defined $pftpvars->{$k} ? $pftpvars->{$k} : "UNDEF";
ok($n->{expect}
==
!!$pftpvars->{$k},
"found $k\[$v] on domain[$n->{domain}]");
}
}
}
{
my $this_block_count;
BEGIN {
$this_block_count = 2;
$count += $this_block_count;
}
use CPAN::FirstTime;
my $keys = keys %CPAN::FirstTime::prompts;
ok $keys>=105, "found keys[$keys] prompts";
my $join = join "", %CPAN::FirstTime::prompts;
my $length = length $join;
ok $length>=20468, "found length[$length] prompts";
}
BEGIN{plan tests => $count}
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# End: