Comments (3)
I haven't tried this, so I could be wrong, but I think this is probably working as intended.
It looks like under the hood, the SUCCEED()
macro allocates memory, and frees it in its destructor. The destructor is not run until after the call to _CrtMemDifference
, so I'm guessing this is the source of the difference.
Now we could change SUCCEED()
to not allocate memory, but that is not a scalable solution. Any RAII object on the stack is going to have the same problem.
If you really want to use _CrtMemDifference
(and I think there are much better memory checkers available, like LSAN), I think you should create an RAII object that saves the state in its constructor and checks for leaks in its destructor. Put this object on the stack and it will ensure that it runs after all objects that were constructed after it have also had their destructors called.
from googletest.
By the way, you can test my hypothesis by simply using an additional set of braces around the body of the test:
TEST(GoogleTest, TestSucceed)
{
// ---- store heap state ----
_CrtMemState s1, s2, s3;
_CrtMemCheckpoint(&s1);
// ---- TEST ----
{
SUCCEED();
}
// ---- compare heap state ----
_CrtMemCheckpoint(&s2);
bool hasMemoryLeaks = (0 != _CrtMemDifference(&s3, &s1, &s2));
if (hasMemoryLeaks)
{
_CrtMemDumpAllObjectsSince(&s1);
}
EXPECT_FALSE(hasMemoryLeaks);
}
from googletest.
@derekmauro Sorry for the delay, I was out of the office for a few days.
Unfortunately, your suggestion does not bring any improvement.
I would have been surprised too, because in my real project the memory leak check is handled in a separate TestEventListener. So the binding scope of SUCCEED() is already finished when the memory check is called. I have simplified the call structure somewhat just for this issue description.
from googletest.
Related Issues (20)
- MSVC `SEH exception with code 0xc0000005` when using `SUCCEED` HOT 1
- Cannot link gtest HOT 1
- [FR]: ExpectationSet(std::initializer_list<Expectation>) HOT 1
- [Bug]: Mutex deadlock when expecting a function call HOT 1
- [Bug]: Google Test Executables don't respect additional help flags mentioned in the documentation
- [Bug]: No details about why GetTempFileName fails
- [Bug]: GCC-12: Compiler warning with C++20 mode in testing::internal::CanonicalizeForStdLibVersioning HOT 1
- [Bug]: Referenced directories not found leading to "duplicate symbols"
- [FR]: Remove Language C dependency on cmakes.
- [Bug]: Python toolchain in MODULE.bazel conflicts with downstream registered versions HOT 2
- Rewrite gtest_main.cc, gmock_main.cc, gtest-all.cc, and gmock-all.cc to use `.h` or `.hpp` files rather than `.cc` files.
- --gtest_list_tests prints incorrect test names HOT 1
- [Bug]: Function call from Test `TearDown` script is counted in Call count
- [FR]: Add gtest-spi.h interface for retrieving SCOPED_TRACE() traces
- [Bug]: undefined reference to `testing::internal::PrintU8StringTo`
- [Bug]: Death tests don't work with emscripten
- gmock/gtest not built/installed
- [Bug]: PDBs not installed with Windows CMake build
- Make death tests more portable, including signals on Windows.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from googletest.