9 use Devel::SelfStubber;
11 my $runperl = "$^X \"-I../lib\"";
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 print "# $runperl \"-I$inlib\" $module--$$\n";
121 ($output{$module} = `$runperl "-I$inlib" $module--$$`)
125 if (&fail (\%wrong, \%output)) {
126 print "not ok 5\n", &faildump (\%wrong, \%output);
133 mkdir $lib, 0777 or die $!;
135 $Devel::SelfStubber::JUST_STUBS=0;
138 foreach my $module (@module) {
139 my $file = "$lib/$module.pm";
140 open FH, "$inlib/$module.pm" or die $!;
143 push @cleanup, $file;
144 open FH, ">$file" or die $!;
146 if ($contents =~ /__DATA__/) {
147 # This will die for any module with no __DATA__
148 Devel::SelfStubber->stub($module, $inlib);
159 foreach my $module (@module) {
160 print "# $runperl \"-I$lib\" $module--$$\n";
161 ($output{$module} = `$runperl "-I$lib" $module--$$`)
165 if (&fail (\%right, \%output)) {
166 print "not ok 7\n", &faildump (\%right, \%output);
173 ################ Parent.pm
181 ################ Child.pm
193 ################ Proto.pm