Add support for messages within asserts
This commit is contained in:
parent
131da4f142
commit
9154667efa
|
@ -1,6 +1,7 @@
|
|||
#include "test_print.h"
|
||||
#include "mgba.h"
|
||||
#include <stdarg.h>
|
||||
#include "printf.h"
|
||||
|
||||
|
||||
void test_printf(const char* ptr, ...) {
|
||||
|
@ -10,10 +11,22 @@ void test_printf(const char* ptr, ...) {
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void assert_print(bool condition, const char* file, int line)
|
||||
void assert_print(bool condition, const char* file, int line, const char* message, ...)
|
||||
{
|
||||
char str[MAX_STR_SIZE];
|
||||
if(!condition)
|
||||
test_printf("FAIL! File: %s - Line: %d", file, line);
|
||||
{
|
||||
if(message == NULL)
|
||||
test_printf("FAIL! File: %s - Line: %d", file, line);
|
||||
else
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
vsnprintf(str, MAX_STR_SIZE, message, args);
|
||||
va_end(args);
|
||||
test_printf("FAIL! File: %s - Line: %d - Message: %s", file, line, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void start_session()
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
#include "mgba.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
#define assert(condition) assert_print(condition, __FILE__, __LINE__)
|
||||
#define MAX_STR_SIZE 0x100
|
||||
#define NULL 0
|
||||
|
||||
void assert_print(bool condition, const char* file, int line);
|
||||
#define assert(condition) assert_print(condition, __FILE__, __LINE__, NULL)
|
||||
#define assert_message(condition, format, ...) assert_print(condition, __FILE__, __LINE__, format, __VA_ARGS__)
|
||||
|
||||
void assert_print(bool condition, const char* file, int line, const char* message, ...);
|
||||
void test_printf(const char* string, ...);
|
||||
void start_session(void);
|
||||
void end_session(void);
|
||||
|
|
Loading…
Reference in New Issue