]> git-server-git.apps.pok.os.sepia.ceph.com Git - googletest.git/commitdiff
Googletest export
authorAbseil Team <absl-team@google.com>
Tue, 14 Jan 2020 19:56:23 +0000 (14:56 -0500)
committervslashg <gfalcon@google.com>
Thu, 16 Jan 2020 18:56:04 +0000 (13:56 -0500)
Wire up things to support marking a type paramaterized test as allowed to be un-instantiated.

PiperOrigin-RevId: 289699939

googletest/src/gtest.cc
googletest/test/googletest-output-test-golden-lin.txt
googletest/test/googletest-param-test-test.cc

index 1abc664ffca09a827d43d867244702a4e83e7757..8e68c04e1d13bd6a658470e0cf271869f09d818a 100644 (file)
@@ -515,8 +515,10 @@ void TypeParameterizedTestSuiteRegistry::RegisterInstantiation(
 }
 
 void TypeParameterizedTestSuiteRegistry::CheckForInstantiations() {
+  const auto& ignored = *GetIgnoredParameterizedTestSuites();
   for (const auto& testcase : suites_) {
     if (testcase.second.instantiated) continue;
+    if (ignored.find(testcase.first) != ignored.end()) continue;
 
     std::string message =
         "Type paramaterized test suite " + testcase.first +
@@ -526,7 +528,12 @@ void TypeParameterizedTestSuiteRegistry::CheckForInstantiations() {
         "Ideally, TYPED_TEST_P definitions should only ever be included as "
         "part of binaries that intend to use them. (As opposed to, for "
         "example, being placed in a library that may be linked in to get other "
-        "utilities.)";
+        "utilities.)"
+        "\n\n"
+        "To suppress this error for this test suite, insert the following line "
+        "(in a non-header) in the namespace it is definedin in:"
+        "\n\n"
+        "GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(" + testcase.first + ");";
 
     std::string full_name =
         "UninstantiatedTypeParamaterizedTestSuite<" + testcase.first + ">";
index 72490816d5e20b7f1dcbdec75fddb04a77ccd3a0..a4a096e4ac50d9d1f11a508f05b9ad96f7b84fc1 100644 (file)
@@ -996,6 +996,10 @@ GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(DetectNotInstantiatedTest);
 Type paramaterized test suite DetectNotInstantiatedTypesTest is defined via REGISTER_TYPED_TEST_SUITE_P, but never instantiated via INSTANTIATE_TYPED_TEST_SUITE_P. None of the test cases will run.
 
 Ideally, TYPED_TEST_P definitions should only ever be included as part of binaries that intend to use them. (As opposed to, for example, being placed in a library that may be linked in to get other utilities.)
+
+To suppress this error for this test suite, insert the following line (in a non-header) in the namespace it is definedin in:
+
+GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(DetectNotInstantiatedTypesTest);
 \e[0;32m[       OK ] \e[mGoogleTestVerification.UninstantiatedTypeParamaterizedTestSuite<DetectNotInstantiatedTypesTest>
 \e[0;32m[----------] \e[mGlobal test environment tear-down
 BarEnvironment::TearDown() called.
index b3b8140d1780ff94f2be2b0dfd748dcb1d49b60a..72a48375cc112cc285dfda0c4db946dbd67ba57e 100644 (file)
@@ -1088,6 +1088,16 @@ TEST_P(NotInstantiatedTest, Used) { }
 using OtherName = NotInstantiatedTest;
 GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(OtherName);
 TEST_P(OtherName, Used) { }
+
+// Used but not instantiated, this would fail. but...
+template <typename T>
+class NotInstantiatedTypeTest : public testing::Test {};
+TYPED_TEST_SUITE_P(NotInstantiatedTypeTest);
+// ... we mark is as allowed.
+GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(NotInstantiatedTypeTest);
+
+TYPED_TEST_P(NotInstantiatedTypeTest, Used) { }
+REGISTER_TYPED_TEST_SUITE_P(NotInstantiatedTypeTest, Used);
 }  // namespace works_here
 
 int main(int argc, char **argv) {