Below's a patch that adds #line support to Pod::Tests, making it easier
to find the original line the test is on.  This makes output from
SelfTest trivial.

I've also really been wishing for 

   =for testing foo()
      ok( foo(1), 2 ) ; 
      ok( foo(3), 4 ) ; 
      ok( foo(5), 6 ) ; 
      ok( foo(7), 8 ) ; 

such that if a test failed in Foo.pm, the message would be something like

   not ok 1
   # Test 1 got: '1' (Foo.pm at line 37)
   #   Expected: '2' (foo())

just to save lots of retyping of C<, "foo()"> everywhere.  Getting the
file and line of Foo.pm and having it fill in the test name nicely makes
it really easy to nail down what's going wrong very quickly.

Would a patch for this be welcome?

- Barrie

--- lib/Pod/Tests.pm    Sat Mar  3 23:09:43 2001
+++ /usr/local/lib/perl5/site_perl/5.6.1/Pod/Tests.pm   Tue Apr  3 11:33:59 2001
@@ -2,7 +2,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = '0.02';
+$VERSION = '0.021';
 
 
 =pod
@@ -164,6 +164,7 @@
 
     $self->_init;
     foreach (@_) {
+        $self->{_linenum}++;
         if( /^=(\w.*)/ and $self->{_sawblank} and !$self->{_inblock}) {
             $self->{_inpod} = 1;
 
@@ -208,11 +209,10 @@
             }
         }
 
-        $self->{_linenum}++;
     }
 
-    push @{$self->{example}}, @{$self->{_for}{example}};
-    push @{$self->{testing}}, @{$self->{_for}{testing}};
+    push @{$self->{example}}, @{$self->{_for}{example}} if $self->{_for}{example} ;
+    push @{$self->{testing}}, @{$self->{_for}{testing}} if $self->{_for}{testing} ;
 }
 
 =begin __private
@@ -264,8 +264,9 @@
     my($self) = shift;
 
     my $pod = {
-               code => $self->{_currpod},
-               line => $self->{_forstart},
+               code     => $self->{_currpod},
+               filename => $self->{_filename},
+               line     => $self->{_forstart},
               };
 
     push @{$self->{_for}{$self->{_infor}}}, $pod if
@@ -303,8 +304,9 @@
     my($self) = shift;
 
     my $pod = {
-               code => $self->{_currpod},
-               line => $self->{_blockstart},
+               code     => $self->{_currpod},
+               filename => $self->{_filename},
+               line     => $self->{_blockstart},
               };
 
     push @{$self->{_for}{$self->{_inblock}}}, $pod if
@@ -334,7 +336,11 @@
         return;
     }
 
-    return $self->parse_fh(\*POD);
+    $self->{_filename} = $file ;
+    my $r = $self->parse_fh(\*POD);
+    $self->{_filename} = undef ;
+
+    return $r ;
 }
 
 
@@ -397,10 +403,12 @@
     my($self, @tests) = @_;
 
     my @code = ();
-
     foreach my $test (@tests) {
+        my $fn = $test->{filename}
+            ? " $test->{filename}"
+            : "" ;
         push @code, <<CODE;
-# From line $test->{line}
+#line $test->{line} $fn
 $test->{code}
 CODE
 
@@ -426,10 +434,14 @@
 
     my @code = ();
     foreach my $example (@examples) {
+        my $fn = $example->{filename}
+            ? " $example->{filename}"
+            : "" ;
         push @code, <<CODE;
 # From line $example->{line}
 eval {
     local \$^W = 0;
+    #line $example->{line} $fn
     $example->{code};
 };
 ok(!\$@);
@@ -439,6 +451,7 @@
 
     return @code;
 }
+
 
 =back
 

Reply via email to