tests: fix compiler warning if tracing is disabled If building libgit2's test suite with tracing disabled, then the compiler will emit a warning due to the unused `message_prefix` function. Fix the issue by wrapping the whole file into ifdef's for `GIT_TRACE` and providing separate empty function implementations for both `cl_global_trace_register` and `cl_global_trace_disable`.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
diff --git a/tests/clar_libgit2_trace.c b/tests/clar_libgit2_trace.c
index 83c83b9..b6c1c1f 100644
--- a/tests/clar_libgit2_trace.c
+++ b/tests/clar_libgit2_trace.c
@@ -1,9 +1,11 @@
-#include "clar_libgit2.h"
#include "clar_libgit2_trace.h"
+
+#if defined(GIT_TRACE)
+
+#include "clar_libgit2.h"
#include "clar_libgit2_timer.h"
#include "trace.h"
-
struct method {
const char *name;
void (*git_trace_cb)(git_trace_level_t level, const char *msg);
@@ -32,7 +34,6 @@ static const char *message_prefix(git_trace_level_t level)
}
}
-#if defined(GIT_TRACE)
static void _git_trace_cb__printf(git_trace_level_t level, const char *msg)
{
printf("%s%s\n", message_prefix(level), msg);
@@ -225,15 +226,11 @@ void _cl_trace_cb__event_handler(
}
}
-#endif /*GIT_TRACE*/
-
/**
* Setup/Enable git_trace() based upon settings user's environment.
- *
*/
void cl_global_trace_register(void)
{
-#if defined(GIT_TRACE)
if (!s_trace_loaded)
_load_trace_params();
@@ -246,7 +243,6 @@ void cl_global_trace_register(void)
git_trace_set(s_trace_level, s_trace_method->git_trace_cb);
cl_trace_register(_cl_trace_cb__event_handler, NULL);
-#endif
}
/**
@@ -258,7 +254,6 @@ void cl_global_trace_register(void)
*/
void cl_global_trace_disable(void)
{
-#if defined(GIT_TRACE)
cl_trace_register(NULL, NULL);
git_trace_set(GIT_TRACE_NONE, NULL);
if (s_trace_method && s_trace_method->close)
@@ -268,5 +263,16 @@ void cl_global_trace_disable(void)
* since we only want to hit the environment variables
* once.
*/
-#endif
}
+
+#else /* GIT_TRACE */
+
+void cl_global_trace_register(void)
+{
+}
+
+void cl_global_trace_disable(void)
+{
+}
+
+#endif /* GIT_TRACE*/