[FR]: Add hook to explicitly delete `testing::UnitTest::impl_` before destruction
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 39.6k
- Forks
- 10.9k
- Avg merge
- 6d 13h
- Merged PRs (30d)
- 1
Description
Does the feature exist in the most recent commit?
No
Why do we need this feature?
I am working on a gtest suite which dynamically loads test suites at runtime using boost::dll::shared_library. Side note: this requires gtest to be compiled as a shared library and using GTEST_LINKED_AS_SHARED_LIBRARY. This works great for me since I have a hard requirement that only one test executable must be defined, and there are issues statically linking some things due to use of protobuf. The problem I'm running into is that the google-test destructors are getting called after the shared libraries have been unloaded. My workaround for this is to keep a list of boost::dll::shared_library locally and call exit() to skip destructor calls of local variables. This then keeps all of those libraries in memory as the static google-test instance is deleted. I'm not a big fan of this workaround though.
Describe the proposal.
I dug through the implementation code and see that if I could simply call delete impl_; prematurely, this would delete all test suites that exist in all of my shared libraries. Then setting impl_ to nullptr would allow a secondary delete in testing::UnitTest::~UnitTest(). All of that is in private scope, so there is no way I can do this without a public hook.
I'm open to suggestions too. Thanks!
Is the feature specific to an operating system, compiler, or build system version?
No
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the UnitTest implementation and its destructor, focusing on the private impl_ member and the proposed deletion sequence. Done would require an agreed public hook that handles the shared-library unload scenario and avoids a second deletion during UnitTest destruction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100