Skip to content

[Feature Request]: support callable objects in macro CHECK_COMPARE() #1854

@zhang-stephen

Description

@zhang-stephen

Hi, the CHECK_EQUAL supports this pattern when I want to compare two objects:

CHECK_EQUAL(lhs, ==, rhs);

But for some user-defined objects, which are without relationship operators, I had to write a function or a lambda to compare them (I cannot modify these classes to add relationship operators, they belong to a shared library in my workplace), e.g.

bool isEqual(const Obj& lhs, const Obj& rhs) { 
    // do real comparison
    return ...;
}

CHECK_TRUE(COMPARE(lhs, rhs));

But it cannot be invoked in macro CHECK_COMPARE, e.g. CHECK_COMPARE(lhs, compare, rhs), or it would be expanded as the following, that's not expected.

bool success = (lhs)compare(rhs);

Then I think CHECK_COMPARE could provide a version to accept the callable objects, it might be expanded as following:

bool success = (compare)((lhs), (rhs));

Will you consider to add something like this? Thank You~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions