summaryrefslogtreecommitdiffstats
path: root/googletest/include/gtest/internal/gtest-param-util.h
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2019-12-11 03:43:25 (GMT)
committerMatt Calabrese <calabrese@x.team>2019-12-13 16:35:09 (GMT)
commitdeeaeb942e20b6711c01e58653f50934d51b5246 (patch)
tree801a0c8322372642cdb5a88647e621c209f61738 /googletest/include/gtest/internal/gtest-param-util.h
parent2ba222fcc5bc0bb640ccd3131356b7aac93c8bb7 (diff)
downloadgoogletest-deeaeb942e20b6711c01e58653f50934d51b5246.zip
googletest-deeaeb942e20b6711c01e58653f50934d51b5246.tar.gz
googletest-deeaeb942e20b6711c01e58653f50934d51b5246.tar.bz2
Export Test - Do Not Merge
Detect when C++ parametric tests (TEST_P) are not instantiated. When an un-instantiated TEST_P is found, a new test will be inserted that will emit a warning message. This can be made to error with minor code edits. In the future, that is intended to be the default. PiperOrigin-RevId: 284901666
Diffstat (limited to 'googletest/include/gtest/internal/gtest-param-util.h')
-rw-r--r--googletest/include/gtest/internal/gtest-param-util.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h
index e900b3f..539fa52 100644
--- a/googletest/include/gtest/internal/gtest-param-util.h
+++ b/googletest/include/gtest/internal/gtest-param-util.h
@@ -42,12 +42,14 @@
#include <memory>
#include <set>
#include <tuple>
+#include <type_traits>
#include <utility>
#include <vector>
#include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-port.h"
#include "gtest/gtest-printers.h"
+#include "gtest/gtest-test-part.h"
namespace testing {
// Input to a parameterized test name generator, describing a test parameter.
@@ -472,6 +474,8 @@ class ParameterizedTestSuiteInfoBase {
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfoBase);
};
+void InsertSyntheticTestCase(const std::string &name, CodeLocation location);
+
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
//
// ParameterizedTestSuiteInfo accumulates tests obtained from TEST_P
@@ -522,11 +526,13 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
return 0; // Return value used only to run this method in namespace scope.
}
// UnitTest class invokes this method to register tests in this test suite
- // test suites right before running tests in RUN_ALL_TESTS macro.
+ // right before running tests in RUN_ALL_TESTS macro.
// This method should not be called more than once on any single
// instance of a ParameterizedTestSuiteInfoBase derived class.
// UnitTest has a guard to prevent from calling this method more than once.
void RegisterTests() override {
+ bool generated_instantiations = false;
+
for (typename TestInfoContainer::iterator test_it = tests_.begin();
test_it != tests_.end(); ++test_it) {
std::shared_ptr<TestInfo> test_info = *test_it;
@@ -549,6 +555,8 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
for (typename ParamGenerator<ParamType>::iterator param_it =
generator.begin();
param_it != generator.end(); ++param_it, ++i) {
+ generated_instantiations = true;
+
Message test_name_stream;
std::string param_name = name_func(
@@ -577,6 +585,11 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
} // for param_it
} // for gen_it
} // for test_it
+
+ if (!generated_instantiations) {
+ // There are no generaotrs, or they all generate nothing ...
+ InsertSyntheticTestCase(GetTestSuiteName(), code_location_);
+ }
} // RegisterTests
private: