I am writing a unit test library and I need to log the name of the test function during the assertion, like as follows:
struct my_test_case : public unit_test::test {
void some_test()
{
assert_test(false, "test failed.");
}
};
When I run the test case, I want to produce an output like:
ASSERTION FAILED (&my_test_case::some_test()): test failed.
I know there are some ways to solve this issue:
-
Give
__FUNCTION__
to assert_true() -
Define a macro like
ASSERT(a, b)
that expands toassert_true(a, b, __FUNCTION__)
-
Define a macro like
TEST
to cache the__FUNCTION__
in the test function:struct my_test_case : public unit_test::test { void some_test() { TEST assert_test(false, "test failed."); } };
But these are error-prone and ugly solutions. Are there any other solutions to this problem?
Aucun commentaire:
Enregistrer un commentaire