[Bug]: Improve compile-time checking of return values from actions in EXPECT_CALL
- Dominant language
- C++
- Stars
- 39.5k
- Forks
- 10.9k
- Avg merge
- 6d 13h
- Merged PRs (30d)
- 1
Description
### Describe the issue
This post includes some problems in a closed ticket [[1886](https://github.com/google/googletest/issues/1886)], I found part of them did not get fixed properly.
Can you please check them and fix them?
### Steps to reproduce the problem
```
#include
#include
using namespace testing;
class cMockFoo {
public:
virtual ~cMockFoo() = default;
MOCK_METHOD0(FooVoid, void());
MOCK_METHOD1(FooRef, int(int&));
MOCK_METHOD0(FooRetRef, int&());
};
TEST(TestFooVoid, Foo){
cMockFoo foo;
//expectation: compile: fail
//result: compile: pass, run: pass
EXPECT_CALL(foo,FooVoid()).WillRepeatedly(ReturnNew(3));
foo.FooVoid();
}
TEST(TestFooVoid, Bar){
cMockFoo foo;
//expectation: compile: fail
//result: compile: pass, run: pass
int asdf=3;
EXPECT_CALL(foo,FooVoid()).WillRepeatedly(ReturnPointee(&asdf));
foo.FooVoid();
}
int main(int argc, char ** argv) {
InitGoogleTest(&argc, argv);
int rtn = RUN_ALL_TESTS();
return rtn;
}
```
To reproduce the issue, please use the following command:
`
g++ main.cc -I /path/to/gtest/googlemock/include -I /path/to/gtest/googletest/googletest/include -L /path/to/gtest/build/lib/ -lgmock -lgtest -lpthread -o main.exe
`
### What version of GoogleTest are you using?
I tried the V1.11, V1.14 and latest github
### What operating system and version are you using?
Ubuntu 20.04.6 LTS
### What compiler and version are you using?
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
### What build system are you using?
cmake version 3.28.1
### Additional context
_No response_
Contributor guide
Research direction
Start with the EXPECT_CALL examples in this issue and review the referenced closed issue 1886 for the intended compile-time behavior. Trace how WillRepeatedly handles ReturnNew and ReturnPointee for void actions, then add regression coverage showing invalid return actions fail to compile while valid actions remain supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100