9 use Devel::SelfStubber;
11 my $runperl = "$^X \"-I../lib\"";
20 foreach my $file (reverse @cleanup) {
21 unlink $file or warn "unlink $file failed: $!" while -f $file;
22 rmdir $file or warn "rmdir $file failed: $!" if -d $file;
27 mkdir $inlib, 0777 or die $!;
28 push @cleanup, $inlib;
31 if (/^\#{16,}\s+(.*)/) {
32 my $file = "$inlib/$1";
34 open FH, ">$file" or die $!;
44 open FH, ">$file" or die $!;
46 Devel::SelfStubber->stub('Child', $inlib);
51 open FH, $file or die $!;
54 if (@A == 1 && $A[0] =~ /^\s*sub\s+Child::foo\s*;\s*$/) {
58 print "# $_" foreach (@A);
65 open FH, ">$file" or die $!;
67 Devel::SelfStubber->stub('Proto', $inlib);
69 print "ok 3\n"; # Checking that we did not die horribly.
72 open FH, $file or die $!;
75 if (@B == 1 && $B[0] =~ /^\s*sub\s+Proto::bar\s*\(\$\$\);\s*$/) {
79 print "# $_" foreach (@B);
88 open FH, ">$file" or die $!;
90 Devel::SelfStubber->stub('Attribs', $inlib);
92 print "ok 5\n"; # Checking that we did not die horribly.
95 open FH, $file or die $!;
98 if (@C == 2 && $C[0] =~ /^\s*sub\s+Attribs::baz\s+:\s*locked\s*;\s*$/
99 && $C[1] =~ /^\s*sub\s+Attribs::lv\s+:\s*lvalue\s*:\s*method\s*;\s*$/) {
103 print "# $_" foreach (@C);
109 # "wrong" and "right" may change if SelfLoader is changed.
110 my %wrong = ( Parent => 'Parent', Child => 'Parent' );
111 my %right = ( Parent => 'Parent', Child => 'Child' );
113 # extra line feeds for MBX IPC
114 %wrong = ( Parent => "Parent\n", Child => "Parent\n" );
115 %right = ( Parent => "Parent\n", Child => "Child\n" );
117 my @module = qw(Parent Child)
120 my ($left, $right) = @_;
121 while (my ($key, $val) = each %$left) {
122 # warn "$key $val $$right{$key}";
124 unless $val eq $$right{$key};
130 my ($expect, $got) = @_;
131 foreach (sort keys %$expect) {
132 print "# $_ expect '$$expect{$_}' got '$$got{$_}'\n";
136 # Now test that the module tree behaves "wrongly" as expected
138 foreach my $module (@module) {
139 my $file = "$module--$$";
140 push @cleanup, $file;
141 open FH, ">$file" or die $!;
142 print FH "use $module;
143 print ${module}->foo;
150 foreach my $module (@module) {
151 print "# $runperl \"-I$inlib\" $module--$$\n";
152 ($output{$module} = `$runperl "-I$inlib" $module--$$`)
156 if (&fail (\%wrong, \%output)) {
157 print "not ok 7\n", &faildump (\%wrong, \%output);
164 mkdir $lib, 0777 or die $!;
166 $Devel::SelfStubber::JUST_STUBS=0;
169 foreach my $module (@module, 'Data', 'End') {
170 my $file = "$lib/$module.pm";
171 open FH, "$inlib/$module.pm" or die $!;
174 push @cleanup, $file;
175 open FH, ">$file" or die $!;
177 if ($contents =~ /__DATA__/) {
178 # This will die for any module with no __DATA__
179 Devel::SelfStubber->stub($module, $inlib);
190 foreach my $module (@module) {
191 print "# $runperl \"-I$lib\" $module--$$\n";
192 ($output{$module} = `$runperl "-I$lib" $module--$$`)
196 if (&fail (\%right, \%output)) {
197 print "not ok 9\n", &faildump (\%right, \%output);
203 # Check that the DATA handle stays open
204 system "$runperl -w \"-I$lib\" -MData -e Data::ok";
206 # Possibly a pointless test as this doesn't really verify that it's been
208 system "$runperl -w \"-I$lib\" -MEnd -e End::lime";
210 # But check that the documentation after the __END__ survived.
211 open FH, "$lib/End.pm" or die $!;
215 if (/Did the documentation here survive\?/) {
218 print "not ok 12 # information after an __END__ token seems to be lost\n";
222 ################ Parent.pm
230 ################ Child.pm
242 ################ Proto.pm
250 ################ Attribs.pm
258 sub lv : lvalue : method {
262 ################ Data.pm
273 ################ End.pm
283 Did the documentation here survive?