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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
|
BEGIN { # Magic Perl CORE pragma
if ($ENV{PERL_CORE}) {
chdir 't' if -d 't';
@INC = '../lib';
}
}
my @extra;
BEGIN {
eval { require ifdef };
shift @INC;
if ($@) {
@extra = ('');
} else {
$ENV{IFDEF_DIFF} = 0;
@extra = ('','-Mifdef=FOO ','-Mifdef=DEBUGGING ' );
}
} #BEGIN
use Test::More tests =>
2 +
2 * (
3 +
(@extra * 2 * (
(5 * (12 + 2 * 6 + 2 * 3)) +
(3*3) +
(3*3) +
(2*3) +
(3*3) +
(3*3) +
(2*3)
))
) +
1;
use strict;
BEGIN { eval {require warnings} or do {$INC{'warnings.pm'} = ''} } #BEGIN
use warnings;
use lib 'lib';
BEGIN {use_ok( 'load','ondemand' )}
can_ok( 'load',qw(
AUTOLOAD
import
) );
my $module = "Foo";
my $filepm = "$module.pm";
my $always = "always $load::VERSION";
my $ondemand = "ondemand $load::VERSION";
my $debugging_only = "debugging_only $load::VERSION";
my $ondemand_debugging_only= "ondemand_debugging_only $load::VERSION";
my $bs = ($^O =~ m#MSWin#) ? '' : '\\' ; # Argh, Windows!
my $INC = qq{@{[map {"-I$_"} @INC]}};
foreach my $emulation ('','AutoLoader') {
my $testmodule = $emulation ? $emulation : 'load';
my $use = ($testmodule eq 'AutoLoader') ?
"$testmodule 'AUTOLOAD'" : $testmodule;
ok( (open OUT, ">$filepm"), "Create dummy module for testing $testmodule" );
ok( (print OUT <<EOD),"Write the dummy module for testing $testmodule" );
package $module;
use $use;
\$VERSION = '$load::VERSION';
sub always {
print "always \$VERSION";
}
=begin DEBUGGING
sub debugging_only {
print "debugging_only \$VERSION";
}
=cut
1;
__END__
sub ondemand {
print "ondemand \$VERSION";
}
sub empty {
undef;
}
=begin DEBUGGING
sub ondemand_debugging_only {
print "ondemand_debugging_only \$VERSION";
}
=cut
EOD
ok( (close OUT),"Close the dummy module for $testmodule" );
test( $emulation );
}
ok( (unlink $filepm,'stderr'),"Clean up dummy module and stderr file" );
1 while unlink $filepm,'stderr'; # multiversioned filesystems
#-------------------------------------------------------------------------
sub test {
my $emulation = shift;
foreach my $extra (@extra) {
my $debugging = $extra =~ m#DEBUGGING#;
foreach ('','-T ') {
$INC = "$_$INC";
$ENV{'LOAD_NOW'} = 0;
$ENV{'LOAD_TRACE'} = 0;
foreach (qw(env now ondemand dontscan),'') {
my $action;
if ($_ eq 'env') {
$ENV{'LOAD_NOW'} = 1;
$action = $emulation ? "-Mload=$emulation" : '';
} elsif ($_) {
$action = $emulation ? "-Mload=$emulation,$_" : "-Mload=$_";
} else {
$action = $emulation ? "-Mload=$emulation" : "-Mload";
}
ok( (open( IN,
qq{$^X -I. -Ilib $INC $extra$action -MFoo -e "${module}::always()" |} )),
"Open check always on $action" );
is( scalar <IN>,$always,"Check always with $action" );
ok( (close IN),"Close check always with $action" );
my $do = qq{$^X -I. $INC $extra$action -MFoo -e "${module}::ondemand()" |};
ok( (open( IN,$do )),"Open check ondemand with $action" );
is( scalar <IN>,$ondemand,"Check ondemand with $action")
or die $do;
ok( (close IN),"Close check ondemand with $action" );
ok( (open( IN,
qq{$^X -I. $INC $extra$action -MFoo -e "${module}::debugging_only()" 2>stderr |} )),
"Open check debugging_only on $action" );
if ($debugging) {
is( scalar <IN>,$debugging_only,
"Check debugging_only with $_ and $action" );
ok( (close IN),
"Close check debugging_only $_ and with $action" );
} else {
ok( !defined <IN>,"Check $_ with $action" );
ok( 1 ,"Extra ok for unopened pipe for $_ with $action" );
}
ok( (open( IN,
qq{$^X -I. $INC $extra$action -MFoo -e "${module}::ondemand_debugging_only()" 2>stderr |} )),
"Open check ondemand_debugging_only with $action" );
if ($debugging) {
is( scalar <IN>,$ondemand_debugging_only,
"Check ondemand_debugging_only with $action" );
ok( (close IN),
"Close check ondemand_debugging_only with $action" );
} else {
ok( !defined <IN>,"Check $_ with $action" );
ok( 1 ,"Extra ok for unopened pipe for $_ with $action" );
}
foreach (qw(always ondemand)) {
ok( (open( IN,
qq{$^X -I. $INC $extra$action -MFoo -e "print exists $bs\$Foo::{$_}"|})),
"Open check exists $_ with $action" );
is( scalar <IN>,'1',"Check exists $_ with $action" );
ok( (close IN),"Close check exists $_ with $action" );
ok( (open( IN,
qq{$^X -I. $INC $extra$action -MFoo -e "print Foo->can($_)" |} )),
"Open check Foo->can( $_ ) with $action" );
ok( (<IN> =~ m#^CODE#),"Check Foo->can( $_ ) with $action");
ok( (close IN),"Close check Foo->can( $_ ) with $action" );
}
foreach ("exists $bs\$Foo::{bar}","Foo->can(bar)") {
ok( (open( IN,
qq{$^X -I. $INC $extra$action -MFoo -e "$_" |} )),
"Open check $_ with $action" );
ok( !defined <IN>,"Check $_ with $action" );
ok( (close IN),"Close check $_ bar with $action" );
}
}
$ENV{'LOAD_NOW'} = 0;
$ENV{'LOAD_TRACE'} = 1;
foreach ('',qw(ondemand dontscan)) {
my $action;
if ($_) {
$action = $emulation ? "-Mload=$emulation,$_" : "-Mload=$_";
} else {
$action = $emulation ? "-Mload=$emulation" : '';
}
ok( (open( IN, qq{$^X -I. $INC $extra$action -MFoo -e "" 2>&1 |} )),
"Open trace store $action" );
my $ondemand = $debugging ? <<'EOD' : '';
load: store Foo::ondemand_debugging_only, line \d+ \(offset \d+, \d+ bytes\)
EOD
like( join( '',<IN> ),
qr/load: store Foo::ondemand, line \d+ \(offset \d+, \d+ bytes\)
load: store Foo::empty, line \d+ \(offset \d+, \d+ bytes\)
$ondemand$/,"Check trace ondemand $action" );
ok( (close IN),"Close trace ondemand $action" );
}
foreach ('',qw(ondemand dontscan)) {
my $action;
if ($_) {
$action = $emulation ? "-Mload=$emulation,$_" : "-Mload=$_";
} else {
$action = $emulation ? "-Mload=$emulation" : '';
}
my $ondemand = $debugging ? <<'EOD' : '';
load: store Foo::ondemand_debugging_only, line \d+ \(offset \d+, \d+ bytes\)
EOD
ok( (open( IN, qq{$^X -I. $INC $extra$action -MFoo -e "Foo::empty()" 2>&1|})),
"Open trace store load $action" );
like( join( '',<IN> ),
qr/load: store Foo::ondemand, line \d+ \(offset \d+, \d+ bytes\)
load: store Foo::empty, line \d+ \(offset \d+, \d+ bytes\)
${ondemand}load: ondemand Foo::empty, line \d+ \(offset \d+, \d+ bytes\)
$/,"Check trace ondemand $action" );
ok( (close IN),"Close trace ondemand $action: $!" );
}
foreach (qw(now env)) {
my $action;
if ($_ eq 'env') {
$ENV{'LOAD_NOW'} = 1;
$action = $emulation ? "-Mload=$emulation" : '';
} else {
$action = $emulation ? "-Mload=$emulation,$_" : "-Mload=$_";
}
ok( (open( IN, qq{$^X -I. $INC $extra$action -MFoo -e "Foo::empty()" 2>&1|})),
"Open trace store load $action" );
like( join( '',<IN> ),
qr/load: now Foo, line \d+ \(offset \d+, onwards\)
$/,"Check trace now $action" );
ok( (close IN),"Close trace ondemand $action" );
}
$ENV{'LOAD_NOW'} = 0;
$ENV{'LOAD_TRACE'} = 1;
SKIP: {
require Config;
skip( "No threads support available", (3*3)+(3*3)+(2*3) )
if !$Config::Config{useithreads};
skip( "Cannot check bare AutoLoader yet", (3*3)+(3*3)+(2*3) )
if $emulation;
my $ondemand = $debugging ? <<'EOD' : '';
load \[0\]: store Foo::ondemand_debugging_only, line \d+ \(offset \d+, \d+ bytes\)
EOD
foreach ('',qw(ondemand dontscan)) {
my $action;
if ($_) {
$action = $emulation ?
"-Mload=$emulation,$_" : "-Mload=$_";
} else {
$action = $emulation ? "-Mload=$emulation" : '';
}
my $do = qq{$^X -I. $INC $extra$action -Mthreads -MFoo -e "" 2>&1 |};
ok( (open( IN,$do )),
"Open trace store $action with threads" );
like( join( '',<IN> ),
qr/load \[0\]: store Foo::ondemand, line \d+ \(offset \d+, \d+ bytes\)
load \[0\]: store Foo::empty, line \d+ \(offset \d+, \d+ bytes\)
$ondemand$/,"Check trace ondemand $action with threads" ) or die $do;
ok( (close IN),"Close trace ondemand $action with threads");
}
foreach ('',qw(-Mload=ondemand -Mload=dontscan)) {
my $action = $_;
my $do = qq{$^X -I. $INC $extra$action -Mthreads -MFoo -e "Foo::empty()" 2>&1 |};
ok((open( IN,$do)),
"Open trace store load $action with threads" );
like( join( '',<IN> ),
qr/load \[0\]: store Foo::ondemand, line \d+ \(offset \d+, \d+ bytes\)
load \[0\]: store Foo::empty, line \d+ \(offset \d+, \d+ bytes\)
${ondemand}load \[0\]: ondemand Foo::empty, line \d+ \(offset \d+, \d+ bytes\)
$/,"Check trace ondemand $action with threads" ) or die $do;
ok( (close IN),"Close trace ondemand $action with threads");
}
foreach (qw(now env)) {
my $action;
if ($_ eq 'env') {
$ENV{'LOAD_NOW'} = 1;
$action = $emulation ? "-Mload=$emulation" : '';
} else {
$action = $emulation ?
"-Mload=$emulation,$_" : "-Mload=$_";
}
ok( (open(IN, qq{$^X -I. $INC $extra$action -Mthreads -MFoo -e "Foo::empty()" 2>&1 |})),
"Open trace store load $action with threads" );
like( join( '',<IN> ),
qr/load \[0\]: now Foo, line \d+ \(offset \d+, onwards\)
$/,"Check trace now $action with threads" );
ok( (close IN),"Close trace ondemand $action with threads");
}
}
}
}
} #test
|