Skip to content

Commit

Permalink
Googletest export
Browse files Browse the repository at this point in the history
Fail TEST_Ps or TYPED_TEST_Ps that are defined but are not instantiated, as well as the opposite case, where INSTANTIATE_TEST_SUITE_P or INSTANTIATE_TYPED_TEST_SUITE_P is used but without any matching TEST_P or TYPED_TEST_P.

PiperOrigin-RevId: 315255779
  • Loading branch information
Abseil Team authored and vslashg committed Jun 10, 2020
1 parent 1b0cdaa commit ec94d9f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions googletest/src/gtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ namespace {
// inserted to report ether an error or a log message.
//
// This configuration bit will likely be removed at some point.
constexpr bool kErrorOnUninstantiatedParameterizedTest = false;
constexpr bool kErrorOnUninstantiatedTypeParameterizedTest = false;
constexpr bool kErrorOnUninstantiatedParameterizedTest = true;
constexpr bool kErrorOnUninstantiatedTypeParameterizedTest = true;

// A test that fails at a given file/line location with a given message.
class FailureTest : public Test {
Expand Down
24 changes: 18 additions & 6 deletions googletest/test/googletest-output-test-golden-lin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -984,32 +984,41 @@ Stack trace: (omitted)
[ FAILED ] PrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
[----------] 3 tests from GoogleTestVerification
[ RUN ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite<NoTests>
googletest-output-test_.cc:#: Failure
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>
Stack trace: (omitted)

[ FAILED ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite<NoTests>
[ RUN ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite<DetectNotInstantiatedTest>
googletest-output-test_.cc:#: Failure
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.

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.)

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(DetectNotInstantiatedTest);
[ OK ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite<DetectNotInstantiatedTest>
Stack trace: (omitted)

[ FAILED ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite<DetectNotInstantiatedTest>
[ RUN ] GoogleTestVerification.UninstantiatedTypeParamaterizedTestSuite<DetectNotInstantiatedTypesTest>
googletest-output-test_.cc:#: Failure
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_PARAMETERIZED_TEST(DetectNotInstantiatedTypesTest);
[ OK ] GoogleTestVerification.UninstantiatedTypeParamaterizedTestSuite<DetectNotInstantiatedTypesTest>
Stack trace: (omitted)

[ FAILED ] GoogleTestVerification.UninstantiatedTypeParamaterizedTestSuite<DetectNotInstantiatedTypesTest>
[----------] Global test environment tear-down
BarEnvironment::TearDown() called.
googletest-output-test_.cc:#: Failure
Expand All @@ -1024,8 +1033,8 @@ Expected fatal failure.
Stack trace: (omitted)

[==========] 88 tests from 41 test suites ran.
[ PASSED ] 34 tests.
[ FAILED ] 54 tests, listed below:
[ PASSED ] 31 tests.
[ FAILED ] 57 tests, listed below:
[ FAILED ] NonfatalFailureTest.EscapesStringOperands
[ FAILED ] NonfatalFailureTest.DiffForLongStrings
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
Expand Down Expand Up @@ -1080,8 +1089,11 @@ Stack trace: (omitted)
[ FAILED ] BadDynamicFixture2.Derived
[ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
[ FAILED ] PrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
[ FAILED ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite<NoTests>
[ FAILED ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite<DetectNotInstantiatedTest>
[ FAILED ] GoogleTestVerification.UninstantiatedTypeParamaterizedTestSuite<DetectNotInstantiatedTypesTest>

54 FAILED TESTS
57 FAILED TESTS
 YOU HAVE 1 DISABLED TEST

Note: Google Test filter = FatalFailureTest.*:LoggingTest.*
Expand Down

0 comments on commit ec94d9f

Please sign in to comment.