Commit 18b67bfc authored by Abseil Team's avatar Abseil Team Committed by Xiaoyi Zhang
Browse files

Googletest export

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
parent 8b4817e3
...@@ -483,7 +483,7 @@ struct MarkAsIgnored { ...@@ -483,7 +483,7 @@ struct MarkAsIgnored {
}; };
GTEST_API_ void InsertSyntheticTestCase(const std::string& name, GTEST_API_ void InsertSyntheticTestCase(const std::string& name,
CodeLocation location); CodeLocation location, bool has_test_p);
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
// //
...@@ -600,7 +600,8 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { ...@@ -600,7 +600,8 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
if (!generated_instantiations) { if (!generated_instantiations) {
// There are no generaotrs, or they all generate nothing ... // There are no generaotrs, or they all generate nothing ...
InsertSyntheticTestCase(GetTestSuiteName(), code_location_); InsertSyntheticTestCase(GetTestSuiteName(), code_location_,
!tests_.empty());
} }
} // RegisterTests } // RegisterTests
......
...@@ -455,19 +455,32 @@ MarkAsIgnored::MarkAsIgnored(const char* test_suite) { ...@@ -455,19 +455,32 @@ MarkAsIgnored::MarkAsIgnored(const char* test_suite) {
// If this parameterized test suite has no instantiations (and that // If this parameterized test suite has no instantiations (and that
// has not been marked as okay), emit a test case reporting 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(); const auto& ignored = *GetIgnoredParameterizedTestSuites();
if (ignored.find(name) != ignored.end()) return; if (ignored.find(name) != ignored.end()) return;
std::string message = const char kMissingInstantiation[] = //
"Paramaterized test suite " + name +
" is defined via TEST_P, but never instantiated. None of the test cases " " 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 " "will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only "
"ones provided expand to nothing." "ones provided expand to nothing."
"\n\n" "\n\n"
"Ideally, TEST_P definitions should only ever be included as part of " "Ideally, TEST_P definitions should only ever be included as part of "
"binaries that intend to use them. (As opposed to, for example, being " "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" "\n\n"
"To suppress this error for this test suite, insert the following line " "To suppress this error for this test suite, insert the following line "
"(in a non-header) in the namespace it is defined in:" "(in a non-header) in the namespace it is defined in:"
......
...@@ -12,7 +12,7 @@ Expected equality of these values: ...@@ -12,7 +12,7 @@ Expected equality of these values:
3 3
Stack trace: (omitted) Stack trace: (omitted)
[==========] Running 87 tests from 41 test suites. [==========] Running 88 tests from 41 test suites.
[----------] Global test environment set-up. [----------] Global test environment set-up.
FooEnvironment::SetUp() called. FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called. BarEnvironment::SetUp() called.
...@@ -982,7 +982,16 @@ Expected failure ...@@ -982,7 +982,16 @@ Expected failure
Stack trace: (omitted) Stack trace: (omitted)
[ FAILED ] PrintingStrings/ParamTest.Failure/a, where GetParam() = "a" [ FAILED ] PrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
[----------] 2 tests from GoogleTestVerification [----------] 3 tests from GoogleTestVerification
[ RUN ] GoogleTestVerification.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);
[ OK ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite<NoTests>
[ RUN ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite<DetectNotInstantiatedTest> [ RUN ] GoogleTestVerification.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. 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 ...@@ -1014,8 +1023,8 @@ Failed
Expected fatal failure. Expected fatal failure.
Stack trace: (omitted) Stack trace: (omitted)
[==========] 87 tests from 41 test suites ran. [==========] 88 tests from 41 test suites ran.
[ PASSED ] 33 tests. [ PASSED ] 34 tests.
[ FAILED ] 54 tests, listed below: [ FAILED ] 54 tests, listed below:
[ FAILED ] NonfatalFailureTest.EscapesStringOperands [ FAILED ] NonfatalFailureTest.EscapesStringOperands
[ FAILED ] NonfatalFailureTest.DiffForLongStrings [ FAILED ] NonfatalFailureTest.DiffForLongStrings
......
...@@ -790,6 +790,10 @@ INSTANTIATE_TEST_SUITE_P(PrintingStrings, ...@@ -790,6 +790,10 @@ INSTANTIATE_TEST_SUITE_P(PrintingStrings,
testing::Values(std::string("a")), testing::Values(std::string("a")),
ParamNameFunc); 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 // fails under kErrorOnUninstantiatedParameterizedTest=true
class DetectNotInstantiatedTest : public testing::TestWithParam<int> {}; class DetectNotInstantiatedTest : public testing::TestWithParam<int> {};
TEST_P(DetectNotInstantiatedTest, Used) { } TEST_P(DetectNotInstantiatedTest, Used) { }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment