googletest icon indicating copy to clipboard operation
googletest copied to clipboard

Set kErrorOnUninstantiatedParameterizedTest et al. to true

Open bcsgh opened this issue 5 years ago • 13 comments

This will start reporting missing instantiations of parameterized tests as a failing test under the GoogleTestVerification test suite (they are currently reported, but just as a notice from a passing test).

NOTE: It is expected that this will surface existing issues in downstream consumers.

bcsgh avatar Jan 24 '20 02:01 bcsgh

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

googlebot avatar Jan 24 '20 02:01 googlebot

As discussed, this may take some time to fix internal users, but we do intend to accept this eventually.

asoffer avatar Jan 24 '20 05:01 asoffer

Yup. That was what I was expecting. Thanks.

bcsgh avatar Jan 24 '20 05:01 bcsgh

BTW: seems this fails presubmit by catching an extra INSTANTIATE_TEST_SUITE_P in the tests. It seems the issue is a orphaned .cc file and another that an overly wide glob() is picking up:

The relevant bit of the log:

[----------] 2 tests from GoogleTestVerification [ RUN ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite<ExternalInstantiationTest> googletest/test/googletest-param-test2-test.cc:51: Failure

Paramaterized test suite ExternalInstantiationTest 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(ExternalInstantiationTest); Stack trace: ...

[ FAILED ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite<ExternalInstantiationTest> (1 ms) [ RUN ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite<InstantiationInMultipleTranslationUnitsTest> googletest/test/googletest-param-test2-test.cc:60: Failure

Paramaterized test suite InstantiationInMultipleTranslationUnitsTest 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(InstantiationInMultipleTranslationUnitsTest); Stack trace: ... [ FAILED ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite<InstantiationInMultipleTranslationUnitsTest> (0 ms)

bcsgh avatar Jan 25 '20 21:01 bcsgh

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

googlebot avatar Feb 10 '20 15:02 googlebot

Bump? Any Progress on this?

bcsgh avatar Apr 18 '20 18:04 bcsgh

To allow gradual detection and fix: would it be possible to add a compile time option to enable this mode?

antoniovicente avatar May 15 '20 23:05 antoniovicente

IIRC that was actually proposed (by me, internally to Google) at one point. I don't remember the details, but it got turned down. (I think it ended up with me reluctantly agreeing with the argument?)

bcsgh avatar May 17 '20 21:05 bcsgh

IIRC that was actually proposed (by me, internally to Google) at one point. I don't remember the details, but it got turned down. (I think it ended up with me reluctantly agreeing with the argument?)

So it goes. I was fortunate enough to be cc'ed on an google-internal report about some tests in an open-source project that I'm a part of which are not running. I'm sad that I can't protect the open source project from regressing once the relevant tests are fixed.

antoniovicente avatar May 18 '20 15:05 antoniovicente

It happened: https://github.com/google/googletest/commit/ec94d9f24c92a5090fda5567156d6dde99cdbf31

yurykats avatar Jun 11 '20 12:06 yurykats

Hello, has googletest switched to "live at HEAD" instead of regular releases? If so, has a refactoring tool been issued for this change, as per the policy ?

Is there a changelog or other announcement mechanism that developers should be subscribing to?

Debian packaged a recent git snapshot of googletest, and now other Debian packages that build and run googletest tests at packaging building time are broken :-(

mr-c avatar Nov 02 '20 10:11 mr-c

Note, this is mostly a bunch of anecdotal observations, so take them with a suitable number of grains of salt.

tl;dr; I don't think it's practicable to automate a significant portion of the work needed to fix issues this surfaces. I would suggest the best course of action is to manually fix things. In the case where there isn't an underlying bug being masked by the missing test, this is easy. If there is such a bug, then that bug will likely be the majority of the work.


I did the original work for building and deploying this internal to Google. In doing that, specifically in fixing the existing cases, there are approximately three actions that were taken to fix things: 1) Delete the Test case/suite, 2) Add a GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST or 3) Add instantiations. And the split between them was not too far off equal.

As for automating things:

  • Inside Google, case 2 was automated using clang's RefactoringEngine (that may still be around, but I no longer have access), but that was mostly because of the quantity of cases to be handled rater than them being hard to handle. And this is actually the least preferred resolution is most case as it can easily paper over actual bugs.
  • Case 1 could also be easily automated in a similar way (and shouldn't be bulk applied, for similar reasons).
  • Case 3 is fundamentally impossible to automate. Empirically, even tests value parameterized on bool have a non-negligible number of cases that can't just be instantiated for both true/false. I tried automating that for the cases I had access to and a bunch of cases still needed manual intervention (e.g. one or the other cases may only be valid in particular build environments).

And even then, the decision of which of those cases to apply will always require semantic understanding of the project that tools will never have (or if they do get that, then I'm out of work). At best, you can apply case 2 and file bugs to go back end manual inspect them.

Furthermore, in my experience, a non-trivial number of cases where the fix was to add instantiations surfaced real bugs which, in a nutshell, was the original motivation for the whole project.

bcsgh avatar Nov 02 '20 16:11 bcsgh

kErrorOnUninstantiatedParameterizedTest et al. should probably be removed at this point. They have been true for 3.5 years.

bcsgh avatar Feb 07 '24 19:02 bcsgh