Merge topic 'FindGTest-TEST_P'

2e2939c3 FindGTest: Teach GTEST_ADD_TESTS about TEST_P
This commit is contained in:
Brad King 2014-04-03 12:51:35 -04:00 committed by CMake Topic Stage
commit 7fcf0277c9
1 changed files with 10 additions and 2 deletions

View File

@ -115,11 +115,19 @@ function(GTEST_ADD_TESTS executable extra_args)
# obtain sources used for building that executable
get_property(ARGN TARGET ${executable} PROPERTY SOURCES)
endif()
set(gtest_case_name_regex ".*\\( *([A-Za-z_0-9]+), *([A-Za-z_0-9]+) *\\).*")
foreach(source ${ARGN})
file(READ "${source}" contents)
string(REGEX MATCHALL "TEST_?F?\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents})
string(REGEX MATCHALL "TEST_?[FP]?\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents})
foreach(hit ${found_tests})
string(REGEX REPLACE ".*\\( *([A-Za-z_0-9]+), *([A-Za-z_0-9]+) *\\).*" "\\1.\\2" test_name ${hit})
string(REGEX MATCH "TEST_?[FP]?" test_type ${hit})
# Parameterized tests have a different signature for the filter
if(${test_type} STREQUAL "TEST_P")
string(REGEX REPLACE ${gtest_case_name_regex} "*/\\1.\\2/*" test_name ${hit})
else()
string(REGEX REPLACE ${gtest_case_name_regex} "\\1.\\2" test_name ${hit})
endif()
add_test(${test_name} ${executable} --gtest_filter=${test_name} ${extra_args})
endforeach()
endforeach()