summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeLib/testRST.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2013-10-01 00:30:57 (GMT)
committerBrad King <brad.king@kitware.com>2013-10-16 13:22:35 (GMT)
commit25f2877eef3b876922c0e40053205026c8c00e7d (patch)
tree9ad520bc5c98f9edc931a86d2f2d358d5efb98f4 /Tests/CMakeLib/testRST.cxx
parent87cc62cab9fcfd2d870d81161643bb1cc1c1e2a2 (diff)
downloadCMake-25f2877eef3b876922c0e40053205026c8c00e7d.zip
CMake-25f2877eef3b876922c0e40053205026c8c00e7d.tar.gz
CMake-25f2877eef3b876922c0e40053205026c8c00e7d.tar.bz2
Add class cmRST to do basic reStructuredText processing
Create a cmRST class to perform just enough reStructuredText processing to support display of Help documents in human-readable text format. This will be used to implement --help-* command-line options. Support directives "include", "replace", "parsed-literal", "toctree" (Sphinx), and "cmake-module" (CMake Sphinx Extension to scan .cmake modules). Support inline CMake Sphinx Domain roles to convert cross-references to corresponding title text. Support inline substitutions defined by the "replace" directive, but keep it simple by requiring replacements to be defined before use. Add a CMakeLib "testRST" case to cover processing of supported constructs and compare results against expected output.
Diffstat (limited to 'Tests/CMakeLib/testRST.cxx')
-rw-r--r--Tests/CMakeLib/testRST.cxx96
1 files changed, 96 insertions, 0 deletions
diff --git a/Tests/CMakeLib/testRST.cxx b/Tests/CMakeLib/testRST.cxx
new file mode 100644
index 0000000..bad9560
--- /dev/null
+++ b/Tests/CMakeLib/testRST.cxx
@@ -0,0 +1,96 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2013 Kitware, Inc., Insight Software Consortium
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#include "cmRST.h"
+
+#include "cmSystemTools.h"
+
+void reportLine(std::ostream& os, bool ret, std::string line, bool eol)
+{
+ if(ret)
+ {
+ os << "\"" << line << "\" (" << (eol?"with EOL":"without EOL") << ")";
+ }
+ else
+ {
+ os << "EOF";
+ }
+}
+
+int testRST(int, char*[])
+{
+ std::string dir = cmSystemTools::GetFilenamePath(__FILE__);
+ if(dir.empty())
+ {
+ dir = ".";
+ }
+ std::string a_name = "testRST.actual";
+ std::string e_name = dir + "/testRST.expect";
+
+ // Process the test RST file.
+ {
+ std::string fname = dir + "/testRST.rst";
+ std::ofstream fout(a_name.c_str());
+ if(!fout)
+ {
+ std::cerr << "Could not open output " << a_name << std::endl;
+ return 1;
+ }
+
+ cmRST r(fout, dir);
+ if(!r.ProcessFile(fname))
+ {
+ std::cerr << "Could not open input " << fname << std::endl;
+ return 1;
+ }
+ }
+
+ // Compare expected and actual outputs.
+ std::ifstream e_fin(e_name.c_str());
+ std::ifstream a_fin(a_name.c_str());
+ if(!e_fin)
+ {
+ std::cerr << "Could not open input " << e_name << std::endl;
+ return 1;
+ }
+ if(!a_fin)
+ {
+ std::cerr << "Could not open input " << a_name << std::endl;
+ return 1;
+ }
+ int lineno = 0;
+ bool e_ret;
+ bool a_ret;
+ do
+ {
+ std::string e_line;
+ std::string a_line;
+ bool e_eol;
+ bool a_eol;
+ e_ret = cmSystemTools::GetLineFromStream(e_fin, e_line, &e_eol);
+ a_ret = cmSystemTools::GetLineFromStream(a_fin, a_line, &a_eol);
+ ++lineno;
+ if(e_ret != a_ret || e_line != a_line || e_eol != a_eol)
+ {
+ a_fin.seekg(0, std::ios::beg);
+ std::cerr << "Actual output does not match that expected on line "
+ << lineno << "." << std::endl << "Expected ";
+ reportLine(std::cerr, e_ret, e_line, e_eol);
+ std::cerr << " but got ";
+ reportLine(std::cerr, a_ret, a_line, a_eol);
+ std::cerr << "." << std::endl
+ << "Actual output:" << std::endl
+ << a_fin.rdbuf();
+ return 1;
+ }
+ } while(e_ret && a_ret);
+ return 0;
+}