TEST_CASE("Functions of Square")
{
std::array<Point, 4> a_Vertices{Point(2, 2), Point(2, 4), Point(4, 2), Point(4, 4)};
Square a_Square(a_Vertices, true);
SECTION("Square is initialized properly")
{
REQUIRE(a_Square.get_Vertex_0() == Point(2, 1));
}
}
Using catch2 unit test framework, I want to override catch2 describe method so that it would print out my type instead of {?} == {?}
I've also tried doing it via matcher method
class Point_Matcher : public Catch::MatcherBase<Point>
{
private:
Point p_;
public:
Point_Matcher(const Point &a_Point)
: p_(a_Point) {}
bool match(Point const &a_Point) const override
{
return a_Point == p_;
}
virtual std::string describe() const override
{
std::ostringstream oss;
oss << "not the same as Point (" << p_.get_X() << ", " << p_.get_Y() << ")";
return oss.str();
}
};
inline Point_Matcher is_Same(const Point &a_Point)
{
return Point_Matcher(a_Point);
}
TEST_CASE("Functions of Square")
{
std::array<Point, 4> a_Vertices{Point(2, 2), Point(2, 4), Point(4, 2), Point(4, 4)};
Square a_Square(a_Vertices, true);
SECTION("Square is initialized properly")
{
REQUIRE_THAT(a_Square.get_Vertex_0(), is_Same(Point(2, 1)));
}
}
however, it would only show the object that's specified as the test and wouldn't show the object being tested. Output will be {?} not the same as Point(2, 1)
in https://github.com/catchorg/Catch2/blob/master/docs/tostring.md#top The suggested way of doing it is to override the operator<< of std::ostream, however, i don't know what i'm supposed to do after i overloaded the operator.
Thank you in advance for the answer
Edit: The overload for operator<< for Point Object is as follows
std::ostream &operator<<(std::ostream &os, const Point &p)
{
os << "Point (" << p.get_X() << ", " << p.get_Y();
return os;
}
In other words, the output, that i'm aiming for is in this case in particular Point(x, y) not the same as Point(x,y)