9 use Devel::SelfStubber;
11 my $runperl = './perl';
18 foreach my $file (reverse @cleanup) {
19 unlink $file or warn "unlink $file failed: $!" while -f $file;
20 rmdir $file or warn "rmdir $file failed: $!" if -d $file;
25 mkdir $inlib, 0777 or die $!;
26 push @cleanup, $inlib;
29 if (/^\#{16,}\s+(.*)/) {
30 my $file = "$inlib/$1";
32 open FH, ">$file" or die $!;
42 open FH, ">$file" or die $!;
44 Devel::SelfStubber->stub('Child', $inlib);
49 open FH, $file or die $!;
52 if (@A == 1 && $A[0] =~ /^\s*sub\s+Child::foo\s*;\s*$/) {
56 print "# $_" foreach (@A);
63 open FH, ">$file" or die $!;
65 Devel::SelfStubber->stub('Proto', $inlib);
67 print "ok 3\n"; # Checking that we did not die horribly.
70 open FH, $file or die $!;
73 if (@B == 1 && $B[0] =~ /^\s*sub\s+Proto::bar\s*\(\$\$\);\s*$/) {
77 print "# $_" foreach (@B);
83 # "wrong" and "right" may change if SelfLoader is changed.
84 my %wrong = ( Parent => 'Parent', Child => 'Parent' );
85 my %right = ( Parent => 'Parent', Child => 'Child' );
86 my @module = qw(Parent Child)
89 my ($left, $right) = @_;
90 while (my ($key, $val) = each %$left) {
91 # warn "$key $val $$right{$key}";
93 unless $val eq $$right{$key};
99 my ($expect, $got) = @_;
100 foreach (sort keys %$expect) {
101 print "# $_ expect '$$expect{$_}' got '$$got{$_}'\n";
105 # Now test that the module tree behaves "wrongly" as expected
107 foreach my $module (@module) {
108 my $file = "$module--$$";
109 push @cleanup, $file;
110 open FH, ">$file" or die $!;
111 print FH "use $module;
112 print ${module}->foo;
119 foreach my $module (@module) {
120 ($output{$module} = `$runperl -I $inlib $module--$$`)
124 if (&fail (\%wrong, \%output)) {
125 print "not ok 5\n", &faildump (\%wrong, \%output);
132 mkdir $lib, 0777 or die $!;
134 $Devel::SelfStubber::JUST_STUBS=0;
137 foreach my $module (@module) {
138 my $file = "$lib/$module.pm";
139 open FH, "$inlib/$module.pm" or die $!;
142 push @cleanup, $file;
143 open FH, ">$file" or die $!;
145 if ($contents =~ /__DATA__/) {
146 # This will die for any module with no __DATA__
147 Devel::SelfStubber->stub($module, $inlib);
158 foreach my $module (@module) {
159 ($output{$module} = `$runperl -I $lib $module--$$`)
163 if (&fail (\%right, \%output)) {
164 print "not ok 7\n", &faildump (\%right, \%output);
171 ################ Parent.pm
179 ################ Child.pm
191 ################ Proto.pm