#ifndef TEST_FAIL_H
#define TEST_FAIL_H
/**
* @file
*
* Various ways to mark the current test as failed.
*/
#include "../error.h"
#include <stdarg.h>
#define NORETURN __attribute((noreturn))
/**
* Output a message representing the given failure using log_output.
*
* Also dumps out a stacktrace for the calling function using log_debug, skipping this func, the backtrace func, and
* the given number of frames.
*/
void test_fail_va (const char *func, const char *file, int line, int skip, const char *fmt, va_list vargs) NORETURN;
/**
* Output given fail using test_fail_va().
*/
void test_fail (const char *func, const char *file, int line, int skip, const char *fmt, ...) NORETURN;
/**
* Fail with a simple error message
*/
#define fail(...) test_fail(__func__, __FILE__, __LINE__, 0, __VA_ARGS__)
/**
* Fail conditionally
*/
#define fail_if(cond, ...) do { \
if (cond) \
fail(__VA_ARGS__); \
} while (0)
/**
* Fail with an error code
*/
#define fail_err(err, fmt, ...) fail(fmt ": %s", __VA_ARGS__, ## error_name(err))
/**
* Fail with an error info
*/
#define fail_error(error, fmt, ...) fail(fmt ": %s", __VA_ARGS__, ## error_msg(error))
#endif /* TEST_FAIL_H */