I am writing tests on Eigen matrices using Google\'s testing framework Google-Mock, as already discussed in another question.
With the followi
I feel compelled to provide a new answer that I believe is simpler and better than the others, although it is so simple that I may have missed something. It's very similar to solutions that you have already tried but it's not quite the same.
Essentially, you don't have to jump through the plugin hoops of modifying the class. The caveat is that, yes, you have to define a PrintTo
function for each type (Matrix2d
, Matrix3d
, etc); a function template won't work. But since this is a unit test, I assume that you know what all your types are and so that's not an issue.
So essentially take your code from the plugin and just put it in the unit test like you were trying to do with the templated SFINAE-enabled one:
namespace Eigen
{
void PrintTo(const Matrix2d &m, std::ostream *os)
{
*os << std::endl << m << std::endl;
}
}
Nothing fancy. This works for me and should do what you want according to your test case and question.