c++ - Getting the function name (__FUNCTION__) for my unit test library's assert function -


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:

  1. give __function__ assert_true()

  2. define macro assert(a, b) expands assert_true(a, b, __function__)

  3. 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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -