From: Branden Archer Date: Sat, 5 Nov 2016 04:14:52 +0000 (-0400) Subject: Add call for retrieving test name X-Git-Tag: 0.11.0~12^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=11152d75e620ec2cd052b9b9838a28f0052018fd;p=check Add call for retrieving test name This will be used internally to determine the current running test and recording it during the check_check_sub tests in order to make unit test failure debugging easier. The call may also be useful for users of Check. --- diff --git a/src/check.c b/src/check.c index f49ed40..fa3c575 100644 --- a/src/check.c +++ b/src/check.c @@ -48,6 +48,8 @@ int check_major_version = CHECK_MAJOR_VERSION; int check_minor_version = CHECK_MINOR_VERSION; int check_micro_version = CHECK_MICRO_VERSION; +const char* current_test_name = NULL; + static int non_pass(int val); static Fixture *fixture_create(SFun fun, int ischecked); static void tcase_add_fixture(TCase * tc, SFun setup, SFun teardown, @@ -337,11 +339,18 @@ void tcase_set_timeout(TCase * tc, double timeout) #endif /* HAVE_FORK */ } -void tcase_fn_start(const char *fname CK_ATTRIBUTE_UNUSED, const char *file, +void tcase_fn_start(const char *fname, const char *file, int line) { send_ctx_info(CK_CTX_TEST); send_loc_info(file, line); + + current_test_name = fname; +} + +const char* tcase_name() +{ + return current_test_name; } void _mark_point(const char *file, int line) diff --git a/src/check.h.in b/src/check.h.in index 3b29d54..43867a6 100644 --- a/src/check.h.in +++ b/src/check.h.in @@ -375,6 +375,16 @@ CK_DLL_EXP void CK_EXPORT tcase_set_timeout(TCase * tc, double timeout); CK_DLL_EXP void CK_EXPORT tcase_fn_start(const char *fname, const char *file, int line); +/** + * Retreive the name of the current running test. This is the name + * of the test passed to START_TEST. This is only valid when called + * from a running test. The value return outside of a running test is + * undefined. + * + * @since 0.11.0 + */ +CK_DLL_EXP const char* CK_EXPORT tcase_name(); + /** * Start a unit test with START_TEST(unit_name), end with END_TEST. *