Browse Source

ENH: add dump documentation test

Bill Hoffman 24 years ago
parent
commit
a4f40c31f1
4 changed files with 18 additions and 12 deletions
  1. 3 0
      Source/CMakeLists.txt
  2. 13 3
      Source/cmDumpDocumentation.cxx
  3. 1 8
      Source/cmMakefile.cxx
  4. 1 1
      Source/cmMakefile.h

+ 3 - 0
Source/CMakeLists.txt

@@ -53,6 +53,7 @@ LINK_LIBRARIES(CMakeLib)
 LINK_DIRECTORIES(${CMake_BINARY_DIR}/Sources)
 
 ADD_EXECUTABLE(cmake cmakemain)
+ADD_EXECUTABLE(DumpDocumentation cmDumpDocumentation)
 
 ADD_EXECUTABLE(ctest ctest.cxx cmSystemTools.cxx cmRegularExpression.cxx)
 
@@ -66,6 +67,8 @@ IF(BUILD_TESTING)
     CONFIGURE_FILE(
       ${CMake_SOURCE_DIR}/Source/cmaketest.h.in 
       ${CMake_BINARY_DIR}/Source/cmaketest.h ESCAPE_QUOTES)
+    ADD_TEST(DumpDocumentation ${CMake_BINARY_DIR}/Source/DumpDocumentation
+      ${CMake_BINARY_DIR}/CMakeDoc.html )
     ADD_TEST(simple ${CMake_BINARY_DIR}/Source/cmaketest 
       ${CMake_SOURCE_DIR}/Tests/Simple 
       ${CMake_BINARY_DIR}/Tests/Simple simple )

+ 13 - 3
Source/cmDumpDocumentation.cxx

@@ -3,10 +3,20 @@
 // 
 #include "cmMakefile.h"
 
-int main()
+int main(int ac, char** av)
 {
   cmMakefile makefile;
-  makefile.DumpDocumentationToFile("cmake.txt");
-
+  const char* outname = "cmake.html";
+  if(ac > 1)
+    {
+    outname = av[1];
+    }
+  std::ofstream fout(outname);
+  if(!fout)
+    {
+    std::cerr << "failed to open output file: " << outname << "\n";
+    return -1;
+    }
+  makefile.DumpDocumentationToFile(fout);
   return 0;
 }

+ 1 - 8
Source/cmMakefile.cxx

@@ -797,16 +797,9 @@ const char* cmMakefile::GetDefinition(const char* name)
   return cmCacheManager::GetInstance()->GetCacheValue(name);
 }
 
-int cmMakefile::DumpDocumentationToFile(const char *fileName)
+int cmMakefile::DumpDocumentationToFile(std::ostream& f)
 {
   // Open the supplied filename
-  std::ofstream f;
-  f.open(fileName, std::ios::out);
-  
-  if ( f.fail() )
-    {
-    return 0;
-    }
   
   // Loop over all registered commands and print out documentation
   const char *name;

+ 1 - 1
Source/cmMakefile.h

@@ -487,7 +487,7 @@ public:
    * Dump documentation to a file. If 0 is returned, the
    * operation failed.
    */
-  int DumpDocumentationToFile(const char *fileName);
+  int DumpDocumentationToFile(std::ostream&);
 
   /**
    * Expand all defined varibles in the string.