[svn:parrot] r37628 - trunk/t/examples

coke at svn.parrot.org coke at svn.parrot.org
Sun Mar 22 00:12:37 UTC 2009


Author: coke
Date: Sun Mar 22 00:12:36 2009
New Revision: 37628
URL: https://trac.parrot.org/parrot/changeset/37628

Log:
[t] - add TODO testing of examples
-- this means we need a one line description
-- so we track the line number of the offending test
--- so we change our algorithm from a simple RE

Modified:
   trunk/t/examples/pod.t

Modified: trunk/t/examples/pod.t
==============================================================================
--- trunk/t/examples/pod.t	Sun Mar 22 00:02:13 2009	(r37627)
+++ trunk/t/examples/pod.t	Sun Mar 22 00:12:36 2009	(r37628)
@@ -44,29 +44,52 @@
               $PConfig{test_prog} . " -o " . File::Spec->devnull() . " " .
               $tempfile;
 
-    my $description = $snippet->{file} . "\n" . $snippet->{code};
+    my $description = $snippet->{file} . ':' .$snippet->{line};
+
+    TODO: {
+        local $TODO = $snippet->{todo} if $snippet->{todo};
+        is(system($cmd), 0 , $description);
+    }
 
-    is(system($cmd), 0 , $description);
 }
 
 sub get_samples {
     my $file = shift;
 
-    my $contents;
-    {
-        local undef $/;
-        open my $fh, '<', $file;
-        $contents = <$fh>;
-    }
+    open my $fh, '<', $file;
 
     my @snippets;
-    while ($contents =~ /^=begin (PIR|PASM)$(.*?)^=end \1$/smg) {
-        push @snippets, {
-            file => $file,
-            type => $1,
-            code => $2,
-        };
+    my $snippet = {};
+    my $code = '';
+    my $target;
+
+    my $in_code = 0;
+    while (my $line = <$fh>) {
+
+        if ( $in_code )  {
+            if ($line =~ /^=end $target$/) {
+                $snippet->{code} = $code;
+                push @snippets, $snippet;
+                $code = '';
+                $snippet = {};
+                $in_code = 0;
+            }
+            else {
+                $code .= $line;
+            }
+        }
+        elsif ( $line =~ /^=begin ((PIR|PASM)( .*)?)$/ ) {
+            $in_code = 1;
+            $snippet->{file} = $file;
+            $snippet->{line} = $.;
+            $snippet->{type} = $2;
+            $snippet->{todo} = $3;
+            $target = $1; 
+        }
     }
+
+    # We don't check for an example in progress here because no file
+    # should end with =end.
     return @snippets;
 }
 


More information about the parrot-commits mailing list