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' );
111 # extra line feeds for MBX IPC
112 %wrong = ( Parent => "Parent\n", Child => "Parent\n" );
113 %right = ( Parent => "Parent\n", Child => "Child\n" );
115 my @module = qw(Parent Child)
118 my ($left, $right) = @_;
119 while (my ($key, $val) = each %$left) {
120 # warn "$key $val $$right{$key}";
122 unless $val eq $$right{$key};
128 my ($expect, $got) = @_;
129 foreach (sort keys %$expect) {
130 print "# $_ expect '$$expect{$_}' got '$$got{$_}'\n";
134 # Now test that the module tree behaves "wrongly" as expected
136 foreach my $module (@module) {
137 my $file = "$module--$$";
138 push @cleanup, $file;
139 open FH, ">$file" or die $!;
140 print FH "use $module;
141 print ${module}->foo;
148 foreach my $module (@module) {
149 print "# $runperl \"-I$inlib\" $module--$$\n";
150 ($output{$module} = `$runperl "-I$inlib" $module--$$`)
154 if (&fail (\%wrong, \%output)) {
155 print "not ok 7\n", &faildump (\%wrong, \%output);
162 mkdir $lib, 0777 or die $!;
164 $Devel::SelfStubber::JUST_STUBS=0;
167 foreach my $module (@module, 'Data', 'End') {
168 my $file = "$lib/$module.pm";
169 open FH, "$inlib/$module.pm" or die $!;
172 push @cleanup, $file;
173 open FH, ">$file" or die $!;
175 if ($contents =~ /__DATA__/) {
176 # This will die for any module with no __DATA__
177 Devel::SelfStubber->stub($module, $inlib);
188 foreach my $module (@module) {
189 print "# $runperl \"-I$lib\" $module--$$\n";
190 ($output{$module} = `$runperl "-I$lib" $module--$$`)
194 if (&fail (\%right, \%output)) {
195 print "not ok 9\n", &faildump (\%right, \%output);
201 # Check that the DATA handle stays open
202 system "$runperl -w \"-I$lib\" -MData -e Data::ok";
204 # Possibly a pointless test as this doesn't really verify that it's been
206 system "$runperl -w \"-I$lib\" -MEnd -e End::lime";
208 # But check that the documentation after the __END__ survived.
209 open FH, "$lib/End.pm" or die $!;
213 if (/Did the documentation here survive\?/) {
216 print "not ok 12 # information after an __END__ token seems to be lost\n";
220 ################ Parent.pm
228 ################ Child.pm
240 ################ Proto.pm
248 ################ Attribs.pm
256 sub lv : lvalue : method {
260 ################ Data.pm
271 ################ End.pm
281 Did the documentation here survive?