From 08441daded83d314c95016b1a6f7bb047b85e0f2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 24 Jul 2003 10:58:40 -0400 Subject: ENH: Added CommandLineTest to add coverage for command line arguments to cmake executables. This replaces the old DumpDocumentation test. --- Source/CMakeLists.txt | 6 +++-- Source/cmDumpDocumentation.cxx | 42 +++++++++++++++++++++++++------ Tests/CommandLineTest/CMakeLists.txt | 22 ++++++++++++++++ Tests/CommandLineTest/CommandLineTest.cxx | 4 +++ Tests/StringFileTest/CMakeLists.txt | 10 -------- 5 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 Tests/CommandLineTest/CMakeLists.txt create mode 100644 Tests/CommandLineTest/CommandLineTest.cxx diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 38cafb6..552bbec 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -154,8 +154,10 @@ ADD_EXECUTABLE(cmaketest cmaketest.cxx) TARGET_LINK_LIBRARIES(cmaketest CMakeLib) IF(BUILD_TESTING) - ADD_TEST(DumpDocumentation ${EXECUTABLE_OUTPUT_PATH}/DumpDocumentation - --all-for-coverage) + ADD_TEST(CommandLineTest ${EXECUTABLE_OUTPUT_PATH}/cmaketest + ${CMake_SOURCE_DIR}/Tests/CommandLineTest + ${CMake_BINARY_DIR}/Tests/CommandLineTest + CommandLineTest) ADD_TEST(CustomCommand ${EXECUTABLE_OUTPUT_PATH}/cmaketest ${CMake_SOURCE_DIR}/Tests/CustomCommand diff --git a/Source/cmDumpDocumentation.cxx b/Source/cmDumpDocumentation.cxx index 0b474c4..0155ac2 100644 --- a/Source/cmDumpDocumentation.cxx +++ b/Source/cmDumpDocumentation.cxx @@ -41,7 +41,9 @@ static const cmDocumentationEntry cmDocumentationUsage[] = static const cmDocumentationEntry cmDocumentationDescription[] = { {0, - "CMake reads ... ", 0}, + "The \"DumpDocumentation\" executable is only available in the build " + "tree. It is used for testing, coverage, and documentation.", 0}, + CMAKE_STANDARD_INTRODUCTION, {0,0,0} }; @@ -73,7 +75,7 @@ int DumpHTML(const char* outname) return 0; } -int DumpForCoverage() +int DumpForCoverageToStream(std::ostream& out) { cmake cmi; cmDocumentation doc; @@ -87,13 +89,31 @@ int DumpForCoverage() doc.SetOptionsSection(cmDocumentationOptions); doc.SetCommandsSection(&commands[0]); doc.SetGeneratorsSection(&generators[0]); - doc.PrintDocumentation(cmDocumentation::Usage, std::cout); - doc.PrintDocumentation(cmDocumentation::Full, std::cout); - doc.PrintDocumentation(cmDocumentation::HTML, std::cout); - doc.PrintDocumentation(cmDocumentation::Man, std::cout); + doc.PrintDocumentation(cmDocumentation::Usage, out); + doc.PrintDocumentation(cmDocumentation::Full, out); + doc.PrintDocumentation(cmDocumentation::HTML, out); + doc.PrintDocumentation(cmDocumentation::Man, out); return 0; } +int DumpForCoverage(const char* outname) +{ + if(outname) + { + std::ofstream fout(outname); + if(!fout) + { + std::cerr << "failed to open output file: " << outname << "\n"; + return -1; + } + return DumpForCoverageToStream(fout); + } + else + { + return DumpForCoverageToStream(std::cout); + } +} + int main(int ac, char** av) { cmSystemTools::EnableMSVCDebugHook(); @@ -104,6 +124,14 @@ int main(int ac, char** av) if(strcmp(av[1], "--all-for-coverage") == 0) { coverage = true; + if(ac > 2) + { + outname = av[2]; + } + else + { + outname = 0; + } } else { @@ -113,7 +141,7 @@ int main(int ac, char** av) if(coverage) { - return DumpForCoverage(); + return DumpForCoverage(outname); } else { diff --git a/Tests/CommandLineTest/CMakeLists.txt b/Tests/CommandLineTest/CMakeLists.txt new file mode 100644 index 0000000..ebea593 --- /dev/null +++ b/Tests/CommandLineTest/CMakeLists.txt @@ -0,0 +1,22 @@ +PROJECT(CommandLineTest) + +GET_FILENAME_COMPONENT(CMAKE_BIN_DIR ${CMAKE_COMMAND} PATH) +FIND_PROGRAM(DUMP_DOC_EXE NAMES DumpDocumentation PATHS ${CMAKE_BIN_DIR}) + +EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E chdir ${CMAKE_CURRENT_SOURCE_DIR} \"${CMAKE_COMMAND} -E echo \\\"Hello World\\\"\"") +EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E time \"${CMAKE_COMMAND} -N -L ${CommandLineTest_SOURCE_DIR}\"") +EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E time \"${CMAKE_COMMAND} -N -LA ${CommandLineTest_SOURCE_DIR}\"") +EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E time \"${CMAKE_COMMAND} -N -LH ${CommandLineTest_SOURCE_DIR}\"") +EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E time \"${CMAKE_COMMAND} -N -LAH ${CommandLineTest_SOURCE_DIR}\"") +EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help") +EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help-full \"${CMAKE_CURRENT_BINARY_DIR}/cmake.txt\"") +EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help-man \"${CMAKE_CURRENT_BINARY_DIR}/cmake.man\"") +EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help-html \"${CMAKE_CURRENT_BINARY_DIR}/cmake.html\"") + +IF(DUMP_DOC_EXE) + EXEC_PROGRAM(${DUMP_DOC_EXE} ARGS "--all-for-coverage \"${CMAKE_CURRENT_BINARY_DIR}/all_for_coverage.txt\"") +ELSE(DUMP_DOC_EXE) + MESSAGE(SEND_ERROR "Cannot find DumpDocumentation executable.") +ENDIF(DUMP_DOC_EXE) + +ADD_EXECUTABLE(CommandLineTest CommandLineTest.cxx) diff --git a/Tests/CommandLineTest/CommandLineTest.cxx b/Tests/CommandLineTest/CommandLineTest.cxx new file mode 100644 index 0000000..f8b643a --- /dev/null +++ b/Tests/CommandLineTest/CommandLineTest.cxx @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/Tests/StringFileTest/CMakeLists.txt b/Tests/StringFileTest/CMakeLists.txt index ff17be6..b0030fe 100644 --- a/Tests/StringFileTest/CMakeLists.txt +++ b/Tests/StringFileTest/CMakeLists.txt @@ -55,16 +55,6 @@ FOREACH(var FILE(APPEND "${file}" "#define ${var} \"${${var}}\"\n") ENDFOREACH(var) -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E chdir ${CMAKE_CURRENT_SOURCE_DIR} \"${CMAKE_COMMAND} -E echo \\\"Hello World\\\"\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E time \"${CMAKE_COMMAND} -N -L ${StringFileTest_SOURCE_DIR}\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E time \"${CMAKE_COMMAND} -N -LA ${StringFileTest_SOURCE_DIR}\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E time \"${CMAKE_COMMAND} -N -LH ${StringFileTest_SOURCE_DIR}\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E time \"${CMAKE_COMMAND} -N -LAH ${StringFileTest_SOURCE_DIR}\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help-full \"${CMAKE_CURRENT_BINARY_DIR}/cmake.txt\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help-man \"${CMAKE_CURRENT_BINARY_DIR}/cmake.man\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help-html \"${CMAKE_CURRENT_BINARY_DIR}/cmake.html\"") - # Write include file to a file STRING(REGEX REPLACE "includefile" "${file}" outfile "${infile}") FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/OutputFile.h" "${outfile}") -- cgit v0.12