]> granicus.if.org Git - check/commitdiff
Add call for retrieving test name
authorBranden Archer <b.m.archer4@gmail.com>
Sat, 5 Nov 2016 04:14:52 +0000 (00:14 -0400)
committerBranden Archer <b.m.archer4@gmail.com>
Sun, 6 Nov 2016 15:40:22 +0000 (10:40 -0500)
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.

src/check.c
src/check.h.in

index f49ed406d8f99eec076205f4e1d90e583102d644..fa3c57595951155f5518c417c30b506ca431bea1 100644 (file)
@@ -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)
index 3b29d546bfa95ebc3a13dbdf91d1e0d84f88472a..43867a61913a71d99b80ecd7405d2bc5a6d7720a 100644 (file)
@@ -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.
  *