Google Test is for run-time tests. The type of a function is determined at compile time, before Google Test ever enters the picture.
You could use result_of
and assert that the typeid value is the same, something like this:
EXPECT_EQ(typeid(int), typeid(std::result_of<foo<int>() >::type));
Another option is to forego an explicit test of the return type and just use the function as it's expected to be used. If there's something wrong with the return type, the compiler will tell you before you ever try running the test. That's probably better than requiring one specific return type, anyway; for example, if the return type turns out to be long
instead of the expected int
, but all your other tests still pass, then was int
really so important in the first place?