Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75769 - in trunk/tools/quickbook: src test/command-line test/xinclude
From: dnljms_at_[hidden]
Date: 2011-12-02 03:28:58


Author: danieljames
Date: 2011-12-02 03:28:57 EST (Fri, 02 Dec 2011)
New Revision: 75769
URL: http://svn.boost.org/trac/boost/changeset/75769

Log:
Quickbook: More error checking for file handling.
Added:
   trunk/tools/quickbook/test/command-line/basic-1_6.quickbook (contents, props changed)
   trunk/tools/quickbook/test/xinclude/xmlbase-1_6-fail.quickbook (contents, props changed)
Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 2 +-
   trunk/tools/quickbook/src/doc_info_actions.cpp | 18 ++++++++++++++++--
   trunk/tools/quickbook/src/files.cpp | 3 +++
   trunk/tools/quickbook/src/quickbook.cpp | 37 +++++++++++++++++++++++++++++++++----
   trunk/tools/quickbook/test/command-line/Jamfile.v2 | 12 ++++++++++--
   trunk/tools/quickbook/test/xinclude/Jamfile.v2 | 1 +
   6 files changed, 64 insertions(+), 9 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2011-12-02 03:28:57 EST (Fri, 02 Dec 2011)
@@ -1918,7 +1918,7 @@
             ++actions.error_count;
 
             detail::outerr(actions.current_file, first)
- << "Loading file:"
+ << "Loading file "
                 << paths.filename
                 << ": "
                 << detail::utf8(e.what())

Modified: trunk/tools/quickbook/src/doc_info_actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/doc_info_actions.cpp (original)
+++ trunk/tools/quickbook/src/doc_info_actions.cpp 2011-12-02 03:28:57 EST (Fri, 02 Dec 2011)
@@ -12,6 +12,7 @@
 #include <boost/bind.hpp>
 #include <boost/algorithm/string/join.hpp>
 #include <boost/foreach.hpp>
+#include <boost/filesystem/v3/operations.hpp>
 #include "quickbook.hpp"
 #include "utils.hpp"
 #include "files.hpp"
@@ -259,8 +260,21 @@
         {
             xinclude_path x = calculate_xinclude_path(xmlbase, actions);
 
- xmlbase_value = x.uri;
- actions.xinclude_base = x.path;
+ if (!fs::is_directory(x.path))
+ {
+ detail::outerr(xmlbase.get_file(), xmlbase.get_position())
+ << "xmlbase \""
+ << detail::utf8(xmlbase.get_quickbook())
+ << "\" isn't a directory."
+ << std::endl;
+
+ ++actions.error_count;
+ }
+ else
+ {
+ xmlbase_value = x.uri;
+ actions.xinclude_base = x.path;
+ }
         }
 
         // Warn about invalid fields

Modified: trunk/tools/quickbook/src/files.cpp
==============================================================================
--- trunk/tools/quickbook/src/files.cpp (original)
+++ trunk/tools/quickbook/src/files.cpp 2011-12-02 03:28:57 EST (Fri, 02 Dec 2011)
@@ -120,6 +120,9 @@
                 std::istream_iterator<char>(),
                 std::back_inserter(source));
 
+ if (in.bad())
+ throw load_error("Error reading input file.");
+
             bool inserted;
 
             boost::tie(pos, inserted) = files.emplace(

Modified: trunk/tools/quickbook/src/quickbook.cpp
==============================================================================
--- trunk/tools/quickbook/src/quickbook.cpp (original)
+++ trunk/tools/quickbook/src/quickbook.cpp 2011-12-02 03:28:57 EST (Fri, 02 Dec 2011)
@@ -150,6 +150,15 @@
 
             fs::ofstream fileout(fileout_);
 
+ if (fileout.fail()) {
+ ::quickbook::detail::outerr()
+ << "Error opening output file "
+ << fileout_
+ << std::endl;
+
+ return 1;
+ }
+
             if (pretty_print)
             {
                 try
@@ -170,6 +179,15 @@
             {
                 fileout << stage2;
             }
+
+ if (fileout.fail()) {
+ ::quickbook::detail::outerr()
+ << "Error writing to output file "
+ << fileout_
+ << std::endl;
+
+ return 1;
+ }
         }
 
         return result;
@@ -281,6 +299,7 @@
         notify(vm);
 
         bool expect_errors = vm.count("expect-errors");
+ int error_count = 0;
 
         if (vm.count("help"))
         {
@@ -394,6 +413,15 @@
                     xinclude_base = ".";
             }
 
+ if (!fs::is_directory(xinclude_base))
+ {
+ quickbook::detail::outerr()
+ << (vm.count("xinclude-base") ?
+ "xinclude-base is not a directory" :
+ "parent directory not found for output file");
+ ++error_count;
+ }
+
             if (vm.count("image-location"))
             {
                 quickbook::image_location = quickbook::detail::input_to_path(
@@ -408,16 +436,17 @@
                 << quickbook::detail::path_to_stream(fileout)
                 << std::endl;
 
- int r = quickbook::parse_document(filein, fileout, xinclude_base, indent, linewidth, pretty_print);
+ if (!error_count)
+ error_count += quickbook::parse_document(filein, fileout, xinclude_base, indent, linewidth, pretty_print);
 
             if (expect_errors)
             {
- if (!r) quickbook::detail::outerr() << "No errors detected for --expect-errors." << std::endl;
- return !r;
+ if (!error_count) quickbook::detail::outerr() << "No errors detected for --expect-errors." << std::endl;
+ return !error_count;
             }
             else
             {
- return r;
+ return error_count;
             }
         }
         else

Modified: trunk/tools/quickbook/test/command-line/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/test/command-line/Jamfile.v2 (original)
+++ trunk/tools/quickbook/test/command-line/Jamfile.v2 2011-12-02 03:28:57 EST (Fri, 02 Dec 2011)
@@ -7,14 +7,22 @@
 # http://www.boost.org/LICENSE_1_0.txt)
 #
 
-# Just checking that expect-errors works as advertised.
-
 project quickook/tests/command-line ;
 
 import quickbook-testing : quickbook-test quickbook-fail-test quickbook-error-test ;
 
 test-suite command-line.test :
+ # Check that expect-errors works as advertised.
     [ quickbook-fail-test error-fail : : <testing.arg>--expect-errors ]
     [ quickbook-error-test error1 ]
     [ quickbook-error-test error2 ]
+
+ [ quickbook-error-test
+ non_existant_output :
+ basic-1_6.quickbook :
+ <testing.arg>--output-file=non-existant/basic.xml ]
+ [ quickbook-error-test
+ output_nested_in_file :
+ basic-1_6.quickbook :
+ <testing.arg>--output-file=basic-1_6.quickbook/basic.xml ]
     ;
\ No newline at end of file

Added: trunk/tools/quickbook/test/command-line/basic-1_6.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/command-line/basic-1_6.quickbook 2011-12-02 03:28:57 EST (Fri, 02 Dec 2011)
@@ -0,0 +1,5 @@
+[article Basic quickbook file
+[quickbook 1.5]
+]
+
+Just used for running command line tests.
\ No newline at end of file

Modified: trunk/tools/quickbook/test/xinclude/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/test/xinclude/Jamfile.v2 (original)
+++ trunk/tools/quickbook/test/xinclude/Jamfile.v2 2011-12-02 03:28:57 EST (Fri, 02 Dec 2011)
@@ -23,4 +23,5 @@
     [ quickbook-test xinclude-1_1-alt : xinclude-1_1.quickbook : xinclude-1_1-alt.gold : <quickbook-xinclude-base>$(xinclude_base2) ]
     [ quickbook-test xmlbase1-1_6-alt : xmlbase1-1_6.quickbook : xmlbase1-1_6-alt.gold : <quickbook-xinclude-base>$(xinclude_base2) ]
     [ quickbook-test xmlbase2-1_6-alt : xmlbase2-1_6.quickbook : xmlbase2-1_6-alt.gold : <quickbook-xinclude-base>$(xinclude_base2) ]
+ [ quickbook-error-test xmlbase-1_6-fail ]
     ;

Added: trunk/tools/quickbook/test/xinclude/xmlbase-1_6-fail.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/xinclude/xmlbase-1_6-fail.quickbook 2011-12-02 03:28:57 EST (Fri, 02 Dec 2011)
@@ -0,0 +1,4 @@
+[article Xmlbase fail
+[quickbook 1.5]
+[xmlbase non-existant]
+]


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