Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79449 - in trunk/tools/build/v2: engine test
From: jurko.gospodnetic_at_[hidden]
Date: 2012-07-12 09:21:47


Author: jurko
Date: 2012-07-12 09:21:46 EDT (Thu, 12 Jul 2012)
New Revision: 79449
URL: http://svn.boost.org/trac/boost/changeset/79449

Log:
Fixed a Boost Jam error reporting bug where it would report the error as originating from an incorrect file & line in case the error occurred after parsing the final token in some file. It usually reported it as the file including the file in question or, if the file is the main project build script not included from anywhere, then it reported the error as originating from file '(builtin)' and line -1. Added a related internal Boost Build unit test (core_source_line_tracking.py).
Added:
   trunk/tools/build/v2/test/core_source_line_tracking.py (contents, props changed)
Text files modified:
   trunk/tools/build/v2/engine/parse.c | 2 +-
   trunk/tools/build/v2/engine/scan.c | 20 ++++++--------------
   trunk/tools/build/v2/engine/scan.h | 2 +-
   trunk/tools/build/v2/test/test_all.py | 1 +
   4 files changed, 9 insertions(+), 16 deletions(-)

Modified: trunk/tools/build/v2/engine/parse.c
==============================================================================
--- trunk/tools/build/v2/engine/parse.c (original)
+++ trunk/tools/build/v2/engine/parse.c 2012-07-12 09:21:46 EDT (Thu, 12 Jul 2012)
@@ -94,7 +94,7 @@
     }
     else
     {
- yyinput_stream( &p->file, &p->line );
+ yyinput_last_read_token( &p->file, &p->line );
         p->file = object_copy( p->file );
     }
 

Modified: trunk/tools/build/v2/engine/scan.c
==============================================================================
--- trunk/tools/build/v2/engine/scan.c (original)
+++ trunk/tools/build/v2/engine/scan.c 2012-07-12 09:21:46 EDT (Thu, 12 Jul 2012)
@@ -71,9 +71,6 @@
      * string literal or action body, in which case yylval location information
      * will hold the information about where the token started while incp will
      * hold the information about where reading it broke.
- *
- * TODO: Test the theory about when yylval and incp location information are
- * the same and when they differ.
      */
     printf( "%s:%d: %s at %s\n", object_str( yylval.file ), yylval.line, s,
             symdump( &yylval ) );
@@ -397,16 +394,11 @@
  * transitions that produce a parse.
  */
 
-void yyinput_stream( OBJECT * * name, int * line )
+void yyinput_last_read_token( OBJECT * * name, int * line )
 {
- if ( incp )
- {
- *name = incp->fname;
- *line = incp->line;
- }
- else
- {
- *name = constant_builtin;
- *line = -1;
- }
+ /* TODO: Consider whether and when we might want to report where the last
+ * read token ended, e.g. EOF errors inside string literals.
+ */
+ *name = yylval.file;
+ *line = yylval.line;
 }

Modified: trunk/tools/build/v2/engine/scan.h
==============================================================================
--- trunk/tools/build/v2/engine/scan.h (original)
+++ trunk/tools/build/v2/engine/scan.h 2012-07-12 09:21:46 EDT (Thu, 12 Jul 2012)
@@ -54,7 +54,7 @@
 int yyline();
 int yylex();
 int yyparse();
-void yyinput_stream( OBJECT * * name, int * line );
+void yyinput_last_read_token( OBJECT * * name, int * line );
 
 #define SCAN_NORMAL 0 /* normal parsing */
 #define SCAN_STRING 1 /* look only for matching } */

Added: trunk/tools/build/v2/test/core_source_line_tracking.py
==============================================================================
--- (empty file)
+++ trunk/tools/build/v2/test/core_source_line_tracking.py 2012-07-12 09:21:46 EDT (Thu, 12 Jul 2012)
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+
+# Copyright 2012. Jurko Gospodnetic
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+
+# Test Boost Jam parser's source line tracking & reporting.
+
+import BoostBuild
+
+
+def test_eof_in_string():
+ t = BoostBuild.Tester(pass_toolset=False)
+ t.write("file.jam", '\n\n\naaa = "\n\n\n\n\n\n')
+ t.run_build_system(["-ffile.jam"], status=1)
+ t.expect_output_line('file.jam:4: unmatched " in string at keyword =')
+ t.expect_output_line("file.jam:4: syntax error at EOF")
+ t.cleanup()
+
+
+def test_error_missing_argument(eof):
+ """
+ This use case used to cause a missing argument error to be reported in
+ module '(builtin)' in line -1 when the input file did not contain a
+ trailing newline.
+
+ """
+ t = BoostBuild.Tester(pass_toolset=False)
+ t.write("file.jam", """\
+rule f ( param ) { }
+f ;%s""" % __trailing_newline(eof))
+ t.run_build_system(["-ffile.jam"], status=1)
+ t.expect_output_line("file.jam:2: in module scope")
+ t.expect_output_line("file.jam:1:see definition of rule 'f' being called")
+ t.cleanup()
+
+
+def test_error_syntax(eof):
+ t = BoostBuild.Tester(pass_toolset=False)
+ t.write("file.jam", "ECHO%s" % __trailing_newline(eof))
+ t.run_build_system(["-ffile.jam"], status=1)
+ t.expect_output_line("file.jam:1: syntax error at EOF")
+ t.cleanup()
+
+
+def test_traceback():
+ t = BoostBuild.Tester(pass_toolset=False)
+ t.write("file.jam", """\
+NOTFILE all ;
+ECHO [ BACKTRACE ] ;""")
+ t.run_build_system(["-ffile.jam"])
+ t.expect_output_line("file.jam 2 module scope")
+ t.cleanup()
+
+
+def __trailing_newline(eof):
+ """
+ Helper function returning an empty string or a newling character to
+ append to the current output line depending on whether we want that line to
+ be the last line in the file (eof == True) or not (eof == False).
+
+ """
+ if eof:
+ return ""
+ return "\n"
+
+
+test_error_missing_argument(eof=False)
+test_error_missing_argument(eof=True)
+test_error_syntax(eof=False)
+test_error_syntax(eof=True)
+test_traceback()
+test_eof_in_string()

Modified: trunk/tools/build/v2/test/test_all.py
==============================================================================
--- trunk/tools/build/v2/test/test_all.py (original)
+++ trunk/tools/build/v2/test/test_all.py 2012-07-12 09:21:46 EDT (Thu, 12 Jul 2012)
@@ -183,6 +183,7 @@
          "core_parallel_actions",
          "core_parallel_multifile_actions_1",
          "core_parallel_multifile_actions_2",
+ "core_source_line_tracking",
          "core_update_now",
          "core_variables_in_actions",
          "custom_generator",


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk