4 use Devel::SelfStubber;
5 use File::Spec::Functions;
9 # ensure correct output ordering for system() calls
11 select STDERR; $| = 1; select STDOUT; $| = 1;
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+(.*)/) {
31 my $file = catfile(curdir(),$inlib,$f);
33 open FH, ">$file" or die $!;
43 open FH, ">$file" or die $!;
45 Devel::SelfStubber->stub('xChild', $inlib);
50 open FH, $file or die $!;
53 if (@A == 1 && $A[0] =~ /^\s*sub\s+xChild::foo\s*;\s*$/) {
57 print "# $_" foreach (@A);
64 open FH, ">$file" or die $!;
66 Devel::SelfStubber->stub('Proto', $inlib);
68 print "ok 3\n"; # Checking that we did not die horribly.
71 open FH, $file or die $!;
74 if (@B == 1 && $B[0] =~ /^\s*sub\s+Proto::bar\s*\(\$\$\);\s*$/) {
78 print "# $_" foreach (@B);
87 open FH, ">$file" or die $!;
89 Devel::SelfStubber->stub('Attribs', $inlib);
91 print "ok 5\n"; # Checking that we did not die horribly.
94 open FH, $file or die $!;
97 if (@C == 2 && $C[0] =~ /^\s*sub\s+Attribs::baz\s+:\s*locked\s*;\s*$/
98 && $C[1] =~ /^\s*sub\s+Attribs::lv\s+:\s*lvalue\s*:\s*method\s*;\s*$/) {
102 print "# $_" foreach (@C);
108 # "wrong" and "right" may change if SelfLoader is changed.
109 my %wrong = ( xParent => 'xParent', xChild => 'xParent' );
110 my %right = ( xParent => 'xParent', xChild => 'xChild' );
112 # extra line feeds for MBX IPC
113 %wrong = ( xParent => "xParent\n", xChild => "xParent\n" );
114 %right = ( xParent => "xParent\n", xChild => "xChild\n" );
116 my @module = qw(xParent xChild)
119 my ($left, $right) = @_;
120 while (my ($key, $val) = each %$left) {
121 # warn "$key $val $$right{$key}";
123 unless $val eq $$right{$key};
129 my ($expect, $got) = @_;
130 foreach (sort keys %$expect) {
131 print "# $_ expect '$$expect{$_}' got '$$got{$_}'\n";
135 # Now test that the module tree behaves "wrongly" as expected
137 foreach my $module (@module) {
138 my $file = "$module--$$";
139 push @cleanup, $file;
140 open FH, ">$file" or die $!;
141 print FH "use $module;
142 print ${module}->foo;
149 foreach my $module (@module) {
150 print "# $runperl \"-I$inlib\" $module--$$\n";
151 ($output{$module} = `$runperl "-I$inlib" $module--$$`)
155 if (&fail (\%wrong, \%output)) {
156 print "not ok 7\n", &faildump (\%wrong, \%output);
163 mkdir $lib, 0777 or die $!;
165 $Devel::SelfStubber::JUST_STUBS=0;
168 foreach my $module (@module, 'Data', 'End') {
169 my $file = catfile(curdir(),$lib,"$module.pm");
170 my $fileo = catfile(curdir(),$inlib,"$module.pm");
171 open FH, $fileo or die "Can't open $fileo: $!";
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, catfile(curdir(),$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 ################ xParent.pm
230 ################ xChild.pm
242 ################ Proto.pm
250 ################ Attribs.pm
258 sub lv : lvalue : method {
262 ################ Data.pm
273 ################ End.pm
283 Did the documentation here survive?