aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-01-14 14:56:23 -0500
committervslashg <gfalcon@google.com>2020-01-16 13:56:04 -0500
commit3e79d366e380ec85b7de9409211b184bc8529655 (patch)
treefaab3a533deda76d3795cbf4702744abfba07111
parent7a8591e6e4e206b748feb052f620c45278e686d0 (diff)
downloadgoogletest-3e79d366e380ec85b7de9409211b184bc8529655.tar.gz
googletest-3e79d366e380ec85b7de9409211b184bc8529655.tar.bz2
googletest-3e79d366e380ec85b7de9409211b184bc8529655.zip
Googletest export
Wire up things to support marking a type paramaterized test as allowed to be un-instantiated. PiperOrigin-RevId: 289699939
-rw-r--r--googletest/src/gtest.cc9
-rw-r--r--googletest/test/googletest-output-test-golden-lin.txt4
-rw-r--r--googletest/test/googletest-param-test-test.cc10
3 files changed, 22 insertions, 1 deletions
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 1abc664f..8e68c04e 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -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 + ">";
diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt
index 72490816..a4a096e4 100644
--- a/googletest/test/googletest-output-test-golden-lin.txt
+++ b/googletest/test/googletest-output-test-golden-lin.txt
@@ -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);
[ OK ] GoogleTestVerification.UninstantiatedTypeParamaterizedTestSuite<DetectNotInstantiatedTypesTest>
[----------] Global test environment tear-down
BarEnvironment::TearDown() called.
diff --git a/googletest/test/googletest-param-test-test.cc b/googletest/test/googletest-param-test-test.cc
index b3b8140d..72a48375 100644
--- a/googletest/test/googletest-param-test-test.cc
+++ b/googletest/test/googletest-param-test-test.cc
@@ -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) {