tests: display trace level with prefix in tests
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
diff --git a/tests/clar_libgit2_trace.c b/tests/clar_libgit2_trace.c
index aaeeb78..eb2fbbd 100644
--- a/tests/clar_libgit2_trace.c
+++ b/tests/clar_libgit2_trace.c
@@ -10,26 +10,42 @@ struct method {
void (*close)(void);
};
+static const char *message_prefix(git_trace_level_t level)
+{
+ switch (level) {
+ case GIT_TRACE_NONE:
+ return "[NONE]: ";
+ case GIT_TRACE_FATAL:
+ return "[FATAL]: ";
+ case GIT_TRACE_ERROR:
+ return "[ERROR]: ";
+ case GIT_TRACE_WARN:
+ return "[WARN]: ";
+ case GIT_TRACE_INFO:
+ return "[INFO]: ";
+ case GIT_TRACE_DEBUG:
+ return "[DEBUG]: ";
+ case GIT_TRACE_TRACE:
+ return "[TRACE]: ";
+ default:
+ return "[?????]: ";
+ }
+}
#if defined(GIT_TRACE)
static void _git_trace_cb__printf(git_trace_level_t level, const char *msg)
{
- /* TODO Use level to print a per-message prefix. */
- GIT_UNUSED(level);
-
- printf("%s\n", msg);
+ printf("%s%s\n", message_prefix(level), msg);
}
#if defined(GIT_WIN32)
static void _git_trace_cb__debug(git_trace_level_t level, const char *msg)
{
- /* TODO Use level to print a per-message prefix. */
- GIT_UNUSED(level);
-
+ OutputDebugString(message_prefix(level));
OutputDebugString(msg);
OutputDebugString("\n");
- printf("%s\n", msg);
+ printf("%s%s\n", message_prefix(level), msg);
}
#else
#define _git_trace_cb__debug _git_trace_cb__printf