aboutsummaryrefslogtreecommitdiffstats
path: root/googletest/src
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-01-14 00:41:46 -0500
committervslashg <gfalcon@google.com>2020-01-16 13:55:45 -0500
commit0b024bd91a14a77a7e7d6072ccd88e09c86ddeaa (patch)
tree78c316c82a0281387d5b1959eb6cafcd68848c0b /googletest/src
parented16134fb31382fd41e8fe513a0e9e940d04cd31 (diff)
downloadgoogletest-0b024bd91a14a77a7e7d6072ccd88e09c86ddeaa.tar.gz
googletest-0b024bd91a14a77a7e7d6072ccd88e09c86ddeaa.tar.bz2
googletest-0b024bd91a14a77a7e7d6072ccd88e09c86ddeaa.zip
Googletest export
Add GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST to mark a paramaterized test as allowed to be un-instantiated. This allows test suites, that are defined in libraries and, for other reasons, get linked in (which should probably be avoided, but isn't always possible) to be marked as allowed to go uninstantiated. This can also be used to grandfather existing issues and expedite adoption of the checks with regards to new cases before they can be fixed. PiperOrigin-RevId: 289581573
Diffstat (limited to 'googletest/src')
-rw-r--r--googletest/src/gtest-internal-inl.h8
-rw-r--r--googletest/src/gtest.cc19
2 files changed, 26 insertions, 1 deletions
diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h
index d0ebe0c5..e42ff475 100644
--- a/googletest/src/gtest-internal-inl.h
+++ b/googletest/src/gtest-internal-inl.h
@@ -698,6 +698,10 @@ class GTEST_API_ UnitTestImpl {
return parameterized_test_registry_;
}
+ std::set<std::string>* ignored_parameterized_test_suites() {
+ return &ignored_parameterized_test_suites_;
+ }
+
// Returns TypeParameterizedTestSuiteRegistry object used to keep track of
// type-parameterized tests and instantiations of them.
internal::TypeParameterizedTestSuiteRegistry&
@@ -884,6 +888,10 @@ class GTEST_API_ UnitTestImpl {
internal::TypeParameterizedTestSuiteRegistry
type_parameterized_test_registry_;
+ // The set holding the name of parameterized
+ // test suites that may go uninstantiated.
+ std::set<std::string> ignored_parameterized_test_suites_;
+
// Indicates whether RegisterParameterizedTests() has been called already.
bool parameterized_tests_registered_;
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 2df647ba..1abc664f 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -444,9 +444,21 @@ class FailureTest : public Test {
} // namespace
+std::set<std::string>* GetIgnoredParameterizedTestSuites() {
+ return UnitTest::GetInstance()->impl()->ignored_parameterized_test_suites();
+}
+
+// Add a given test_suit to the list of them allow to go un-instantiated.
+MarkAsIgnored::MarkAsIgnored(const char* test_suite) {
+ GetIgnoredParameterizedTestSuites()->insert(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) {
+ const auto& ignored = *GetIgnoredParameterizedTestSuites();
+ if (ignored.find(name) != ignored.end()) return;
+
std::string message =
"Paramaterized test suite " + name +
" is defined via TEST_P, but never instantiated. None of the test cases "
@@ -455,7 +467,12 @@ void InsertSyntheticTestCase(const std::string &name, CodeLocation location) {
"\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.)"
+ "\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:"
+ "\n\n"
+ "GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(" + name + ");";
std::string full_name = "UninstantiatedParamaterizedTestSuite<" + name + ">";
RegisterTest( //