google / googletest

GoogleTest - Google Testing and Mocking Framework
https://google.github.io/googletest/
BSD 3-Clause "New" or "Revised" License
33.7k stars 9.98k forks source link

[Bug]: Improve compile-time checking of return values from actions in EXPECT_CALL #4501

Open lipeng28 opened 3 months ago

lipeng28 commented 3 months ago

Describe the issue

This post includes some problems in a closed ticket [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 <gmock/gmock.h>
#include <gtest/gtest.h>

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<int>(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

lipeng28 commented 3 months ago

@derekmauro is there anybody who can follow up this issue? I asked previously in the original post, however did not get any response. thanks

derekmauro commented 3 months ago

We don't look at closed issues that are years old. Thank you for filing a new issue. It will be triaged within a week.

lipeng28 commented 3 months ago

@derekmauro Any updates on this issue?

justzh commented 3 months ago

Organize your tests.

justzh commented 3 months ago

We cannot fix your issues for you?

justzh commented 3 months ago

Place using namespace testing; at the beginning of your file, please.

lipeng28 commented 3 months ago

@justzh this file can be compiled on my end, not sure what the problem is on your side? I am using GTest V1.11 now

justzh commented 3 months ago

cool!

derekmauro commented 3 months ago

justzh appears to be a spammer.

I agree this is a bug, but not a high priority bug. I don't think anyone has time to look into it at the moment.

justzh commented 3 months ago

This requires the use of Go, hopefully you know it, especially since we're at Google.

justzh commented 3 months ago

The issue seems to be on line 667. Pick inspect and then fix code, hopefully this helps.