ENH: Added CommandLineTest to add coverage for command line arguments to cmake executables. This replaces the old DumpDocumentation test.
This commit is contained in:
parent
1a0ca72648
commit
08441daded
|
@ -154,8 +154,10 @@ ADD_EXECUTABLE(cmaketest cmaketest.cxx)
|
||||||
TARGET_LINK_LIBRARIES(cmaketest CMakeLib)
|
TARGET_LINK_LIBRARIES(cmaketest CMakeLib)
|
||||||
|
|
||||||
IF(BUILD_TESTING)
|
IF(BUILD_TESTING)
|
||||||
ADD_TEST(DumpDocumentation ${EXECUTABLE_OUTPUT_PATH}/DumpDocumentation
|
ADD_TEST(CommandLineTest ${EXECUTABLE_OUTPUT_PATH}/cmaketest
|
||||||
--all-for-coverage)
|
${CMake_SOURCE_DIR}/Tests/CommandLineTest
|
||||||
|
${CMake_BINARY_DIR}/Tests/CommandLineTest
|
||||||
|
CommandLineTest)
|
||||||
|
|
||||||
ADD_TEST(CustomCommand ${EXECUTABLE_OUTPUT_PATH}/cmaketest
|
ADD_TEST(CustomCommand ${EXECUTABLE_OUTPUT_PATH}/cmaketest
|
||||||
${CMake_SOURCE_DIR}/Tests/CustomCommand
|
${CMake_SOURCE_DIR}/Tests/CustomCommand
|
||||||
|
|
|
@ -41,7 +41,9 @@ static const cmDocumentationEntry cmDocumentationUsage[] =
|
||||||
static const cmDocumentationEntry cmDocumentationDescription[] =
|
static const cmDocumentationEntry cmDocumentationDescription[] =
|
||||||
{
|
{
|
||||||
{0,
|
{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}
|
{0,0,0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,7 +75,7 @@ int DumpHTML(const char* outname)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DumpForCoverage()
|
int DumpForCoverageToStream(std::ostream& out)
|
||||||
{
|
{
|
||||||
cmake cmi;
|
cmake cmi;
|
||||||
cmDocumentation doc;
|
cmDocumentation doc;
|
||||||
|
@ -87,13 +89,31 @@ int DumpForCoverage()
|
||||||
doc.SetOptionsSection(cmDocumentationOptions);
|
doc.SetOptionsSection(cmDocumentationOptions);
|
||||||
doc.SetCommandsSection(&commands[0]);
|
doc.SetCommandsSection(&commands[0]);
|
||||||
doc.SetGeneratorsSection(&generators[0]);
|
doc.SetGeneratorsSection(&generators[0]);
|
||||||
doc.PrintDocumentation(cmDocumentation::Usage, std::cout);
|
doc.PrintDocumentation(cmDocumentation::Usage, out);
|
||||||
doc.PrintDocumentation(cmDocumentation::Full, std::cout);
|
doc.PrintDocumentation(cmDocumentation::Full, out);
|
||||||
doc.PrintDocumentation(cmDocumentation::HTML, std::cout);
|
doc.PrintDocumentation(cmDocumentation::HTML, out);
|
||||||
doc.PrintDocumentation(cmDocumentation::Man, std::cout);
|
doc.PrintDocumentation(cmDocumentation::Man, out);
|
||||||
return 0;
|
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)
|
int main(int ac, char** av)
|
||||||
{
|
{
|
||||||
cmSystemTools::EnableMSVCDebugHook();
|
cmSystemTools::EnableMSVCDebugHook();
|
||||||
|
@ -104,6 +124,14 @@ int main(int ac, char** av)
|
||||||
if(strcmp(av[1], "--all-for-coverage") == 0)
|
if(strcmp(av[1], "--all-for-coverage") == 0)
|
||||||
{
|
{
|
||||||
coverage = true;
|
coverage = true;
|
||||||
|
if(ac > 2)
|
||||||
|
{
|
||||||
|
outname = av[2];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
outname = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -113,7 +141,7 @@ int main(int ac, char** av)
|
||||||
|
|
||||||
if(coverage)
|
if(coverage)
|
||||||
{
|
{
|
||||||
return DumpForCoverage();
|
return DumpForCoverage(outname);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -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)
|
|
@ -0,0 +1,4 @@
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -55,16 +55,6 @@ FOREACH(var
|
||||||
FILE(APPEND "${file}" "#define ${var} \"${${var}}\"\n")
|
FILE(APPEND "${file}" "#define ${var} \"${${var}}\"\n")
|
||||||
ENDFOREACH(var)
|
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
|
# Write include file to a file
|
||||||
STRING(REGEX REPLACE "includefile" "${file}" outfile "${infile}")
|
STRING(REGEX REPLACE "includefile" "${file}" outfile "${infile}")
|
||||||
FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/OutputFile.h" "${outfile}")
|
FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/OutputFile.h" "${outfile}")
|
||||||
|
|
Loading…
Reference in New Issue