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

How to write mock for functions accepting std::experimental::any argument.

honey-speaks-tech opened this issue · comments

Describe the bug

I need a help in fixing my unit test issue with gtest 1.10.0 version.
When I tried to unit test involving a function that accepts std::experimental::any argument, exception is thrown and unit test terminated.

Steps to reproduce the bug

Snippet of unit tests covering my test scenario available under https://godbolt.org/z/Y7dvEsaPf
In TestBoth testcase, if EXPECT_CALL and actual function calls are adjacently provided, exception is not thrown and test case execute successfully. But in my actual project code, my test function has call to send_data() function with both these data types.

Does the bug persist in the most recent commit?

N.A. gtest version is 1.10.0

What operating system and version are you using?

Ubuntu Linux 20.04

What compiler and version are you using?

g++ (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0

What build system are you using?

cmake version 3.20.5

Additional context

Help needed or please direct to where I can get this query asked and get resolved.

I don't believe this is a bug in GoogleTest. It looks like your code is using any_cast without checking that the call is safe. Matchers need to be callable with any possible value of the given type, so an any_cast needs to be checked before usage.