unit-tests: Add ability to issue a warning message for a test case

This way we can warn if we e.g. skipped actually doing something due to
dependencies (otherwise the test case would just appear to have succeeded).
This commit is contained in:
Tobias Brunner
2017-11-08 16:48:10 +01:00
parent 90a3bc5075
commit 4c5dd39aa3
3 changed files with 116 additions and 6 deletions
+24
View File
@@ -219,6 +219,17 @@ void test_setup_timeout(int s);
*/
int test_failure_get(char *msg, int len, const char **file);
/**
* Get info about a warning if one was issued during the test. Resets the
* warning state.
*
* @param msg buffer receiving warning
* @param len size of msg buffer
* @param file pointer receiving source code file
* @return source code line number, 0 if no warning issued
*/
int test_warning_get(char *msg, int len, const char **file);
/**
* Get a backtrace for a failure.
*
@@ -246,6 +257,18 @@ void test_fail_vmsg(const char *file, int line, char *fmt, va_list args);
*/
void test_fail_msg(const char *file, int line, char *fmt, ...);
/**
* Issue a warning for a particular test with a message using printf style
* arguments. This does not fail the test, and only the last warning for each
* test is kept.
*
* @param file source code file name
* @param line source code line number
* @param fmt printf format string
* @param ... arguments for fmt
*/
void test_warn_msg(const char *file, int line, char *fmt, ...);
/**
* Let a test fail if one of the worker threads has failed (only if called from
* the main thread).
@@ -345,6 +368,7 @@ void test_fail_if_worker_failed();
#define ck_assert_msg test_assert_msg
#define ck_assert_str_eq test_str_eq
#define ck_assert_chunk_eq test_chunk_eq
#define warn(fmt, ...) test_warn_msg(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
#define fail(fmt, ...) test_fail_msg(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
#define fail_if(x, fmt, ...) \
({ \