[svn:parrot] r36401 - in trunk: lib/Parrot/Configure t/steps

rurban at svn.parrot.org rurban at svn.parrot.org
Fri Feb 6 13:05:39 UTC 2009


Author: rurban
Date: Fri Feb  6 13:05:37 2009
New Revision: 36401
URL: https://trac.parrot.org/parrot/changeset/36401

Log:
Fix TT #279, report correct sourcefile line numbers
with makefile compiler errors, and a test for it.

Modified:
   trunk/lib/Parrot/Configure/Compiler.pm
   trunk/t/steps/gen_makefiles-01.t

Modified: trunk/lib/Parrot/Configure/Compiler.pm
==============================================================================
--- trunk/lib/Parrot/Configure/Compiler.pm	Fri Feb  6 07:42:45 2009	(r36400)
+++ trunk/lib/Parrot/Configure/Compiler.pm	Fri Feb  6 13:05:37 2009	(r36401)
@@ -34,6 +34,13 @@
     move_if_diff
 );
 
+# report the makefile and lineno
+sub makecroak {
+    my ($conf, $error) = @_;
+    my ($file, $line) = ($conf->{_compiler_file}, $conf->{_compiler_line});
+    die "$error at $file line $line\n";
+}
+
 our %file_types_info = (
     makefile => {
         comment_type    => '#',
@@ -396,9 +403,11 @@
     # this loop can not be implemented as a foreach loop as the body
     # is dependent on <IN> being evaluated lazily
 
+    $conf->{_compiler_file} = $source;
     my $former_truth = -1;
   LINE:
     while ( my $line = <$in> ) {
+        $conf->{_compiler_line} = $.;
 
         # everything after the line starting with #perl is eval'ed
         if ( $line =~ /^#perl/ && $options{feature_file} ) {
@@ -413,7 +422,7 @@
             # interpolate @foo@ values
             $text =~ s{ \@ (\w+) \@ }{\$conf->data->get("$1")}gx;
             eval $text;
-            die $@ if $@;
+            croak $@ if $@;
             last LINE;
         }
         if ( $options{conditioned_lines} ) {
@@ -531,7 +540,7 @@
 
         if ( $options{replace_slashes} ) {
             if ( $line =~ m{/$} ) {
-                die "$source:$.: line ends in a slash\n";
+                croak "$source:$.: line ends in a slash\n";
             }
 
             $line =~ s{(/+)}{
@@ -651,18 +660,18 @@
                     $op = 'NOT';
                 }
                 else {
-                    die "invalid op \"$op\" in \"$_[1]\" at \"$prevexpr\".\n";
+                    makecroak($conf, "invalid op \"$op\" in \"$_[1]\" at \"$prevexpr\"");
                 }
                 $key = next_expr($expr);
             }
             elsif ($prevexpr) {
-                die "Makefile conditional syntax error: missing op in \"$_[1]\" at \"$prevexpr\".\n";
+                makecroak($conf, "Makefile conditional syntax error: missing op in \"$_[1]\" at \"$prevexpr\"");
             }
             else {
                 last LOOP; # end of expr, nothing left
             }
             if ($prevexpr eq $expr) {
-                die "Makefile conditional parser error in \"$_[1]\" at \"$prevexpr\".\n";
+                makecroak($conf, "Makefile conditional parser error in \"$_[1]\" at \"$prevexpr\"");
             }
         }
         return $truth;

Modified: trunk/t/steps/gen_makefiles-01.t
==============================================================================
--- trunk/t/steps/gen_makefiles-01.t	Fri Feb  6 07:42:45 2009	(r36400)
+++ trunk/t/steps/gen_makefiles-01.t	Fri Feb  6 13:05:37 2009	(r36401)
@@ -76,7 +76,7 @@
        ["INVERSE_CONDITIONED_LINE(false)",  1],
       );
 }
-use Test::More tests => (7 + scalar(@cond_tests));
+use Test::More tests => (8 + scalar(@cond_tests));
 use Carp;
 use lib qw( . lib );
 use_ok('config::gen::makefiles');
@@ -140,9 +140,6 @@
     local $/;
     $f = <OUT>;
 }
-END {
-    unlink "Makefile_$$.in", "Makefile_$$.out";
-}
 $index = undef;
 for my $c (@cond_tests) {
     my $result = result($c);
@@ -155,7 +152,25 @@
     }
 }
 
+# TT #279: reporting the makefile line number
+# step gen::makefiles died during execution:
+#  invalid op "IF" in "#IF(bla)" at "(bla)" at Configure.pl line 72
+open IN, ">", "Makefile_$$.in";
+print IN "# Test reporting sourcefile line numbers. TT #279\n";
+print IN "#IF(IF(bla)):test\n";
+close IN;
+eval {
+    $conf->genfile("Makefile_$$.in", "Makefile_$$.out",
+                   (makefile => 1, conditioned_lines => 1));
+};
+my $error = $@;
+ok($error eq "invalid op \"bla\" in \"IF(bla)\" at \"(bla)\" at Makefile_$$.in line 2\n",
+   "report correct error line");
+
 pass("Completed all tests in $0");
+END {
+    unlink "Makefile_$$.in", "Makefile_$$.out";
+}
 
 ################### DOCUMENTATION ###################
 
@@ -176,6 +191,7 @@
 =head1 AUTHOR
 
 James E Keenan
+Reini Urban
 
 =head1 SEE ALSO
 


More information about the parrot-commits mailing list