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);
86 open FH, ">$file" or die $!;
88 Devel::SelfStubber->stub('Attribs', $inlib);
90 print "ok 5\n"; # Checking that we did not die horribly.
93 open FH, $file or die $!;
96 if (@C == 2 && $C[0] =~ /^\s*sub\s+Attribs::baz\s+:\s*locked\s*;\s*$/
97 && $C[1] =~ /^\s*sub\s+Attribs::lv\s+:\s*lvalue\s*:\s*method\s*;\s*$/) {
101 print "# $_" foreach (@C);
107 # "wrong" and "right" may change if SelfLoader is changed.
108 my %wrong = ( Parent => 'Parent', Child => 'Parent' );
109 my %right = ( Parent => 'Parent', Child => 'Child' );
110 my @module = qw(Parent Child)
113 my ($left, $right) = @_;
114 while (my ($key, $val) = each %$left) {
115 # warn "$key $val $$right{$key}";
117 unless $val eq $$right{$key};
123 my ($expect, $got) = @_;
124 foreach (sort keys %$expect) {
125 print "# $_ expect '$$expect{$_}' got '$$got{$_}'\n";
129 # Now test that the module tree behaves "wrongly" as expected
131 foreach my $module (@module) {
132 my $file = "$module--$$";
133 push @cleanup, $file;
134 open FH, ">$file" or die $!;
135 print FH "use $module;
136 print ${module}->foo;
143 foreach my $module (@module) {
144 print "# $runperl \"-I$inlib\" $module--$$\n";
145 ($output{$module} = `$runperl "-I$inlib" $module--$$`)
149 if (&fail (\%wrong, \%output)) {
150 print "not ok 7\n", &faildump (\%wrong, \%output);
157 mkdir $lib, 0777 or die $!;
159 $Devel::SelfStubber::JUST_STUBS=0;
162 foreach my $module (@module, 'Data', 'End') {
163 my $file = "$lib/$module.pm";
164 open FH, "$inlib/$module.pm" or die $!;
167 push @cleanup, $file;
168 open FH, ">$file" or die $!;
170 if ($contents =~ /__DATA__/) {
171 # This will die for any module with no __DATA__
172 Devel::SelfStubber->stub($module, $inlib);
183 foreach my $module (@module) {
184 print "# $runperl \"-I$lib\" $module--$$\n";
185 ($output{$module} = `$runperl "-I$lib" $module--$$`)
189 if (&fail (\%right, \%output)) {
190 print "not ok 9\n", &faildump (\%right, \%output);
196 # Check that the DATA handle stays open
197 system "$runperl -w \"-I$lib\" -MData -e Data::ok";
199 # Possibly a pointless test as this doesn't really verify that it's been
201 system "$runperl -w \"-I$lib\" -MEnd -e End::lime";
203 # But check that the documentation after the __END__ survived.
204 open FH, "$lib/End.pm" or die $!;
208 if (/Did the documentation here survive\?/) {
211 print "not ok 12 # information after an __END__ token seems to be lost\n";
215 ################ Parent.pm
223 ################ Child.pm
235 ################ Proto.pm
243 ################ Attribs.pm
251 sub lv : lvalue : method {
255 ################ Data.pm
266 ################ End.pm
276 Did the documentation here survive?