cmake: enable running the tests
authorAdam Simpkins <simpkins@fb.com>
Fri, 19 Jan 2018 04:43:19 +0000 (20:43 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 19 Jan 2018 05:04:33 +0000 (21:04 -0800)
Summary:
CMake 3.9+ includes built-in support for gtest.  This updates the CMake build
scripts to make use of this if the GoogleTest module is available.

Reviewed By: meyering

Differential Revision: D6745369

fbshipit-source-id: 1ef978874b9a0ef2cc5f48ab1c7a0b55d0f1155e

CMake/FollyFunctions.cmake
CMakeLists.txt

index 691ac4a39b87a125ad9af97994f3f3b8e590552b..1cfc60a3ed0868302aecc26cb4865401f524d500 100755 (executable)
@@ -258,6 +258,12 @@ function(folly_define_tests)
         ${test_${cur_test}_headers}
         ${test_${cur_test}_sources}
       )
         ${test_${cur_test}_headers}
         ${test_${cur_test}_sources}
       )
+      if (HAVE_CMAKE_GTEST)
+        gtest_add_tests(TARGET ${cur_test_name}
+                        TEST_PREFIX "${cur_test_name}."
+                        TEST_LIST test_cases)
+        set_tests_properties(${test_cases} PROPERTIES TIMEOUT 120)
+      endif()
       if (NOT "x${test_${cur_test}_content_dir}" STREQUAL "x")
         # Copy the content directory to the output directory tree so that
         # tests can be run easily from Visual Studio without having to change
       if (NOT "x${test_${cur_test}_content_dir}" STREQUAL "x")
         # Copy the content directory to the output directory tree so that
         # tests can be run easily from Visual Studio without having to change
index b0982f940d942eda93312141b46f074049758e68..27834daeeae6f89a467914ca1c2ba2f45182537f 100755 (executable)
@@ -298,8 +298,11 @@ option(BUILD_HANGING_TESTS "If enabled, compile tests that are known to hang." O
 option(BUILD_SLOW_TESTS "If enabled, compile tests that take a while to run in debug mode." OFF)
 if (BUILD_TESTS)
   find_package(GMock MODULE REQUIRED)
 option(BUILD_SLOW_TESTS "If enabled, compile tests that take a while to run in debug mode." OFF)
 if (BUILD_TESTS)
   find_package(GMock MODULE REQUIRED)
+  include(GoogleTest OPTIONAL RESULT_VARIABLE HAVE_CMAKE_GTEST)
+  enable_testing()
 
   add_library(folly_test_support
 
   add_library(folly_test_support
+    ${FOLLY_DIR}/test/common/TestMain.cpp
     ${FOLLY_DIR}/test/DeterministicSchedule.cpp
     ${FOLLY_DIR}/test/DeterministicSchedule.h
     ${FOLLY_DIR}/test/SingletonTestStructs.cpp
     ${FOLLY_DIR}/test/DeterministicSchedule.cpp
     ${FOLLY_DIR}/test/DeterministicSchedule.h
     ${FOLLY_DIR}/test/SingletonTestStructs.cpp
@@ -354,7 +357,9 @@ if (BUILD_TESTS)
       TEST access_test SOURCES AccessTest.cpp
       TEST array_test SOURCES ArrayTest.cpp
       TEST bit_iterator_test SOURCES BitIteratorTest.cpp
       TEST access_test SOURCES AccessTest.cpp
       TEST array_test SOURCES ArrayTest.cpp
       TEST bit_iterator_test SOURCES BitIteratorTest.cpp
-      TEST enumerate_test SOURCES EnumerateTest.cpp
+      # TODO: CMake's gtest_add_tests() function currently chokes on
+      # EnumerateTest.cpp since it uses macros to define tests.
+      #TEST enumerate_test SOURCES EnumerateTest.cpp
       TEST evicting_cache_map_test SOURCES EvictingCacheMapTest.cpp
       TEST foreach_test SOURCES ForeachTest.cpp
       TEST merge_test SOURCES MergeTest.cpp
       TEST evicting_cache_map_test SOURCES EvictingCacheMapTest.cpp
       TEST foreach_test SOURCES ForeachTest.cpp
       TEST merge_test SOURCES MergeTest.cpp