c++ - Getting the function name (__FUNCTION__) for my unit test library's assert function -
this question has answer here:
i writing unit test library , need log name of test function during assertion, follows:
struct my_test_case : public unit_test::test { void some_test() { assert_test(false, "test failed."); } };
when run test case, want produce output like:
assertion failed (&my_test_case::some_test()): test failed.
i know there ways solve issue:
give
__function__
assert_true()define macro
assert(a, b)
expandsassert_true(a, b, __function__)
define macro
test
cache__function__
in test function
struct my_test_case : public unit_test::test { void some_test() { test assert_test(false, "test failed."); } };
but these error-prone , ugly solutions. there other solutions problem?
something (2) or variant thereof choice:
__function__
not function or run time variable, exists @ compile time; so, no matter do, when need value @ runtime, need locally save value.
Comments
Post a Comment