Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50091 - in trunk/tools/quickbook: detail test
From: daniel_james_at_[hidden]
Date: 2008-12-03 14:14:43


Author: danieljames
Date: 2008-12-03 14:14:42 EST (Wed, 03 Dec 2008)
New Revision: 50091
URL: http://svn.boost.org/trac/boost/changeset/50091

Log:
Keep a count of errors in quickbook, and return an error code when appropriate. Refs #1399.

Added:
   trunk/tools/quickbook/test/fail-template-arguments1.quickbook (contents, props changed)
   trunk/tools/quickbook/test/fail-template-arguments2.quickbook (contents, props changed)
Text files modified:
   trunk/tools/quickbook/detail/actions.cpp | 20 +++++++++++++++++---
   trunk/tools/quickbook/detail/actions.hpp | 20 ++++++++++++++++----
   trunk/tools/quickbook/detail/actions_class.cpp | 7 ++++---
   trunk/tools/quickbook/detail/actions_class.hpp | 1 +
   trunk/tools/quickbook/detail/quickbook.cpp | 10 +++++++---
   trunk/tools/quickbook/test/Jamfile.v2 | 2 ++
   6 files changed, 47 insertions(+), 13 deletions(-)

Modified: trunk/tools/quickbook/detail/actions.cpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.cpp (original)
+++ trunk/tools/quickbook/detail/actions.cpp 2008-12-03 14:14:42 EST (Wed, 03 Dec 2008)
@@ -38,6 +38,7 @@
         boost::spirit::file_position const pos = first.get_position();
         detail::outerr(pos.file,pos.line)
             << "Syntax Error near column " << pos.column << ".\n";
+ ++error_count;
     }
 
     void phrase_action::operator()(iterator first, iterator last) const
@@ -229,6 +230,7 @@
                 << "Illegal change of list style near column " << pos.column << ".\n";
             detail::outwarn(pos.file,pos.line)
                 << "Ignoring change of list style" << std::endl;
+ ++error_count;
         }
     }
 
@@ -484,6 +486,7 @@
             boost::spirit::file_position const pos = first.get_position();
             detail::outerr(pos.file,pos.line)
                 << "Template Redefinition: " << actions.template_info[0] << std::endl;
+ ++actions.error_count;
         }
 
         actions.template_info.push_back(std::string(first, last));
@@ -561,6 +564,7 @@
                 {
                     detail::outerr(pos.file,pos.line)
                         << "Duplicate Symbol Found" << std::endl;
+ ++actions.error_count;
                     return std::make_pair(false, tpl);
                 }
                 else
@@ -637,6 +641,7 @@
             detail::outerr(pos.file,pos.line)
                 << "Infinite loop detected" << std::endl;
             --actions.template_depth;
+ ++actions.error_count;
             return;
         }
 
@@ -659,6 +664,7 @@
             {
                 actions.pop(); // restore the actions' states
                 --actions.template_depth;
+ ++actions.error_count;
                 return;
             }
 
@@ -693,6 +699,7 @@
                     << std::endl;
                 actions.pop(); // restore the actions' states
                 --actions.template_depth;
+ ++actions.error_count;
                 return;
             }
         }
@@ -890,6 +897,8 @@
             boost::spirit::file_position const pos = first.get_position();
             detail::outerr(pos.file,pos.line)
                 << "Mismatched [endsect] near column " << pos.column << ".\n";
+ ++error_count;
+
             // $$$ TODO: somehow fail parse else BOOST_ASSERT(std::string::npos != n)
             // $$$ below will assert.
         }
@@ -1042,7 +1051,7 @@
         id.clear();
     }
 
- void load_snippets(
+ int load_snippets(
         std::string const& file
       , std::vector<template_symbol>& storage // snippets are stored in a
                                                 // vector of template_symbols
@@ -1052,14 +1061,17 @@
         std::string code;
         int err = detail::load(file, code);
         if (err != 0)
- return; // return early on error
+ return err; // return early on error
 
         typedef position_iterator<std::string::const_iterator> iterator_type;
         iterator_type first(code.begin(), code.end(), file);
         iterator_type last(code.end(), code.end());
 
         cpp_code_snippet_grammar g(storage, doc_id);
+ // TODO: Should I check that parse succeeded?
         boost::spirit::parse(first, last, g);
+
+ return 0;
     }
 
     namespace
@@ -1098,7 +1110,8 @@
         fs::path path = include_search(actions.filename.branch_path(), std::string(first,last));
         std::string ext = fs::extension(path);
         std::vector<template_symbol> storage;
- load_snippets(path.string(), storage, ext, actions.doc_id);
+ actions.error_count +=
+ load_snippets(path.string(), storage, ext, actions.doc_id);
 
         BOOST_FOREACH(template_symbol const& ts, storage)
         {
@@ -1108,6 +1121,7 @@
                 boost::spirit::file_position const pos = boost::get<1>(ts);
                 detail::outerr(pos.file, pos.line)
                     << "Template Redefinition: " << tname << std::endl;
+ ++actions.error_count;
             }
             else
             {

Modified: trunk/tools/quickbook/detail/actions.hpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.hpp (original)
+++ trunk/tools/quickbook/detail/actions.hpp 2008-12-03 14:14:42 EST (Wed, 03 Dec 2008)
@@ -54,7 +54,13 @@
     {
         // Prints an error message to std::cerr
 
+ error_action(
+ int& error_count)
+ : error_count(error_count) {}
+
         void operator()(iterator first, iterator /*last*/) const;
+
+ int& error_count;
     };
 
     struct phrase_action
@@ -230,16 +236,19 @@
         list_format_action(
             collector& out
           , int& list_indent
- , std::stack<mark_type>& list_marks)
+ , std::stack<mark_type>& list_marks
+ , int& error_count)
         : out(out)
         , list_indent(list_indent)
- , list_marks(list_marks) {}
+ , list_marks(list_marks)
+ , error_count(error_count) {}
 
         void operator()(iterator first, iterator last) const;
 
         collector& out;
         int& list_indent;
         std::stack<mark_type>& list_marks;
+ int& error_count;
     };
 
     struct span
@@ -671,16 +680,19 @@
         end_section_action(
             collector& out
           , int& section_level
- , std::string& qualified_section_id)
+ , std::string& qualified_section_id
+ , int& error_count)
         : out(out)
         , section_level(section_level)
- , qualified_section_id(qualified_section_id) {}
+ , qualified_section_id(qualified_section_id)
+ , error_count(error_count) {}
 
         void operator()(iterator first, iterator last) const;
 
         collector& out;
         int& section_level;
         std::string& qualified_section_id;
+ int& error_count;
    };
 
     struct xinclude_action

Modified: trunk/tools/quickbook/detail/actions_class.cpp
==============================================================================
--- trunk/tools/quickbook/detail/actions_class.cpp (original)
+++ trunk/tools/quickbook/detail/actions_class.cpp 2008-12-03 14:14:42 EST (Wed, 03 Dec 2008)
@@ -62,9 +62,10 @@
         , template_depth(0)
         , template_escape(false)
         , templates()
+ , error_count(0)
 
     // actions
- , error()
+ , error(error_count)
         , extract_doc_license(doc_license, phrase)
         , extract_doc_purpose(doc_purpose, phrase)
 
@@ -96,7 +97,7 @@
         , cond_phrase_post(phrase, conditions, macro)
 
         , list(out, list_buffer, list_indent, list_marks)
- , list_format(list_buffer, list_indent, list_marks)
+ , list_format(list_buffer, list_indent, list_marks, error_count)
         , list_item(list_buffer, phrase, list_item_pre, list_item_post)
 
         , funcref_pre(phrase, funcref_pre_)
@@ -165,7 +166,7 @@
         , anchor(out)
 
         , begin_section(out, phrase, doc_id, section_id, section_level, qualified_section_id)
- , end_section(out, section_level, qualified_section_id)
+ , end_section(out, section_level, qualified_section_id, error_count)
         , xinclude(out, *this)
         , include(*this)
         , import(out, *this)

Modified: trunk/tools/quickbook/detail/actions_class.hpp
==============================================================================
--- trunk/tools/quickbook/detail/actions_class.hpp (original)
+++ trunk/tools/quickbook/detail/actions_class.hpp 2008-12-03 14:14:42 EST (Wed, 03 Dec 2008)
@@ -90,6 +90,7 @@
         int template_depth;
         bool template_escape;
         template_stack templates;
+ int error_count;
 
     // push/pop the states and the streams
         void push();

Modified: trunk/tools/quickbook/detail/quickbook.cpp
==============================================================================
--- trunk/tools/quickbook/detail/quickbook.cpp (original)
+++ trunk/tools/quickbook/detail/quickbook.cpp 2008-12-03 14:14:42 EST (Wed, 03 Dec 2008)
@@ -56,8 +56,10 @@
 
         std::string storage;
         int err = detail::load(filein_, storage);
- if (err != 0)
+ if (err != 0) {
+ ++actor.error_count;
             return err;
+ }
 
         typedef position_iterator<std::string::const_iterator> iterator_type;
         iterator_type first(storage.begin(), storage.end(), filein_);
@@ -83,10 +85,10 @@
             file_position const pos = info.stop.get_position();
             detail::outerr(pos.file,pos.line)
                 << "Syntax Error near column " << pos.column << ".\n";
- return 1;
+ ++actor.error_count;
         }
 
- return 0;
+ return actor.error_count ? 1 : 0;
     }
 
     static int
@@ -257,6 +259,7 @@
         else
         {
             quickbook::detail::outerr("",0) << "Error: No filename given" << std::endl;
+ return 1;
         }
     }
 
@@ -269,6 +272,7 @@
     catch(...)
     {
         quickbook::detail::outerr("",0) << "Error: Exception of unknown type caught\n";
+ return 1;
     }
 
     return 0;

Modified: trunk/tools/quickbook/test/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/test/Jamfile.v2 (original)
+++ trunk/tools/quickbook/test/Jamfile.v2 2008-12-03 14:14:42 EST (Wed, 03 Dec 2008)
@@ -23,6 +23,8 @@
     [ quickbook-test import ]
     [ quickbook-fail-test fail-include ]
     [ quickbook-fail-test fail-import ]
+ [ quickbook-fail-test fail-template-arguments1 ]
+ [ quickbook-fail-test fail-template-arguments2 ]
     ;
 
 

Added: trunk/tools/quickbook/test/fail-template-arguments1.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/fail-template-arguments1.quickbook 2008-12-03 14:14:42 EST (Wed, 03 Dec 2008)
@@ -0,0 +1,13 @@
+[article Expect template to fail because there are too many arguments.
+]
+
+[template unary[x] [x]]
+
+[section Failure]
+
+[unary a..b ]
+
+[endsect]
+
+
+

Added: trunk/tools/quickbook/test/fail-template-arguments2.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/fail-template-arguments2.quickbook 2008-12-03 14:14:42 EST (Wed, 03 Dec 2008)
@@ -0,0 +1,13 @@
+[article Expect template to fail because there are not enough arguments.
+]
+
+[template ternary[x y z] [x][y][z]]
+
+[section Failure]
+
+[ternary a b ]
+
+[endsect]
+
+
+


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