Commit 7b92e116 authored by Stefan Floeren's avatar Stefan Floeren Committed by Brad King
Browse files

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.
parent 77ba7539
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()
......@@ -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
......
......@@ -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)
......
......@@ -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";
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment