google / googletest

GoogleTest - Google Testing and Mocking Framework

Home Page:https://google.github.io/googletest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

lipeng28 opened this issue · comments

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

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

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.

@derekmauro Any updates on this issue?

Organize your tests.

We cannot fix your issues for you?

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

@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

cool!

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.

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

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