Explorar o código

Merge topic 'GoogleTest-disabled-tests'

92bbb706 GoogleTest: Add support for disabled tests

Acked-by: Kitware Robot <[email protected]>
Reviewed-by: Craig Scott <[email protected]>
Merge-request: !920
Brad King %!s(int64=8) %!d(string=hai) anos
pai
achega
2d3d88f3bb

+ 38 - 8
Modules/GoogleTest.cmake

@@ -172,20 +172,50 @@ function(gtest_add_tests)
 
 
       # Parameterized tests have a different signature for the filter
       # Parameterized tests have a different signature for the filter
       if("x${test_type}" STREQUAL "xTEST_P")
       if("x${test_type}" STREQUAL "xTEST_P")
-        string(REGEX REPLACE ${gtest_case_name_regex}  "*/\\1.\\2/*" test_name ${hit})
+        string(REGEX REPLACE ${gtest_case_name_regex}  "*/\\1.\\2/*" gtest_test_name ${hit})
       elseif("x${test_type}" STREQUAL "xTEST_F" OR "x${test_type}" STREQUAL "xTEST")
       elseif("x${test_type}" STREQUAL "xTEST_F" OR "x${test_type}" STREQUAL "xTEST")
-        string(REGEX REPLACE ${gtest_case_name_regex} "\\1.\\2" test_name ${hit})
+        string(REGEX REPLACE ${gtest_case_name_regex} "\\1.\\2" gtest_test_name ${hit})
       elseif("x${test_type}" STREQUAL "xTYPED_TEST")
       elseif("x${test_type}" STREQUAL "xTYPED_TEST")
-        string(REGEX REPLACE ${gtest_case_name_regex} "\\1/*.\\2" test_name ${hit})
+        string(REGEX REPLACE ${gtest_case_name_regex} "\\1/*.\\2" gtest_test_name ${hit})
       else()
       else()
         message(WARNING "Could not parse GTest ${hit} for adding to CTest.")
         message(WARNING "Could not parse GTest ${hit} for adding to CTest.")
         continue()
         continue()
       endif()
       endif()
-      add_test(NAME ${ARGS_TEST_PREFIX}${test_name}${ARGS_TEST_SUFFIX}
-               ${workDir}
-               COMMAND ${ARGS_TARGET} --gtest_filter=${test_name} ${ARGS_EXTRA_ARGS}
-      )
-      list(APPEND testList ${ARGS_TEST_PREFIX}${test_name}${ARGS_TEST_SUFFIX})
+
+      # Make sure tests disabled in GTest get disabled in CTest
+      if(gtest_test_name MATCHES "(^|\\.)DISABLED_")
+        # Add the disabled test if CMake is new enough
+        # Note that this check is to allow backwards compatibility so this
+        # module can be copied locally in projects to use with older CMake
+        # versions
+        if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.8.20170401)
+          string(REGEX REPLACE
+                 "(^|\\.)DISABLED_" "\\1"
+                 orig_test_name "${gtest_test_name}"
+          )
+          set(ctest_test_name
+              ${ARGS_TEST_PREFIX}${orig_test_name}${ARGS_TEST_SUFFIX}
+          )
+          add_test(NAME ${ctest_test_name}
+                   ${workDir}
+                   COMMAND ${ARGS_TARGET}
+                     --gtest_also_run_disabled_tests
+                     --gtest_filter=${gtest_test_name}
+                     ${ARGS_EXTRA_ARGS}
+          )
+          set_tests_properties(${ctest_test_name} PROPERTIES DISABLED TRUE)
+          list(APPEND testList ${ctest_test_name})
+        endif()
+      else()
+        set(ctest_test_name ${ARGS_TEST_PREFIX}${gtest_test_name}${ARGS_TEST_SUFFIX})
+        add_test(NAME ${ctest_test_name}
+                 ${workDir}
+                 COMMAND ${ARGS_TARGET}
+                   --gtest_filter=${gtest_test_name}
+                   ${ARGS_EXTRA_ARGS}
+        )
+        list(APPEND testList ${ctest_test_name})
+      endif()
     endforeach()
     endforeach()
   endforeach()
   endforeach()
 
 

+ 14 - 1
Tests/GoogleTest/Test/CMakeLists.txt

@@ -53,12 +53,25 @@ gtest_add_tests(TARGET test_gtest2
 )
 )
 set(expectedTests
 set(expectedTests
   GoogleTest.SomethingElse
   GoogleTest.SomethingElse
+  GoogleTest.OffTest1
+  GoogleTest.OffTest2
+  GoogleTest.OffTest3
 )
 )
 if(NOT testList STREQUAL "${expectedTests}")
 if(NOT testList STREQUAL "${expectedTests}")
   message(FATAL_ERROR "Expected test list: ${expectedTests}
   message(FATAL_ERROR "Expected test list: ${expectedTests}
 Actual test list: ${testList}")
 Actual test list: ${testList}")
 endif()
 endif()
-
+set(disabledTests
+  GoogleTest.OffTest1
+  GoogleTest.OffTest2
+  GoogleTest.OffTest3
+)
+foreach(T ${disabledTests})
+  get_test_property(${T} DISABLED testDisabled)
+  if(NOT testDisabled)
+    message(FATAL_ERROR "Test ${T} should be disabled but is not")
+  endif()
+endforeach()
 
 
 # Non-keyword form, auto-find sources
 # Non-keyword form, auto-find sources
 add_executable(test_gtest3 main3.cxx)
 add_executable(test_gtest3 main3.cxx)

+ 15 - 0
Tests/GoogleTest/Test/main2.h

@@ -4,3 +4,18 @@ TEST(GoogleTest, SomethingElse)
 {
 {
   ASSERT_TRUE(true);
   ASSERT_TRUE(true);
 }
 }
+
+TEST(GoogleTest, DISABLED_OffTest1)
+{
+  ASSERT_TRUE(true);
+}
+
+TEST(DISABLED_GoogleTest, OffTest2)
+{
+  ASSERT_TRUE(true);
+}
+
+TEST(DISABLED_GoogleTest, DISABLED_OffTest3)
+{
+  ASSERT_TRUE(true);
+}