diff options
author | Stefan Floeren <stefan.floeren@smartronic.de> | 2020-06-30 09:29:53 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-07-01 10:48:19 (GMT) |
commit | 7b92e116830805e61a86119071e56b47eb5dd51c (patch) | |
tree | 7b9d258ae07b7a179bc94c1a6d563fb6f42341a7 /Tests | |
parent | 77ba7539adb805b154b778046eda491b40acf09e (diff) | |
download | CMake-7b92e116830805e61a86119071e56b47eb5dd51c.zip CMake-7b92e116830805e61a86119071e56b47eb5dd51c.tar.gz CMake-7b92e116830805e61a86119071e56b47eb5dd51c.tar.bz2 |
Tests: Add test for GoogleTest XML_OUTPUT_DIR
Add tests to make sure the XML_OUTPUT_DIR is generated correctly and the
correct files are getting created.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/GoogleTest/GoogleTestXML-special-result-check.cmake | 28 | ||||
-rw-r--r-- | Tests/RunCMake/GoogleTest/GoogleTestXML.cmake | 11 | ||||
-rw-r--r-- | Tests/RunCMake/GoogleTest/RunCMakeTest.cmake | 7 | ||||
-rw-r--r-- | Tests/RunCMake/GoogleTest/xml_output.cpp | 11 |
4 files changed, 57 insertions, 0 deletions
diff --git a/Tests/RunCMake/GoogleTest/GoogleTestXML-special-result-check.cmake b/Tests/RunCMake/GoogleTest/GoogleTestXML-special-result-check.cmake new file mode 100644 index 0000000..fea0a6b --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTestXML-special-result-check.cmake @@ -0,0 +1,28 @@ +set(RESULT_FILES + "${RunCMake_TEST_BINARY_DIR}/GoogleTestXMLSpecial/cases.case/0.xml" + "${RunCMake_TEST_BINARY_DIR}/GoogleTestXMLSpecial/cases.case/1.xml" + "${RunCMake_TEST_BINARY_DIR}/GoogleTestXMLSpecial/cases.case/2.xml" +) + +# Check result files exist +foreach(file ${RESULT_FILES}) + if(NOT EXISTS ${file}) + if(NOT ${RunCMake_TEST_FAILED} STREQUAL "") + set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}\n") + endif() + set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}Result XML file ${file} was not created") + endif() +endforeach() + +# and no other xml files are created +file(GLOB_RECURSE file_list "${RunCMake_TEST_BINARY_DIR}/GoogleTestXMLSpecial/*/*.xml" LIST_DIRECTORIES false) + +foreach(file ${file_list}) + list(FIND RESULT_FILES "${file}" idx) + if(-1 EQUAL ${idx}) + if(NOT ${RunCMake_TEST_FAILED} STREQUAL "") + set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}\n") + endif() + set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}Invalid file ${file} was created") + endif() +endforeach() diff --git a/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake b/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake index 29bd05e..fb91c0e 100644 --- a/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake +++ b/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake @@ -3,6 +3,17 @@ include(GoogleTest) enable_testing() +# This creates the folder structure for the paramterized tests +# to avoid handling missing folders in C++ +# +# This must match the match the name defined in xml_output.cpp +# for every instance of tests with GetParam. +# +# The folder name is created fom the test name (output of the line +# without leading spaces: "GoogleTestXMLSpecial/cases.") and +# the parts until the last slash ("case/"). These parts are concatenated. +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/GoogleTestXMLSpecial/cases.case") + add_executable(xml_output xml_output.cpp) gtest_discover_tests( xml_output diff --git a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake index efd22be..530c8ab 100644 --- a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake +++ b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake @@ -101,6 +101,13 @@ function(run_GoogleTestXML DISCOVERY_MODE) -R GoogleTestXML --no-label-summary ) + + run_cmake_command(GoogleTestXML-special-result + ${CMAKE_CTEST_COMMAND} + -C Debug + -R GoogleTestXMLSpecial + --no-label-summary + ) endfunction() function(run_GoogleTest_discovery_timeout DISCOVERY_MODE) diff --git a/Tests/RunCMake/GoogleTest/xml_output.cpp b/Tests/RunCMake/GoogleTest/xml_output.cpp index e130231..82f0d02 100644 --- a/Tests/RunCMake/GoogleTest/xml_output.cpp +++ b/Tests/RunCMake/GoogleTest/xml_output.cpp @@ -13,11 +13,22 @@ int main(int argc, char** argv) // This actually defines the name of the file passed in the 2nd run std::cout << "GoogleTestXML." << std::endl; std::cout << " Foo" << std::endl; + // When changing these names, make sure to adapt the folder creation + // in GoogleTestXML.cmake + std::cout << "GoogleTestXMLSpecial/cases." << std::endl; + std::cout << " case/0 # GetParam() = 42" << std::endl; + std::cout << " case/1 # GetParam() = \"string\"" << std::endl; + std::cout << " case/2 # GetParam() = \"path/like\"" << std::endl; } else if (param.find("--gtest_output=xml:") != std::string::npos) { std::string::size_type split = param.find(":"); std::string filepath = param.substr(split + 1); // The full file path is passed std::ofstream ostrm(filepath.c_str(), std::ios::binary); + if (!ostrm) { + std::cerr << "Failed to create file: " << filepath.c_str() + << std::endl; + return 1; + } ostrm << "--gtest_output=xml: mockup file\n"; } } |