Skip to content

Commit

Permalink
Hacky Solution nemequ#1 (log_noabort)
Browse files Browse the repository at this point in the history
Add _noabort variants to
munit_logf_ex
munit_logf
munit_log

They do not stop the program, independent of log-level.

As a proof of concept, I added a _msgf variant to munit_assert,
that first logs the error with _noabort
and then the message with the default errorf.

This solution works, but I'd prefer some form of
indentention or grouping of user messages and error messages.
  • Loading branch information
etwasanderes2 committed May 20, 2020
1 parent fbbdf14 commit 0763517
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions munit.c
Expand Up @@ -227,6 +227,17 @@ munit_logf_ex(MunitLogLevel level, const char* filename, int line, const char* f
}
}

/////////////////////////
void
munit_logf_ex_noabort(MunitLogLevel level, const char* filename, int line, const char* format, ...) {
va_list ap;

va_start(ap, format);
munit_logf_exv(level, stderr, filename, line, format, ap);
va_end(ap);
}
/////////////////////////////

void
munit_errorf_ex(const char* filename, int line, const char* format, ...) {
va_list ap;
Expand Down
24 changes: 24 additions & 0 deletions munit.h
Expand Up @@ -185,6 +185,18 @@ typedef enum {
MUNIT_PRINTF(4, 5)
void munit_logf_ex(MunitLogLevel level, const char* filename, int line, const char* format, ...);

//////////////////////
void munit_logf_ex_noabort(MunitLogLevel level, const char* filename, int line, const char* format, ...);

#define munit_logf_noabort(level, format, ...) \
munit_logf_ex_noabort(level, __FILE__, __LINE__, format, __VA_ARGS__)

#define munit_log_noabort(level, msg) \
munit_logf_noabort(level, "%s", msg)


///////////////////////

#define munit_logf(level, format, ...) \
munit_logf_ex(level, __FILE__, __LINE__, format, __VA_ARGS__)

Expand All @@ -210,6 +222,18 @@ void munit_errorf_ex(const char* filename, int line, const char* format, ...);
} while (0) \
MUNIT_POP_DISABLE_MSVC_C4127_

/////////////////////////////////////
#define munit_assert_msgf(expr, msg, ...) \
do { \
if (!MUNIT_LIKELY(expr)) { \
munit_log_noabort(MUNIT_LOG_ERROR, "assertion failed: " #expr); \
munit_errorf(msg, __VA_ARGS__); \
} \
MUNIT_PUSH_DISABLE_MSVC_C4127_ \
} while (0) \
MUNIT_POP_DISABLE_MSVC_C4127_
/////////////////////////////////////

#define munit_assert_true(expr) \
do { \
if (!MUNIT_LIKELY(expr)) { \
Expand Down

0 comments on commit 0763517

Please sign in to comment.