SEH exception in UnitTestImpl::CurrentOsStackTraceExceptTop in case of a global mock
@derekmauro is already working on this.
Since May 23, 2022.
- Dominant language
- C++
- Stars
- 39.6k
- Forks
- 10.9k
- Avg merge
- 6d 13h
- Merged PRs (30d)
- 1
Description
Describe the bug
When there is a global instance (created in a global scope) of a class with a mocked method and the test that uses this global instance is the only available test, there will be a SEH exception in UnitTestImpl::CurrentOsStackTraceExceptTop while trying to report an unsuccessful EXPECT_CALL.
Steps to reproduce the bug
Consider the following source file:
#include "gtest/gtest.h"
#include "gmock/gmock.h"
class SomeInterface
{
public:
virtual ~SomeInterface() { }
virtual int SomeMethod(int) = 0;
};
class SomeClass : public SomeInterface
{
public:
MOCK_METHOD(int, SomeMethod, (int), (override));
};
SomeClass g_SomeInstance; // global scope
TEST(SomeTestSuite, SomeTest)
{
using ::testing::Exactly;
using ::testing::_;
EXPECT_CALL(g_SomeInstance, SomeMethod(_)).Times(Exactly(1)); // not actually called
}
The problem is that in this case the following method
UnitTestImpl::~UnitTestImpl() {
// Deletes every TestSuite.
ForEach(test_suites_, internal::Delete<TestSuite>);
// Deletes every Environment.
ForEach(environments_, internal::Delete<Environment>);
delete os_stack_trace_getter_;
}
is called before this one:
std::string UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) {
return os_stack_trace_getter()->CurrentStackTrace(
static_cast<int>(GTEST_FLAG_GET(stack_trace_depth)), skip_count + 1
// Skips the user-specified number of frames plus this function
// itself.
); // NOLINT
}
so the os_stack_trace_getter_ is already deleted at this point.
Does the bug persist in the most recent commit?
Yes, it with the latest code.
What operating system and version are you using?
Windows 10 Professional 64-bit
What compiler and version are you using?
Visual Studio 2019 with default settings (ISO C++14 Standard), the configuration is Debug Win32 and Debug x64.
What build system are you using?
None, just manual building and running.
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.
Assessment
This issue has not been assessed yet.