]> git-server-git.apps.pok.os.sepia.ceph.com Git - googletest.git/commitdiff
Googletest export
authorAbseil Team <absl-team@google.com>
Thu, 16 Jan 2020 19:58:28 +0000 (14:58 -0500)
committerXiaoyi Zhang <zhangxy@google.com>
Tue, 21 Jan 2020 21:26:08 +0000 (16:26 -0500)
Add extra filtering so that the reported message differentiates between the case where INSTANTIATE_TEST_SUITE_P is missing vs. the case where TEST_P is missing.

PiperOrigin-RevId: 290114508

googletest/include/gtest/internal/gtest-param-util.h
googletest/src/gtest.cc
googletest/test/googletest-output-test-golden-lin.txt
googletest/test/googletest-output-test_.cc

index 65aa956826ccbc02c23dd464e8b66cee8b5d0b03..7f7a13bf84b5a0ed5d22784a8db86459a9c1bd11 100644 (file)
@@ -483,7 +483,7 @@ struct MarkAsIgnored {
 };
 
 GTEST_API_ void InsertSyntheticTestCase(const std::string& name,
-                                        CodeLocation location);
+                                        CodeLocation location, bool has_test_p);
 
 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
 //
@@ -600,7 +600,8 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
 
     if (!generated_instantiations) {
       // There are no generaotrs, or they all generate nothing ...
-      InsertSyntheticTestCase(GetTestSuiteName(), code_location_);
+      InsertSyntheticTestCase(GetTestSuiteName(), code_location_,
+                              !tests_.empty());
     }
   }    // RegisterTests
 
index 1f8a68e37e7c7f58f4d22ae008afe71512b413c5..095778e6e93fcd0697594893e414bc2315c7c076 100644 (file)
@@ -455,19 +455,32 @@ MarkAsIgnored::MarkAsIgnored(const char* test_suite) {
 
 // If this parameterized test suite has no instantiations (and that
 // has not been marked as okay), emit a test case reporting that.
-void InsertSyntheticTestCase(const std::string &name, CodeLocation location) {
+void InsertSyntheticTestCase(const std::string& name, CodeLocation location,
+                             bool has_test_p) {
   const auto& ignored = *GetIgnoredParameterizedTestSuites();
   if (ignored.find(name) != ignored.end()) return;
 
-  std::string message =
-      "Paramaterized test suite " + name +
+  const char kMissingInstantiation[] =  //
       " is defined via TEST_P, but never instantiated. None of the test cases "
       "will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only "
       "ones provided expand to nothing."
       "\n\n"
       "Ideally, 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.)"
+      "placed in a library that may be linked in to get other utilities.)";
+
+  const char kMissingTestCase[] =  //
+      " is instantiated via INSTANTIATE_TEST_SUITE_P, but no tests are "
+      "defined via TEST_P . No test cases will run."
+      "\n\n"
+      "Ideally, INSTANTIATE_TEST_SUITE_P should only ever be invoked from "
+      "code that always depend on code that provides TEST_P. Failing to do "
+      "so is often an indication of dead code, e.g. the last TEST_P was "
+      "removed but the rest got left behind.";
+
+  std::string message =
+      "Paramaterized test suite " + name +
+      (has_test_p ? kMissingInstantiation : kMissingTestCase) +
       "\n\n"
       "To suppress this error for this test suite, insert the following line "
       "(in a non-header) in the namespace it is defined in:"
index 2b34aad39c057f7fce2d3583d39b96fb0e4cd7ea..8bc45800b94660f748fb0b270686878f9fbd4269 100644 (file)
@@ -12,7 +12,7 @@ Expected equality of these values:
   3
 Stack trace: (omitted)
 
-\e[0;32m[==========] \e[mRunning 87 tests from 41 test suites.
+\e[0;32m[==========] \e[mRunning 88 tests from 41 test suites.
 \e[0;32m[----------] \e[mGlobal test environment set-up.
 FooEnvironment::SetUp() called.
 BarEnvironment::SetUp() called.
@@ -982,7 +982,16 @@ Expected failure
 Stack trace: (omitted)
 
 \e[0;31m[  FAILED  ] \e[mPrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
-\e[0;32m[----------] \e[m2 tests from GoogleTestVerification
+\e[0;32m[----------] \e[m3 tests from GoogleTestVerification
+\e[0;32m[ RUN      ] \e[mGoogleTestVerification.UninstantiatedParamaterizedTestSuite<NoTests>
+Paramaterized test suite NoTests is instantiated via INSTANTIATE_TEST_SUITE_P, but no tests are defined via TEST_P . No test cases will run.
+
+Ideally, INSTANTIATE_TEST_SUITE_P should only ever be invoked from code that always depend on code that provides TEST_P. Failing to do so is often an indication of dead code, e.g. the last TEST_P was removed but the rest got left behind.
+
+To suppress this error for this test suite, insert the following line (in a non-header) in the namespace it is defined in:
+
+GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NoTests);
+\e[0;32m[       OK ] \e[mGoogleTestVerification.UninstantiatedParamaterizedTestSuite<NoTests>
 \e[0;32m[ RUN      ] \e[mGoogleTestVerification.UninstantiatedParamaterizedTestSuite<DetectNotInstantiatedTest>
 Paramaterized test suite DetectNotInstantiatedTest is defined via TEST_P, but never instantiated. None of the test cases will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only ones provided expand to nothing.
 
@@ -1014,8 +1023,8 @@ Failed
 Expected fatal failure.
 Stack trace: (omitted)
 
-\e[0;32m[==========] \e[m87 tests from 41 test suites ran.
-\e[0;32m[  PASSED  ] \e[m33 tests.
+\e[0;32m[==========] \e[m88 tests from 41 test suites ran.
+\e[0;32m[  PASSED  ] \e[m34 tests.
 \e[0;31m[  FAILED  ] \e[m54 tests, listed below:
 \e[0;31m[  FAILED  ] \e[mNonfatalFailureTest.EscapesStringOperands
 \e[0;31m[  FAILED  ] \e[mNonfatalFailureTest.DiffForLongStrings
index b1d66f9fb60380b8372335fd61f904bf5dd76fd0..76af5bca27c91a33275e37490379e45eec0ed682 100644 (file)
@@ -790,6 +790,10 @@ INSTANTIATE_TEST_SUITE_P(PrintingStrings,
                          testing::Values(std::string("a")),
                          ParamNameFunc);
 
+// The case where a suite has INSTANTIATE_TEST_SUITE_P but not TEST_P.
+using NoTests = ParamTest;
+INSTANTIATE_TEST_SUITE_P(ThisIsOdd, NoTests, ::testing::Values("Hello"));
+
 // fails under kErrorOnUninstantiatedParameterizedTest=true
 class DetectNotInstantiatedTest : public testing::TestWithParam<int> {};
 TEST_P(DetectNotInstantiatedTest, Used) { }